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.
posted 9 years ago
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