Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Jason Perry   on Feb 11 In Java Category.

  
Question Answered By: Percy Morgan   on Feb 11

Here is a simple and primitive example  for you.Don't forget to use setVisible
method of JFrame.
Regards

public class JFrmMainWindow extends JFrame implements
java.awt.event.ActionListener{
JButton newWindow = new JButton();
public JFrmMainWindow() {
init();
}
public static void main(String[] args) {
JFrmMainWindow jFrmMainWindow = new JFrmMainWindow();

}
private void init() {
newWindow.setBounds(new Rectangle(134, 211, 132, 45));
newWindow.setText("New Window");
newWindow.addActionListener(this);
this.setSize(500,400);
this.getContentPane().setLayout(null);
this.getContentPane().add(newWindow, null);
this.setVisible(true);
}

private void createNewWindowAndShowIt(){
JFrame newWindow=new JFrame();
newWindow.setSize(100,100);
newWindow.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
createNewWindowAndShowIt();
}
}

Share: