Help!

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2008
Posts: 7
Reputation: anbuhikaru is an unknown quantity at this point 
Solved Threads: 0
anbuhikaru's Avatar
anbuhikaru anbuhikaru is offline Offline
Newbie Poster

Help!

 
0
  #1
Apr 19th, 2008
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...

  
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. public class Play extends JApplet implements KeyListener, FocusListener, MouseListener {
  6.  
  7. private JPanel main, fini, game;
  8. private CardLayout cards;
  9. private Container c;
  10. private int index, max;
  11. private String player;
  12.  
  13. public Play( ) {
  14. index = 0;
  15. max = 3;
  16. }
  17.  
  18. public void init( ) {
  19. c = this.getContentPane();
  20. cards = new CardLayout( );
  21. c.setLayout( cards );
  22. main = new MainPanel();
  23. main.addMouseListener(this);
  24. game.addMouseListener(this);
  25. fini.addMouseListener(this);
  26. c.add( main, "Greeting" );
  27. c.add( game, "Game" );
  28. c.add( fini, "End" );
  29. c.addFocusListener(this);
  30. c.addKeyListener(this);
  31. getContentPane().setBackground( Color.blue );
  32. }
  33. public Insets getInsets() {
  34. return new Insets ( 0, 0, 0, 0 );
  35. }
  36. class MainPanel extends JPanel implements ActionListener {
  37. private JLabel name, grade, greeting;
  38. private JTextField gradeText, nameText;
  39. private JButton go;
  40.  
  41. public MainPanel( ) {
  42. setLayout(new GridLayout(6, 1));
  43. greeting = new JLabel("Welcome to the game of Navigate!", JLabel.CENTER);
  44. this.add(greeting);
  45. name = new JLabel("Name");
  46. this.add(name);
  47. nameText = new JTextField(10);
  48. this.add(nameText);
  49. grade = new JLabel("Grade");
  50. this.add(grade);
  51. gradeText = new JTextField(10);
  52. this.add(gradeText);
  53. go = new JButton("GO!");
  54. go.addActionListener ( this );
  55. this.add(go);
  56. }
  57.  
  58. public void paintComponent(Graphics g) {
  59. super.paintComponent(g);
  60. }
  61.  
  62. public void actionPerformed ( ActionEvent evt ) {
  63. String command = evt.getActionCommand();
  64. if ( command.equals( "GO!")) {
  65. cards.next(c);
  66. }
  67. }
  68. }
  69.  
  70. class Game extends JPanel implements KeyListener, FocusListener, MouseListener {
  71. private PlayCell [][] board;
  72. private int x = 0, y = 0;
  73. private int numberofbad = 4;
  74. private boolean done = false, firsttime;
  75. private PaintPanel canvas;
  76.  
  77. public Game( ) {
  78. canvas = new PaintPanel();
  79. setContentPane(canvas);
  80. canvas.setBackground(Color.gray);
  81. canvas.addFocusListener(this);
  82. canvas.addKeyListener(this);
  83. canvas.addMouseListener(this);
  84. SetUpBoard( );
  85. }
  86. public void SetUpBoard( ) {
  87. x = y = 0;
  88. numberofbad = 4;
  89. done = false;
  90. firsttime = true;
  91. board = new PlayCell[6][6];
  92. for ( int i = 0; i < 6; i++ )
  93. for ( int k = 0; k < 6; k++ )
  94. board[i][k] = new PlayCell();
  95. PlaceBadCells( );
  96. }
  97. class PaintPanel extends JPanel {
  98. public void paintComponent(Graphics g) {
  99. super.paintComponent(g);
  100. for ( int i = 0; i < 6; i++ )
  101. for ( int k = 0; k < 6; k++ )
  102. board[i][k].drawCell( g, i * 40 + 117, k * 40 + 17, 36, 36 );
  103. board[x][y].changeToOnCell( );
  104. board[x][y].changeToCellVisited( );
  105. board[x][y].drawCell( g, x * 40 + 117, y * 40 + 17, 36, 36 );
  106. }
  107. }
  108. public void focusGained(FocusEvent evt) {
  109. firsttime = false;
  110. canvas.repaint();
  111. }
  112. public void focusLost(FocusEvent evt) {
  113. firsttime = true;
  114. canvas.repaint();
  115. }
  116. public void mousePressed(MouseEvent evt) {
  117. canvas.requestFocus();
  118. }
  119. public void mouseEntered(MouseEvent evt) { }
  120. public void mouseExited(MouseEvent evt) { }
  121. public void mouseReleased(MouseEvent evt) { }
  122. public void mouseClicked(MouseEvent evt) { }
  123. public void keyTyped( KeyEvent e ) {}
  124. public void keyPressed( KeyEvent e ) {
  125. Graphics g = getGraphics();
  126. int value = e.getKeyCode();
  127. if ( value == KeyEvent.VK_SPACE ) {
  128. SetUpBoard ( );
  129. firsttime = false;
  130. canvas.repaint ( );
  131. }
  132. else if (( value == KeyEvent.VK_RIGHT || value == KeyEvent.VK_LEFT ||
  133. value == KeyEvent.VK_UP || value == KeyEvent.VK_DOWN ) && !done ) {
  134. board[x][y].changeToOffCell( );
  135. board[x][y].drawCell( g, x * 40 + 117, y * 40 + 17, 36, 36 );
  136. if ( value == KeyEvent.VK_RIGHT && x < 5 )
  137. x++;
  138. else if ( value == KeyEvent.VK_LEFT && x > 0 )
  139. x--;
  140. else if ( value == KeyEvent.VK_UP && y > 0 )
  141. y--;
  142. else if ( value == KeyEvent.VK_DOWN && y < 5 )
  143. y++;
  144. board[x][y].changeToOnCell( );
  145. board[x][y].changeToCellVisited( );
  146. board[x][y].drawCell( g, x * 40 + 117, y * 40 + 17, 36, 36 );
  147. if ( board[x][y].checkForBadCell ( ) || (x == 5 && y == 5) ) {
  148. done = true;
  149. DrawFinalBoard(g);
  150. }
  151. }
  152. }
  153. public void keyReleased( KeyEvent e ) {}
  154. public void PlaceBadCells( ) {
  155. int badx, bady;
  156. for ( int v = 1; v <= numberofbad; v++ ) {
  157. badx = (int)( Math.random() * 4 );
  158. bady = (int)( Math.random() * 4 );
  159. if ( (badx != 0 || bady != 0) && !board[badx][bady].checkForBadCell() &&
  160. (badx != 3 || bady != 3) )
  161. board[badx][bady].changeToBadCell( );
  162. else
  163. v--;
  164. }
  165. }
  166. public void DrawFinalBoard( Graphics g ) {
  167. for ( int i = 0; i < 6; i++ )
  168. for ( int k = 0; k < 6; k++ ) {
  169. board[i][k].changeToCellVisited ( );
  170. board[i][k].drawCell( g, i * 40 + 117, k * 40 + 17, 36, 36 );
  171. WinOrLoseMessage ( g );
  172. }
  173. }
  174. public void WinOrLoseMessage( Graphics g ) {
  175. g.setColor ( Color.red );
  176. Font letters = new Font("Serif", Font.BOLD, 20);
  177. g.setFont(letters);
  178. if ( x == 5 && y == 5 ) {
  179. g.drawString ( "YOU", 20, 40 );
  180. g.drawString ( "ARE", 20, 70 );
  181. g.drawString ( "A", 20, 100 );
  182. g.drawString ( "WINNER!", 20, 130 );
  183. }
  184. else {
  185. g.drawString ( "Sorry,",20, 40 );
  186. g.drawString ( "but",20, 70 );
  187. g.drawString ( "this",20, 100 );
  188. g.drawString ( "time",20, 130 );
  189. g.drawString ( "you",20, 160 );
  190. g.drawString ( "lost.",20, 190 );
  191. }
  192. g.drawString ( "Hit", 460, 40 );
  193. g.drawString ( "Spacebar", 460, 70 );
  194. g.drawString ( "to", 460, 100 );
  195. g.drawString ( "play", 460, 130 );
  196. g.drawString ( "again.", 460, 160 );
  197. }
  198. }
  199. }
Last edited by anbuhikaru; Apr 19th, 2008 at 8:09 pm. Reason: try to syntax highlight
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 7
Reputation: anbuhikaru is an unknown quantity at this point 
Solved Threads: 0
anbuhikaru's Avatar
anbuhikaru anbuhikaru is offline Offline
Newbie Poster

Re: Help!

 
0
  #2
Apr 19th, 2008
bump
~*[anbuhikaru]*~
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,467
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 267
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Help!

 
0
  #3
Apr 20th, 2008
this error message is quite self-explanatory
  1. Play.java:5: Play is not abstract and does not override abstract method keyReleased(java.awt.event.KeyEvent)
  2. 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
  1. public void keyReleased(KeyEvent e) {
  2. // your code
  3. }


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
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 7
Reputation: anbuhikaru is an unknown quantity at this point 
Solved Threads: 0
anbuhikaru's Avatar
anbuhikaru anbuhikaru is offline Offline
Newbie Poster

Re: Help!

 
0
  #4
Apr 20th, 2008
So should i add all the listener classes after my game class as well as in the game class? [sorry if this is a stupid question, but my teacher never explained these concepts to me]
~*[anbuhikaru]*~
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 3,584
Reputation: jasimp has a spectacular aura about jasimp has a spectacular aura about jasimp has a spectacular aura about 
Solved Threads: 52
Featured Poster
jasimp's Avatar
jasimp jasimp is online now Online
Senior Poster

Re: Help!

 
0
  #5
Apr 20th, 2008
I think he means you should remove the implements from your Play class.
  1. 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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum


Views: 622 | Replies: 4
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC