java可视化编程,通过登入界面进入主界面只显示空窗口,但单独运行主界面主界面正常。 15
protectedvoidloginActionPerformed(ActionEvente){StringuserName=this.userName.getText(...
protected void loginActionPerformed(ActionEvent e) {
String userName = this.userName.getText();
String password = new String(this.password.getText());
if(StringUtil.isEmpty(userName)){
JOptionPane.showMessageDialog(null, "用户名不能为空");
return;
}
if(StringUtil.isEmpty(password)){
JOptionPane.showMessageDialog(null, "密码不能为空");
return;
}
User user=new User(userName,password);
java.sql.Connection con = null;
try {
con = dbUtil.getCon();
User currentUser = userDao.login(con, user);
if (currentUser != null) {
JOptionPane.showMessageDialog(null, "登入成功");
dispose();
MainFrm mainfrm = new MainFrm();
mainfrm.setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误");
}
} catch (Exception e1) {
e1.printStackTrace();
JOptionPane.showMessageDialog(null, "登录失败");
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
登入界面的JFrame窗口有一个main方法,主界面也有main方法,这是windowbuilder自动生成的。打开主界面,我是直接实例化mainfrm,然后调用setvisible方法
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainFrm window = new MainFrm();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
} 展开
String userName = this.userName.getText();
String password = new String(this.password.getText());
if(StringUtil.isEmpty(userName)){
JOptionPane.showMessageDialog(null, "用户名不能为空");
return;
}
if(StringUtil.isEmpty(password)){
JOptionPane.showMessageDialog(null, "密码不能为空");
return;
}
User user=new User(userName,password);
java.sql.Connection con = null;
try {
con = dbUtil.getCon();
User currentUser = userDao.login(con, user);
if (currentUser != null) {
JOptionPane.showMessageDialog(null, "登入成功");
dispose();
MainFrm mainfrm = new MainFrm();
mainfrm.setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误");
}
} catch (Exception e1) {
e1.printStackTrace();
JOptionPane.showMessageDialog(null, "登录失败");
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
登入界面的JFrame窗口有一个main方法,主界面也有main方法,这是windowbuilder自动生成的。打开主界面,我是直接实例化mainfrm,然后调用setvisible方法
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainFrm window = new MainFrm();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
} 展开
1个回答
2018-01-01
展开全部
MainFrm 类的初始化过程,又是怎样的呢
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询