【发布时间】:2016-10-23 03:00:29
【问题描述】:
一段时间以来,我一直在尝试打开不同的JFrame AdminHome,但它没有打开。即使我做了JFrame的方法
AdminHome hmscrn = new AdminHome();
它所做的只是关闭我已经完成的框架并完全结束程序而不是打开主页
private void addBttnActionPerformed(java.awt.event.ActionEvent evt) {
try{
String sql = "insert into maintainsite (siteID,country,state,city,revenue,date,capacity) values (?,?,?,?,?,?,?)";
pst=conn.prepareStatement(sql);
pst.setString(1, (String) siteID.getSelectedItem());
pst.setString(2, (String) country.getSelectedItem());
pst.setString(3, (String) state.getSelectedItem());
pst.setString(4, (String) city.getSelectedItem());
pst.setString(5, revenuelb.getText());
pst.setString(6, ((JTextField) date.getDateEditor().getUiComponent()).getText());
pst.setString(7, capacitylb.getText());
pst.execute();
int replying = JOptionPane.showConfirmDialog(null, "information saved! return to home page?","successful", JOptionPane.YES_NO_OPTION);
if (replying == JOptionPane.YES_OPTION) {
JOptionPane.showMessageDialog(null, "got it!");
close();
AdminHome hmscrn = new AdminHome();
hmscrn.setVisible(true);
}
else {
JOptionPane.showMessageDialog(null, "close program!");
close();
}
}
catch(Exception e){JOptionPane.showMessageDialog(null, "please complete your selection and try again");}
}
【问题讨论】:
-
你的 close() 方法是什么样的?如果它包含 System.exit(),那么您的程序将在该点终止。
-
异常的目的是告诉你哪里出了问题。与其忽略它,不如在你的 catch 块中尝试
e.printStackTrace();。 -
1) 请参阅The Use of Multiple JFrames, Good/Bad Practice? 2) 如需更快的帮助,请尽快发布minimal reproducible example 或Short, Self Contained, Correct Example。硬编码一些数据来替换数据库。