Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 11th, 2008, 11:38 AM   #1
JD-Salinger
Unknown
 
JD-Salinger's Avatar
 
Join Date: Apr 2008
Location: unknown
Posts: 87
Rep Power: 1 JD-Salinger is on a distinguished road
Error in Inner Class

i think the logic is right, i dont know why an error popped out... thnks
java Syntax (Toggle Plain Text)
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. public class ButtonTest
  6. {
  7. public static void main(String[] args)
  8. {
  9. EventQueue.invokeLater(new Runnable()
  10. {
  11. public void run()
  12. {
  13. ButtonFrame frame = new ButtonFrame();
  14. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  15. frame.setVisible(true);
  16. }
  17. });
  18. }
  19. }
  20.  
  21. class ButtonFrame extends JFrame
  22. {
  23. public ButtonFrame()
  24. {
  25. setTitle("ButtonTest");
  26. setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
  27.  
  28. JButton yellowButton = new JButton("Yellow");
  29. JButton blueButton = new JButton("Blue");
  30. JButton redButton = new JButton("Red");
  31.  
  32. buttonPanel = new JPanel();
  33. buttonPanel.add(yellowButton);
  34. buttonPanel.add(blueButton);
  35. buttonPanel.add(redButton);
  36.  
  37. //add panel to frame
  38. add(buttonPanel);
  39.  
  40. //create button actions
  41. ColorAction yellowAction = new ColorAction(Color.YELLOW);
  42. ColorAction blueAction = new ColorAction(Color.BLUE);
  43. ColorAction redAction = new ColorAction(Color.RED);
  44.  
  45. yellowButton.addActionListener(yellowAction);
  46. blueButton.addActionListener(blueAction);
  47. redButton.addActionListener(redAction);
  48. }
  49.  
  50.  
  51. private class ColorAction implements ActionListener
  52. {
  53. public ColorAction(Color c)
  54. {
  55. backgroundColor = c;
  56. }
  57. public void actionPerfomed(ActionEvent event)
  58. {
  59. buttonPanel.setBackground(backgroundColor);
  60. }
  61.  
  62. private Color backgroundColor;
  63. }
  64. private JPanel buttonPanel;
  65.  
  66. public static final int DEFAULT_WIDTH = 300;
  67. public static final int DEFAULT_HEIGHT = 200;
  68. }

the error says that the ColorAction is not abstract and does not override abstract method
__________________
-------------------------------------------------------------------------
I thought what I'd Do was, I'd pretend to be one of those deaf mutes
------------------------------------------------------------------------
JD-Salinger is offline   Reply With Quote
Old Jul 11th, 2008, 6:54 PM   #2
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,254
Rep Power: 5 grumpy will become famous soon enough
Re: Error in Inner Class

You've made a typo. The name "actionPerformed" needs two r's not one.
grumpy is offline   Reply With Quote
Old Jul 11th, 2008, 10:47 PM   #3
JD-Salinger
Unknown
 
JD-Salinger's Avatar
 
Join Date: Apr 2008
Location: unknown
Posts: 87
Rep Power: 1 JD-Salinger is on a distinguished road
Re: Error in Inner Class

Thnk grumpy
__________________
-------------------------------------------------------------------------
I thought what I'd Do was, I'd pretend to be one of those deaf mutes
------------------------------------------------------------------------
JD-Salinger is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
template class brad sue C++ 1 Mar 25th, 2007 6:46 PM
URL class Eric the Red Java 5 Jun 24th, 2006 10:01 PM
Problem with class constructor paeck C++ 8 Feb 7th, 2006 1:53 PM
using classes in another class ling_wong C++ 6 Jan 23rd, 2006 10:55 PM
MFC/OpenGL: problem with 'Document' class brenda C++ 11 May 23rd, 2005 9:10 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:51 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC