java弹出对话框

java弹出对话框

我想在一个Panel中弹出另外一个Panel,该怎么写?
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;

public class FrameTest extends JFrame {

private static final long serialVersionUID = 1L;

private int lx = 200;

private int ly = 200;

public FrameTest(){

}

public FrameTest(int x , int y) {
this.lx = x;
this.ly = y;
this.setBounds(lx, ly, 400, 300);
}

public void init(){
this.setBounds(lx, ly, 400, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(null);
JButton bton = new JButton("EXIT");
JButton bnew = new JButton("NEW");
bton.setBounds(80, 80, 80, 50);
bnew.setBounds(180, 80, 80, 50);
bnew.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {
new FrameTest(200, 400).init();
}

});
bton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
this.add(bton);
this.add(bnew);
this.setVisible(true);
}

public static void main(String[] args) {
new FrameTest().init();
}

}
← 上一篇: 下一篇: →