不就是frame.setVisible(true);就可以了

解决方案 »

  1.   

    不行亚
    在Frame2中不能用frame。setvisible(true)
      

  2.   

    我建议改一下程序,方法如下
    创建主界面,同你上面一样
    Frame1 frame = new Frame1();
        
        frame.setVisible(false);
    然后不要再用一个JFrame而改做由frame调用一个Dialog作为登录界面
    再由Dialog返回值决定是否frame.setVisible(true);
      

  3.   

    楼上说得对,楼主的可以如下实现import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;public class test extends JFrame implements ActionListener{
    JButton jb = new JButton("打开");
    public test(){
    this.getContentPane().add(jb);
    jb.addActionListener(this);
    this.setTitle("frame1");
    this.pack();
    this.show();
    }

    public static void main(String a[]){
    new test();
    }

    public void actionPerformed(ActionEvent e) {
        if(e.getActionCommand().equals("打开")){
         Frame frame2 = new Frame("frame2");
         frame2.setSize(400,300);
         this.setVisible(false);
         frame2.show();
        }
        }
    }