单击按钮时摆动创建两个框架

时间:2013-12-14 08:11:29

标签: java swing jframe

我有两个类,一个扩展JFrame,它是一个swing类,另一个是普通类。现在,我将点击JButton调用普通类,我希望将普通类中的值嵌入到swing类JTextArea中。

Based on this solution

但是当我点击按钮时会创建另一个帧。我知道我两次调用swing类的构造函数。但我不知道如何克服这个问题。

我将从swing类中的main方法调用Swing框架。但是当我单击按钮时,我创建了另一个帧,因为我再次调用构造函数。如何克服这个问题?

SwingClass

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         


        Grid grids=new Grid();
        grids.setVisible(true); // based on the above solution

        int user=Integer.parseInt(jTextField1.getText());
        if(jTextField1.getText().equals(null))
        {
        JOptionPane.showMessageDialog(rootPane,"Please Enter the users");
        }
        else
        {
        GridSourceClass.caller("Grid Class Called",grids,user);
        }

    }    

0 个答案:

没有答案
相关问题