Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

open new window

 
sven pohle
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i'm new with java and swing and have the following prob
i build a gui with a few buttons. now i want to pop up a new window if i press a button.
i search for sample codes or similiar.
thnx in advance
 
Vijay Mitra
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JAVAWORLD.
For your button, for ex.
JButton myButton = new JButton("Open new window");
JFrame newFrame = new JFrame("New Window");
//add this line of code
myButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// open a new frame i.e window
newFrame.pack();
newFrame.setVisible(true);
}
});
Hope that would help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!