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

Open a new window to the press of a button  RSS feed

 
Ilh Oleo
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i am learning about swing and i want to know how can i open a new window when i push a button. I think it must to be an actionevent or a mouse click but i not sure about this.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for your button to do anything it does need a listener - normally that
would be an ActionListener, but can be MouseListener (trap here is MouseListener
will still work if button is disabled)

in ActionListener's actionPerformed(), if you want to open a new window,
assuming by 'window' you mean a new JFrame, the code is similar to how you
opened the original window
JFrame secondFrame = new JFrame();
secondFrame.addSomeComponents...
secondFrame.setSize
secondFrame.setLocation
secondFrame.someOtherStuff
secondFrame.setVisible(true);
etc
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!