怎样刷新表格数据? 如果将TwoDialog类包含在OnePane类中可以实现,但分成两个单独的类就不知道怎么做了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 方法1、把oneTable的句柄传到TwoDialog里方法2、在TwoDialog按完twoButton后发个事件通知oneTable刷新 Dialog作为OnePane 的private class。关闭dialog的时候,设置OnePane的类变量。然后刷新table, tableModel.addRow(Vector rowData) 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; }} oneButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ev){ twoDialog =null; twoDialog = new twoDialog(mainFrame); twoDialog.setTable(oneTable);//把oneTable传进去 twoDialog.setVisible(true); } }); 方法1、把oneTable的句柄传到TwoDialog里方法2、在TwoDialog按完twoButton后发个事件通知oneTable刷新 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); }} 下次我回复帖子的时候也Ctrl+c,Ctrl+v好了,混分的好办法啊 public ButtonActionEvent {//这个可以根据你的要求定义里面的属性}忘写class了public class ButtonActionEvent {//这个可以根据你的要求定义里面的属性} 求助String转JSONObject问题 打包好的jar文件没法执行 关于runtime求助 my-proxy.com 捉取代理 关于基础类库中框架的问题,急急!!给分100 一个线程间通信问题 请问split函数如何写? 谁帮我看看这个书上的例子 菜鸟提问,请大虾帮助!!! java不用jni应该不能做ftp服务器吧 如何在java中调用dll中定义的函数? 如何才能在struts中以最简单的方式获得返回值?
方法2、在TwoDialog按完twoButton后发个事件通知oneTable刷新
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;
}
}
public void actionPerformed(ActionEvent ev){
twoDialog =null;
twoDialog = new twoDialog(mainFrame);
twoDialog.setTable(oneTable);//把oneTable传进去
twoDialog.setVisible(true);
}
});
方法2、在TwoDialog按完twoButton后发个事件通知oneTable刷新
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);
}
}
//这个可以根据你的要求定义里面的属性
}
忘写class了
public class ButtonActionEvent {
//这个可以根据你的要求定义里面的属性
}