如果将TwoDialog类包含在OnePane类中可以实现,但分成两个单独的类就不知道怎么做了。

解决方案 »

  1.   

    方法1、把oneTable的句柄传到TwoDialog里
    方法2、在TwoDialog按完twoButton后发个事件通知oneTable刷新
      

  2.   

    Dialog作为OnePane 的private class。关闭dialog的时候,设置OnePane的类变量。然后刷新table, tableModel.addRow(Vector rowData)
      

  3.   

    1、
    public class TwoDialog extends JDialog{
        JTextField twoText;
        JButton twoButton;
        JTable oneTable;
        TwoDialog(){
            twoText = new JTextField("  ",12);
            twoButton = new JButton("ok");
            add(new twoText, BorderLayout.CENTER);
            add(twoButton, BorderLayout.EAST);
        }
        twoButton.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ev){
                //将twoText数据写到数据库中
                ?????更新oneTable的数据?????
                oneTable.update();
       twoDialog.setVisible(true);
            }
        });
        public void setTable(JTable table){
            oneTable = table;
        }
    }
      

  4.   

    oneButton.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ev){
                twoDialog =null;
       twoDialog = new twoDialog(mainFrame);
                twoDialog.setTable(oneTable);//把oneTable传进去
       twoDialog.setVisible(true);
            }
        });
      

  5.   

    方法1、把oneTable的句柄传到TwoDialog里
    方法2、在TwoDialog按完twoButton后发个事件通知oneTable刷新
      

  6.   

    2、
    interface DialogListener{
    void dialogButtonActioned(ButtonActionEvent e);
    }
    public ButtonActionEvent {
    //这个可以根据你的要求定义里面的属性
    }
    public class OnePane extends JPanel implements DialogListener{
    public void dialogButtonActioned(ButtonActionEvent e){
    oneTable.update();
    }
    }    oneButton.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ev){
                twoDialog =null;
       twoDialog = new twoDialog(mainFrame);
                twoDialog.addDialogListener(this);
       twoDialog.setVisible(true);
            }
        });public class TwoDialog extends JDialog{
        JTextField twoText;
        JButton twoButton;
        Vector listeners = new Vector();
        TwoDialog(){
            twoText = new JTextField("  ",12);
            twoButton = new JButton("ok");
            add(new twoText, BorderLayout.CENTER);
            add(twoButton, BorderLayout.EAST);
        }
        twoButton.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ev){
                //将twoText数据写到数据库中
                ?????更新oneTable的数据?????
                fireButtonActionEvent(new ButtonActionEvent());
       twoDialog.setVisible(true);
            }
        });
        public void fireButtonActionEvent(ButtonActionEvent e){
            for(int i = 0 ; i < listeners.size() ; i++)
            {
                 ((DialogListener)listeners.elementAt(i)).dialogButtonActioned(e);
            }
        }
        public void addDialogListener(DialogListener listener){
            listeners.addElement(listener);
        }
        public void removeDialogListener(DialogListener listener){
            listeners.remove(listener);
        }
    }
      

  7.   

    下次我回复帖子的时候也Ctrl+c,Ctrl+v好了,混分的好办法啊
      

  8.   

    public ButtonActionEvent {
    //这个可以根据你的要求定义里面的属性
    }
    忘写class了
    public class ButtonActionEvent {
    //这个可以根据你的要求定义里面的属性
    }