当更新学生信息关闭时,它将刷新学生信息系统上的数据并清除搜索文本框中的数据。请帮忙!当我关闭JFrame2时,我想清除JFrame1中的jtextfile,我该怎么办?
以下是我已经试过了,但它不工作!
public class UpdateInfo extends JFrame{
public JPanel pParent;
public JTextField jtfStudentID;
public JTextField jtfStudentName;
public JTextField jtfGender;
public JTextField jtfAddres;
private JButton updateButton;
private JButton cancelButton;
private StudentList stu;
public UpdateInfo() {
super("Update Student Information ");
setContentPane(pParent);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setPreferredSize(new Dimension(650, 350));
pack();
setLocationRelativeTo(null);
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
stu = new StudentList();
stu.jtfSearch.setText("");
dispose();
}
});
}
}
你可以在你的框架上调用'WindowListener',关闭框架的动作,你可以做任何你想做的事情。阅读更多关于WindowListener的链接(https://docs.oracle.com/javase/7/docs/api/java/awt/event/WindowListener.html) –