package com.ajie;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Test9 extends JFrame implements ActionListener{
JButton jbutton=null;
public static void main(String[] args) {
// TODO Auto-generated method stub
Test9 test=new Test9();
}
public Test9(){
jbutton=new JButton("点击打开窗口2");
jbutton.addActionListener(this);
this.add(jbutton);
this.setTitle("窗口1");
this.setBounds(200, 200, 600, 300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent arg0) {
if(arg0.getSource()==jbutton){
//创建一个新窗口
new Jframe2();
}
}
}
//这个类可以单独写在同包下目录 也可以在这直接写
class Jframe2 extends JFrame{
public Jframe2(){
this.setTitle("窗口2");
this.setBounds(200, 200, 600, 300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}