• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calling another GUI class

 
arnie frenato
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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?
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
arnie frenato
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about putting another button on the AnotherClass and that button will have an action to perform?
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
arnie frenato
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
arnie frenato
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, how do I add actionlisteners to this buttons?
 
Jonathan Janisch
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
button.addActionListener(...) what's '...' ?
 
Jonathan Janisch
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic