wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes calling another GUI class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "calling another GUI class" Watch "calling another GUI class" New topic
Author

calling another GUI class

arnie frenato
Greenhorn

Joined: Mar 08, 2007
Posts: 14
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?
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
arnie frenato
Greenhorn

Joined: Mar 08, 2007
Posts: 14
How about putting another button on the AnotherClass and that button will have an action to perform?
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
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


How simple does it have to be???
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
arnie frenato
Greenhorn

Joined: Mar 08, 2007
Posts: 14
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

Joined: Jan 14, 2004
Posts: 1535
arnie frenato
Greenhorn

Joined: Mar 08, 2007
Posts: 14
So, how do I add actionlisteners to this buttons?
Jonathan Janisch
Greenhorn

Joined: Mar 17, 2007
Posts: 24
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

Joined: Mar 08, 2007
Posts: 14
you can probably see that there is no variable assigned to the newly created buttons..
Jonathan Janisch
Greenhorn

Joined: Mar 17, 2007
Posts: 24
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

Joined: Mar 08, 2007
Posts: 14
button.addActionListener(...) what's '...' ?
Jonathan Janisch
Greenhorn

Joined: Mar 17, 2007
Posts: 24
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calling another GUI class
 
Similar Threads
Passing updated data back to a Main GUI and listening to button clicks
communicating/affecting another class
Class inheritence and GUI question
Alignment format on JTable
java import packages question