gpt4 book ai didi

java - 关闭 JFrame

转载 作者:行者123 更新时间:2023-12-01 11:20:09 24 4
gpt4 key购买 nike

我正在研究 jtable。对于该表的每一行(当我选择它时),我需要打开一个新的 jframe。打开应用程序后,我使用按钮进行简单的搜索,并第一次选择一行,它工作正常;当我关闭刚刚打开的这个新 jframe 时,问题就开始了我执行另一个搜索并选择
另一行;实际上,会打开多个具有相同内容的 jframe。这就像发送了多个请求。

此代码位于主应用程序中:

private static String QUERY_BASED_ON_SITE2="from WordsToFind a where a.wordToFindName like '";

private void runQueryBasedOnName2() {
executeHQLQuery2(QUERY_BASED_ON_SITE2 + jTextField14.getText() + "%'");
}

private void executeHQLQuery2(String hql2) {
try {
Configuration configuration = new Configuration().configure();
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
SessionFactory factory = configuration.buildSessionFactory(builder.build());
Session session = factory.openSession();
Query q2 = session.createQuery(hql2);
List resultsWords2 = (List) q2.list();
System.out.println("resultsWords2 ----> " + resultsWords2);
displayWords2(resultsWords2);
} catch (ClassNotFoundException ex) {
Logger.getLogger(ClientEditor.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(ClientEditor.class.getName()).log(Level.SEVERE, null, ex);
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
if(!jTextField14.getText().trim().equals("")) {
runQueryBasedOnName2();
}

}

private void displayWords2(List resultsWords2) throws ClassNotFoundException, InstantiationException {
Vector<String> tableHeaders2 = new Vector<String>();
final Vector tableWords2 = new Vector();
tableHeaders2.add("Word Id");
for(Object ow : resultsWords2) {
WordsToFind words;
words = (WordsToFind)ow;
Vector<Object> oneRowWords = new Vector<Object>();
oneRowWords.add(words.getWordToFindId());
tableWords2.add(oneRowWords);
}
jTable4.setModel(new DefaultTableModel(tableWords2, tableHeaders2));
jTable4.setAutoCreateRowSorter(true);
jTable4.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jTable4.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int selectedRow = jTable4.getSelectedRow();
selectedRow = jTable4.convertRowIndexToModel(selectedRow);
SimpleSwingBrowser browser = new SimpleSwingBrowser();
browser.setVisible(true);
browser.loadURL("http://www.google.com");
browser.highlihtWord();
}
});
}

我尝试将以下代码行添加到 SimpleSwingBrowser 类中

dispose();

还有

this.dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));

我得到了相同的结果。谢谢阿尔布

最佳答案

JFrame 获取关闭事件,关闭后退出。

    JFrame frame= new JFrame()
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// frame code here ..
frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));

关于java - 关闭 JFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31344232/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com