我有一个我在 fedora 14 中开发的 java swing 应用程序,应用程序在 fedora 14 上正常工作,没有任何问题。但是当我在 Windows 7 上尝试它时,它无法正常工作。菜单栏显示父菜单项,但单击父菜单项时不显示菜单,选项卡式窗格显示为黑色。系统似乎冻结了。我在 widows xp 中尝试了这一点,并得到了与图形相同的结果。请告诉我申请中可能出现的错误。
这是起点的代码,
public class SplashScreen extends javax.swing.JFrame {
String filePath = File.separator;
static final Logger logger = Logger.getLogger(SplashScreen.class);
/** Creates new form SplashScreen */
public SplashScreen() {
initComponents();
setSize(400, 250);
setLocationRelativeTo(null);
try {
initSetup();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void initSetup() throws Exception {
new Thread(new Runnable() {
@Override
public void run() {
Connection con = null;
try {
Thread.sleep(1000);
con = JDBCConnectionPool.getInstance().checkOut();
if (con == null) {
lblMessage.setText("No database connection found!");
logger.debug("No database connection found!");
} else {
lblMessage.setText("Loading the system...");
}
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, ex.getLocalizedMessage());
logger.debug(ex.getMessage());
} finally {
if (con != null) {
try {
PropertyConfigurator.configure(this.getClass().getClassLoader().getResource("conf/log4j.properties"));
logger.info("Starting the system!");
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, e.getLocalizedMessage());
}
new Login().setVisible(true);
dispose();
JDBCConnectionPool.getInstance().checkIn(con);
return;
}
lblMessage.setText("Error occured... exiting the system");
try {
Thread.sleep(500);
System.exit(0);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}).start();
}
登录屏幕
/** Creates new form Login */
public Login() {
userAuth = new UserAuthentication();
initComponents();
add(pnlControlls);
addButtonListeners();
addTextFieldListeners();
setSize(400, 250);
setTitle("Loging");
//pack();
setLocationRelativeTo(null);
}
private void login() {
txtAlert.setText("");
UserDTO user = new UserDTO();
char[] p = txtPassword.getPassword();
String pw = "";
for (int i = 0; i < p.length; i++) {
pw = pw + p[i];
}
user.setUsername(txtUsername.getText());
user.setPassword(StringHasher.getInstance().getHash(pw));
UserDTO authUser = userAuth.authenticate(user);
if (authUser == null) {
txtAlert.setText("<html>Internal error...</html>");
} else {
if (authUser.getIsActive() && authUser.isIsAvailable()) {
Main main = Main.getInstance();
CurrentUser.getInstance().setUserName(authUser.getUsername());
Main.getInstance().setUserName(authUser.getUsername());
Main.getInstance().setFullNameOnUserName(authUser.getFullName());
Main.getInstance().prepareMenu();
Main.getInstance().setVersion(System.getProperty("version"));
main.setVisible(true);
SwingUtilities.updateComponentTreeUI(main);
this.dispose();
//here Main is the main user gui interface which user interacts with
} else if (!authUser.getIsActive() && authUser.isIsAvailable()) {
txtAlert.setText("<html>User account is inactive!</html>");
} else {
txtAlert.setText("<html>Username or password is incorrect, <br> please check again.</html>");
}
}
}
有时,当我最小化和最大化应用程序时会出现下拉菜单,但菜单重叠如下,