Java表单和子表单

时间:2016-05-25 18:40:22

标签: java swing

我有一个父表单和我的应用程序的子表单。现在,在我的按钮处理程序中打开子表单,我有以下代码:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) 
{
        // TODO add your handling code here:
        SubForm test = new SubForm();
        Author retriveAuthor = null;
        test.setVisible(true);
        retriveAuthor = test.getAuthor();
        jTextField3.setText(retriveAuthor.getFirstName());
}

子表格:

    Author subCreateAuthor;

   public SubForm() {
       initComponents();
   }

   public Author getAuthor()
   {
       return this.subCreateAuthor;
   }

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
     // TODO add your handling code here: 
    //When the user clicks the button Create Author it will 
    //grab the text from the two text boxes and then create the author object.
    //Afterward it will set the form visible parameter to false.
    subCreateAuthor = new Author(jTextField1.getText(),jTextField2.getText());
    this.setVisible(false);
 }

我的问题是,当我调用子表单时,父表单不会等到子表单关闭,它尝试设置jtextfield3的文本,但是,它会抛出nullpointerexception,因为尚未完全创建retrieveAuthor对象。如何正确调用我的子表单,然后在表单关闭时将jTextField设置为我的Author对象?

我尝试将子表单可见性设置为false,然后在我的主表单中检查它,但这不起作用。

0 个答案:

没有答案