Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Problem with ActionPerformed

 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic