Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with ActionPerformed  RSS feed

 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have this wierd problem in my program (I'm a nube so it must be a basic stuff). It is a GUI problem where are 3 classes +main class - buttonPanel, infoPanel and Stats.
This buttonPanel has buttons and ActionPerformed method. Infopanel has a basic constructor and methods that should show stuff on infoPanel. And this Stats class has just a constructor.
What my goal right now is, is to make a program so that when i press on buttonPanel - Stats class appears to infoPanel.
Problem is when everything should be ok it doesen't work - it shows a blank panel on infopanel + to the console on the background it gives me stuff about action performed things EventDispatchThread - don't know what to do wiht that.
code:

[ February 18, 2004: Message edited by: Juhan Voolaid ]
 
Lalit K Kumar
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know ,of all the components you have used, you can add "actionlistener" only to the jButton. In the snapshot of your code I can'nt see you attaching a listener to any of your code. Add the listener ("addactionlistener") to your respective button (in the constructor) and let me know in case of any confusion.
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eee... didn't quite get that. I am adding actionlistener to my buttons in my code. Tell me what should i change in my code in your point of view.
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should invoke validate() after add(stats). This is so because you modified the content of the JPanel after it was shown.
Button b1 was added twice to container!
hero class does not have to extend Frame because the one you are using is created in hero constructor.
The class stats is not needed. Make the variable stats in infoPannel of type JLabel instead.
The Java Tutorial is very useful to learn GUI stuff.
The convention of using Capital names for Types is a wise thing to do.
[ February 19, 2004: Message edited by: Jose Botella ]
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I'm still doing my first steps in java and all the help is very welcome. And yes - i itended to add button b1 2 times.
[ February 21, 2004: Message edited by: Juhan Voolaid ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!