按钮增加监听器如下, 即可显示一个空的Dialog, So easy...private void jButton1ActionPerformed(ActionEvent evt)
{
JDialog dlg = new JDialog();
dlg.setSize(new Dimension(400, 400));
dlg.setVisible(true);
}
{
JDialog dlg = new JDialog();
dlg.setSize(new Dimension(400, 400));
dlg.setVisible(true);
}
public frame1(){
setSize(300,300);
setVisible(false);
}
}
public class frame extends JFrame{
private JButton button = new JButton("Show");
public frame(){
setSize(300,300);
getContentPane().add(button);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
new frame1().show();
}
});
show();
}
}
public static void main(String [] args){
new frame();
}
{
private JButton jb1 = new JButton("Show Dialog2");
private JButton jb2 = new JButton("Show Dialog1");
private JDialog jd2 = new JDialog(); TestDialog()
{
initJD1();
initJD2();
} private void initJD1()
{
setTitle("Dialog1");
getContentPane().setLayout(null);
getContentPane().add(jb1);
jb1.setSize(150, 25);
jb1.addActionListener(this);
setSize(400, 400);
setVisible(true);
} private void initJD2()
{
jd2.setTitle("Dialog2");
jd2.getContentPane().setLayout(null);
jd2.getContentPane().add(jb2);
jb2.setSize(150, 25);
jb2.addActionListener(this);
jd2.setSize(400, 400);
} public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source == jb1)
{
this.setVisible(false);
jd2.setVisible(true);
}
else if(source == jb2)
{
jd2.setVisible(false);
this.setVisible(true);
} } public static void main(String[] args)
{
new TestDialog();
}
}
填加语句 new Frame2,
这样可以实现你说的功能
public void actionPerformed(ActionEvent ae){
frame2.show();
}
);
JFrame jframe=new JFrame();
jframe.show();
就可以了.
呵呵,谢谢各位的帮助!