import java.awt.Button; import java.awt.Frame; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; @SuppressWarnings("serial") public class Login extends Frame{ public Login(String str){ super(str); } static Login fr = new Login("测试Panel"); public static void main(String[] args){ fr.setSize(500, 500); fr.setLocation(500, 300); fr.setBackground(null); fr.setLayout(null); Button button = new Button("点击我"); button.setSize(50, 25); //button.setBorderPainted(false); button.setLocation(50, 50); button.addActionListener(new ActionListener(){ //单击按钮执行的方法 public void actionPerformed(ActionEvent e) { closeThis(); //建立新的窗口 JFrame frame = new JFrame("新窗口"); //设置在屏幕的位置 frame.setLocation(100,50); // 窗体大小 frame.setSize(500,500); // 显示窗体 frame.setVisible(true); } }); JButton button1 = new JButton("点"); button1.setSize(50, 25); button1.setBackground(null); button1.setBorderPainted(false); button1.setLocation(50,80 ); button1.addActionListener(new ActionListener(){ //单击按钮执行的方法 public void actionPerformed(ActionEvent e) { closeThis(); //建立新的窗口 JFrame frame1 = new JFrame("新窗口"); //设置在屏幕的位置 frame1.setLocation(100,50); // 窗体大小 frame1.setSize(200,200); JButton button2 = new JButton("点击我"); button2.setSize(50, 25); button2.setBorderPainted(false); button2.setLocation(50,80 ); button2.addActionListener(new ActionListener(){ //单击按钮执行的方法 public void actionPerformed(ActionEvent e) { closeThis(); //建立新的窗口 JFrame frame = new JFrame("新窗口"); //设置在屏幕的位置 frame.setLocation(200,50); // 窗体大小 frame.setSize(200,200); // 显示窗体 frame.setVisible(true); } }); Panel pan = new Panel(); pan.setSize(100, 100); frame1.add(button2); frame1.add(pan); // 显示窗体 frame1.setVisible(true); } }); fr.add(button); fr.add(button1); fr.setVisible(true); } public static void closeThis(){ fr.dispose(); } }