import java.awt.event.ActionEvent; import java.awt.event.ActionListener;import javax.swing.*;public class Test extends JFrame{ private JButton jb=null; private Test2 t2=null; public Test(){ jb = new JButton("按钮"); jb.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ jb_actionPerformed(e); } }); this.add(jb); this.setBounds(200, 200, 400, 300); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} public void jb_actionPerformed(ActionEvent e){ if(t2==null){ t2 = new Test2(); } } public static void main(String[]args){ Test t = new Test(); } } class Test2 extends JFrame { public Test2(){ this.setBounds(200, 200, 400, 300); this.setVisible(true); } }
import java.awt.event.ActionListener;import javax.swing.*;public class Test extends JFrame{
private JButton jb=null;
private Test2 t2=null;
public Test(){
jb = new JButton("按钮");
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jb_actionPerformed(e);
}
});
this.add(jb);
this.setBounds(200, 200, 400, 300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void jb_actionPerformed(ActionEvent e){
if(t2==null){
t2 = new Test2();
}
}
public static void main(String[]args){
Test t = new Test();
}
}
class Test2 extends JFrame {
public Test2(){
this.setBounds(200, 200, 400, 300);
this.setVisible(true);
}
}