| | |
Help!
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
So i'm a java student in 9th grade and my code gives me an error i have never encountered before...
time is off the essence, so quick help is loved!
it says:
Play.java:5: Play is not abstract and does not override abstract method keyReleased(java.awt.event.KeyEvent)
public class Play extends JApplet implements KeyListener, FocusListener, MouseListener {
and i'll post my code...
time is off the essence, so quick help is loved!
it says:
Play.java:5: Play is not abstract and does not override abstract method keyReleased(java.awt.event.KeyEvent)
public class Play extends JApplet implements KeyListener, FocusListener, MouseListener {
and i'll post my code...
Java Syntax (Toggle Plain Text) - import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
-
- public class Play extends JApplet implements KeyListener, FocusListener, MouseListener {
-
- private JPanel main, fini, game;
- private CardLayout cards;
- private Container c;
- private int index, max;
- private String player;
-
- public Play( ) {
- index = 0;
- max = 3;
- }
-
- public void init( ) {
- c = this.getContentPane();
- cards = new CardLayout( );
- c.setLayout( cards );
- main = new MainPanel();
- main.addMouseListener(this);
- game.addMouseListener(this);
- fini.addMouseListener(this);
- c.add( main, "Greeting" );
- c.add( game, "Game" );
- c.add( fini, "End" );
- c.addFocusListener(this);
- c.addKeyListener(this);
- getContentPane().setBackground( Color.blue );
- }
- public Insets getInsets() {
- return new Insets ( 0, 0, 0, 0 );
- }
- class MainPanel extends JPanel implements ActionListener {
- private JLabel name, grade, greeting;
- private JTextField gradeText, nameText;
- private JButton go;
-
- public MainPanel( ) {
- setLayout(new GridLayout(6, 1));
- greeting = new JLabel("Welcome to the game of Navigate!", JLabel.CENTER);
- this.add(greeting);
- name = new JLabel("Name");
- this.add(name);
- nameText = new JTextField(10);
- this.add(nameText);
- grade = new JLabel("Grade");
- this.add(grade);
- gradeText = new JTextField(10);
- this.add(gradeText);
- go = new JButton("GO!");
- go.addActionListener ( this );
- this.add(go);
- }
-
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- }
-
- public void actionPerformed ( ActionEvent evt ) {
- String command = evt.getActionCommand();
- if ( command.equals( "GO!")) {
- cards.next(c);
- }
- }
- }
-
- class Game extends JPanel implements KeyListener, FocusListener, MouseListener {
- private PlayCell [][] board;
- private int x = 0, y = 0;
- private int numberofbad = 4;
- private boolean done = false, firsttime;
- private PaintPanel canvas;
-
- public Game( ) {
- canvas = new PaintPanel();
- setContentPane(canvas);
- canvas.setBackground(Color.gray);
- canvas.addFocusListener(this);
- canvas.addKeyListener(this);
- canvas.addMouseListener(this);
- SetUpBoard( );
- }
- public void SetUpBoard( ) {
- x = y = 0;
- numberofbad = 4;
- done = false;
- firsttime = true;
- board = new PlayCell[6][6];
- for ( int i = 0; i < 6; i++ )
- for ( int k = 0; k < 6; k++ )
- board[i][k] = new PlayCell();
- PlaceBadCells( );
- }
- class PaintPanel extends JPanel {
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- for ( int i = 0; i < 6; i++ )
- for ( int k = 0; k < 6; k++ )
- board[i][k].drawCell( g, i * 40 + 117, k * 40 + 17, 36, 36 );
- board[x][y].changeToOnCell( );
- board[x][y].changeToCellVisited( );
- board[x][y].drawCell( g, x * 40 + 117, y * 40 + 17, 36, 36 );
- }
- }
- public void focusGained(FocusEvent evt) {
- firsttime = false;
- canvas.repaint();
- }
- public void focusLost(FocusEvent evt) {
- firsttime = true;
- canvas.repaint();
- }
- public void mousePressed(MouseEvent evt) {
- canvas.requestFocus();
- }
- public void mouseEntered(MouseEvent evt) { }
- public void mouseExited(MouseEvent evt) { }
- public void mouseReleased(MouseEvent evt) { }
- public void mouseClicked(MouseEvent evt) { }
- public void keyTyped( KeyEvent e ) {}
- public void keyPressed( KeyEvent e ) {
- Graphics g = getGraphics();
- int value = e.getKeyCode();
- if ( value == KeyEvent.VK_SPACE ) {
- SetUpBoard ( );
- firsttime = false;
- canvas.repaint ( );
- }
- else if (( value == KeyEvent.VK_RIGHT || value == KeyEvent.VK_LEFT ||
- value == KeyEvent.VK_UP || value == KeyEvent.VK_DOWN ) && !done ) {
- board[x][y].changeToOffCell( );
- board[x][y].drawCell( g, x * 40 + 117, y * 40 + 17, 36, 36 );
- if ( value == KeyEvent.VK_RIGHT && x < 5 )
- x++;
- else if ( value == KeyEvent.VK_LEFT && x > 0 )
- x--;
- else if ( value == KeyEvent.VK_UP && y > 0 )
- y--;
- else if ( value == KeyEvent.VK_DOWN && y < 5 )
- y++;
- board[x][y].changeToOnCell( );
- board[x][y].changeToCellVisited( );
- board[x][y].drawCell( g, x * 40 + 117, y * 40 + 17, 36, 36 );
- if ( board[x][y].checkForBadCell ( ) || (x == 5 && y == 5) ) {
- done = true;
- DrawFinalBoard(g);
- }
- }
- }
- public void keyReleased( KeyEvent e ) {}
- public void PlaceBadCells( ) {
- int badx, bady;
- for ( int v = 1; v <= numberofbad; v++ ) {
- badx = (int)( Math.random() * 4 );
- bady = (int)( Math.random() * 4 );
- if ( (badx != 0 || bady != 0) && !board[badx][bady].checkForBadCell() &&
- (badx != 3 || bady != 3) )
- board[badx][bady].changeToBadCell( );
- else
- v--;
- }
- }
- public void DrawFinalBoard( Graphics g ) {
- for ( int i = 0; i < 6; i++ )
- for ( int k = 0; k < 6; k++ ) {
- board[i][k].changeToCellVisited ( );
- board[i][k].drawCell( g, i * 40 + 117, k * 40 + 17, 36, 36 );
- WinOrLoseMessage ( g );
- }
- }
- public void WinOrLoseMessage( Graphics g ) {
- g.setColor ( Color.red );
- Font letters = new Font("Serif", Font.BOLD, 20);
- g.setFont(letters);
- if ( x == 5 && y == 5 ) {
- g.drawString ( "YOU", 20, 40 );
- g.drawString ( "ARE", 20, 70 );
- g.drawString ( "A", 20, 100 );
- g.drawString ( "WINNER!", 20, 130 );
- }
- else {
- g.drawString ( "Sorry,",20, 40 );
- g.drawString ( "but",20, 70 );
- g.drawString ( "this",20, 100 );
- g.drawString ( "time",20, 130 );
- g.drawString ( "you",20, 160 );
- g.drawString ( "lost.",20, 190 );
- }
- g.drawString ( "Hit", 460, 40 );
- g.drawString ( "Spacebar", 460, 70 );
- g.drawString ( "to", 460, 100 );
- g.drawString ( "play", 460, 130 );
- g.drawString ( "again.", 460, 160 );
- }
- }
- }
Last edited by anbuhikaru; Apr 19th, 2008 at 8:09 pm. Reason: try to syntax highlight
this error message is quite self-explanatory
You have implements KeyListener and have not (in that class) implemented (i.e. defined) the method
If you take a close look above, both your "Play" class, and your "Game" class claim to implement a couple of interfaces, but only "Game" actually defines the methods declared in those interfaces.
Java Syntax (Toggle Plain Text)
Play.java:5: Play is not abstract and does not override abstract method keyReleased(java.awt.event.KeyEvent) public class Play extends JApplet implements KeyListener, FocusListener, MouseListener {
You have implements KeyListener and have not (in that class) implemented (i.e. defined) the method
Java Syntax (Toggle Plain Text)
public void keyReleased(KeyEvent e) { // your code }
If you take a close look above, both your "Play" class, and your "Game" class claim to implement a couple of interfaces, but only "Game" actually defines the methods declared in those interfaces.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
I think he means you should remove the implements from your Play class.
java Syntax (Toggle Plain Text)
public class Play extends JApplet {
Last edited by jasimp; Apr 20th, 2008 at 1:19 pm.
"Argyou not with the hand you are dealt in cards or life." ---- Wizard and Glass
![]() |
Other Threads in the Java Forum
- Previous Thread: open source java program
- Next Thread: how to print out an array in a message box
Views: 622 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Java
6 android api apple applet application arguments array arrays automation binary bluetooth bold byte c++ chat class classes client code component coordinates database datagram doctype draw eclipse educational error event exception file fractal froglogic game givemetehcodez graphics gui helpwithhomework html ide ideas image ingres input integer internet intersect ip j2me java javaexcel javaprojects jmf jni jpanel jtextarea julia linux list loop map method methods mobile netbeans newbie nextline number object oracle pong print problem program programming project recursion recursive scanner screen sell server set size sms socket sort sql string swing test threads time transfer tree user web websites windows






