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

calling another GUI class

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
uhm, for example.. I created a class with a button in it.. If I click the button, I would like it to open another gui class that I've created.. How do i do that?
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
arnie frenato
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about putting another button on the AnotherClass and that button will have an action to perform?
 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont see why you cant

as long as the button you press has a listener for the action performed, and call the other class' gui method.

davy
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
arnie frenato
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, got it. Thanks. One last question. How do I do this - if a button is clicked, it'll create another button, label, or textfield - ?

Thanks again
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
arnie frenato
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, how do I add actionlisteners to this buttons?
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
arnie, that's kind of a silly question.

It's like asking, "Given the following code.."



"... how do you add an actionlistener to button2?"

Maybe this link will help you:

http://java.sun.com/docs/books/tutorial/uiswing/events/index.html
 
arnie frenato
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can probably see that there is no variable assigned to the newly created buttons..
 
Jonathan Janisch
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem:

Originally posted by arnie frenato:
you can probably see that there is no variable assigned to the newly created buttons..



Solution:

Assign them to a variable.




 
arnie frenato
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
button.addActionListener(...) what's '...' ?
 
Jonathan Janisch
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Programming is about problem solving.

Try to compile it and see what happens. If it gives you an error, try to figure out why. I believe you were using the addActionListener method earlier, maybe that might help.

The (JavaDoc for JButton says that addActionListener expects an ActionListener. '...' doesn't appear to be an Object, let alone an ActionListener. It doesn't even appear to be legal Java code!



If you really don't want to learn then I'll tell you the answer

You asked:

So, how do I add actionlisteners to this buttons?



The code I posted showed how to add an ActionListener to your dynamic buttons as you requested. You have to replace '...' with a object whose class implements the ActionListener interface. Craig already posted code that does this.
 
reply
    Bookmark Topic Watch Topic
  • New Topic