就是一个从数据库查询数据的小程序点'查询'的时候一个JOptionPane.showInputDialog(....);
输入后显示另外一个子数据frame,但是现在问题出现了,当我点多个'查询'的时候(没有关闭前面的子数据frame).当前子frame的功能都不能用了,比如我定义的
JMenuItem close=new JMenuItem("退出",new ImageIcon("images/exit.gif"));
close.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
_idText.setText("");    //id  text
_nameText.setText("");  // name text
_frame.dispose();   
}
});
关闭的不是这个子frame  而是另外一个.很郁闷~~~~
大概代码如下:
public class searchIDAction extends AbstractAction{   
                                     //显示对应数据的子frame,接收主frame的ActionListener
JFrame _frame;
JPanel _panel;
JLabel _idLabel;
JLabel _nameLabel;
JTextField _idText;
JTextField _nameText;
JMenuBar _menuBar;
//-----------入口-----
public void actionPerformed(ActionEvent e){
input=JOptionPane.showInputDialog(null,"输入要查找的ID","输入",JOptionPane.QUESTION_MESSAGE);
showPanel(input);  //显示子frame
}
public void showPanel(String input){
..
initComponent();   //初始化组件
initMenu();   //生成Menu
initText(id,name); //生成text
initFrame(); // frame加载组件
}