按钮增加监听器如下, 即可显示一个空的Dialog, So easy...private void jButton1ActionPerformed(ActionEvent evt) 
        {
            JDialog dlg = new JDialog(); 
            dlg.setSize(new Dimension(400, 400));
            dlg.setVisible(true);   
        }

解决方案 »

  1.   

    我的意思是说,我建立了一个主窗口,上面是程序的各个功能,用button打开程序的分窗口来实现功能,进行程序的操作.
      

  2.   

    class frame1 extends JFrame{
        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();
        }
    }
      

  3.   

    在JDialog1上有个按钮,打开JDialog2窗口进行操作,在按ESC键时关闭JDialog2退回到JDialog1.
      

  4.   

    漏了一段:在frame类中
    public static void main(String [] args){
        new frame();
    }
      

  5.   

    我给你来个例子import java.awt.event.*;import javax.swing.*;public class TestDialog extends JDialog implements ActionListener
    {
    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();
    }
    }
      

  6.   

    最好是写两个Frame类(Frame1 and Frame2),然后在Frame1中的actionListener事件中
    填加语句 new Frame2,
    这样可以实现你说的功能
      

  7.   

    button.addActionListener(new ActionListener(){
       public void actionPerformed(ActionEvent ae){
           frame2.show();
       }
    );
      

  8.   

    我已经试出来了,只要在button的代码中加上
    JFrame jframe=new JFrame();
             jframe.show();
    就可以了.
    呵呵,谢谢各位的帮助!