2014-01-08 41 views
0

我正在做一个汽车项目。我怎样才能使分配器框架弹出和汽车框架不可见并自动关闭?请简单有效地发送任何解决方案。 我做编码是这样的: - “请帮我如何才能让经销商框弹出和汽车框架是不可见的,靠近自动”如何在不使用swing的情况下连接NetBeans中的两个JFrame?

{ 
     Cars frm1=new Cars(); 
     Distributor frm2=new Distributor(); 
     frm2.setVisible(true); 
     frm1.setVisible(false); 
     frm1.setDefaultCloseOperation(frm1.DISPOSE_ON_CLOSE); 
    }           
+0

'JFrame' _without_ using'Swing' ...嗯。 –

+0

'如何关闭JFrame并在按下JButton后打开另一个?' – Sergi

+0

'javax.swing.JFrame' - 你知道你在说什么吗? –

回答

2

好了,所以在Netbeans的GUI Builder中,你可能想要做的(这是假设你已经创建了两个独立的JFrame表单文件

  • 在作为启动程序的框架下(我们” LL称之为MyFrame1)添加一个按钮,它(我们就叫它jButton1
  • 添加监听器按钮,然后将下面的代码应该是自动生成的

    public void jButton1ActionPerforemd(javax.swing.ActionEvent evt) { 
    
    } 
    
  • 在这种actionPerformed,只是实例化第二帧(我们就叫它MyFrame2)和setVisible(false)MyFrame1MyFrame2应该已经在实例可见,这样你就不必setVisisble(true)

    public void jButton1ActionPerforemd(javax.swing.ActionEvent evt) { 
        MyFrame2 frame2 = new MyFrame2(); 
        MyFrame1.this.setVisible(false); 
        // You can also use MyFrame1.this.dispose(); dependind if you ever need to use that frame again 
    } 
    

我认为这应该工作

+0

非常感谢你,它非常帮助我。 – KS1

0

你需要调用setVisible Jframe2作为真正的...所以它可以apear on output sceen

public void jButton1ActionPerforemd(javax.swing.ActionEvent evt) 
{ 
    myFrame2 frame2=new myframe2(); 
    myframe1.this.setVisible(false); 
    frame2.setVisible(true); 
} 
相关问题