java 登录页面问题

NetMatrix 2010-03-14 08:53:51
package test;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;

public class LoadFrame extends JFrame implements ActionListener{
private JLabel jlb1,jlb2;
private JTextField jtf1;
private JPasswordField jpf;
private JButton jbt1,jbt2;
//public static String name = null;
//public static String password = null;

public Connection conn = null;
public Statement stmt = null;
public ResultSet rs = null;
public String s2 = null;

public LoadFrame(){
jlb1 = new JLabel("用户名");
jlb2 = new JLabel("密码");
jtf1 = new JTextField();
jpf = new JPasswordField();

jbt1 = new JButton("登录");
jbt2 = new JButton("退出");

Toolkit tool = this.getToolkit();
Dimension dim = tool.getScreenSize();
int x = (dim.width-380)/2;
int y = (dim.height-300)/2;

this.setTitle("登录窗口");
this.setLayout(null);
this.setBounds(x,y,380,300);
this.setVisible(true);

this.add(jlb1);
jlb1.setBounds(55,55,70,50);
this.add(jtf1);
jtf1.setBounds(120,60,150,30);
this.add(jlb2);
jlb2.setBounds(55,115,70,50);
this.add(jpf);
jpf.setBounds(120,120,150,30);

this.add(jbt1);
jbt1.setBounds(60,180,80,30);
jbt1.addActionListener(this);
this.add(jbt2);
jbt2.setBounds(200,180,80,30);
jbt2.addActionListener(this);

}

public void ConnDB(){
try{
String url = "jdbc:sqlserver://localhost:1433; DatabaseName=Bus";
String userName = "sa";
String userPwd = "1101";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(url,userName,userPwd);
System.out.println("Connected");

}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}
}

public void actionPerformed(ActionEvent e){
if(e.getSource()==jbt2){
dispose();
}
if(e.getSource()==jbt1){
String str1,str2 = null;
ConnDB();
str1 = jtf1.getText();
try{

stmt = conn.createStatement();
rs = stmt.executeQuery("select * from bus_manager where Account='"+str1+"'");
while(rs.next()){
str2 = rs.getString("Password");
System.out.println(str2);
}
String str3 = new String(jpf.getPassword());
System.out.println(str3);
if(str2.equals(str3)){
JOptionPane.showMessageDialog(null,"登录成功");
MainFrame.jmi4.setEnabled(true);
MainFrame.jmi5.setEnabled(true);
dispose();
}else{
JOptionPane.showMessageDialog(null,"登录失败");
}


}catch(SQLException ex){
ex.printStackTrace();
}finally{
try{
rs.close();
conn.close();
stmt.close();
}catch(SQLException en){
en.printStackTrace();
}
}

}
}
}
大家帮我看一下,这段码下面的地方为什么不能执行?
if(str2.equals(str3)){
JOptionPane.showMessageDialog(null,"登录成功");
MainFrame.jmi4.setEnabled(true);
MainFrame.jmi5.setEnabled(true);
dispose();
}
...全文
258 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lryxxh 2010-03-15
  • 打赏
  • 举报
回复
你所谓的不能执行是什么意思?
gao512008 2010-03-15
  • 打赏
  • 举报
回复
Str2 str3 试试打印出什么内容
zliuzz 2010-03-15
  • 打赏
  • 举报
回复
swing。。。学习ing
SambaGao 2010-03-15
  • 打赏
  • 举报
回复
MainFrame.jmi4.setEnabled(true);
MainFrame.jmi5.setEnabled(true);

MainFrame.jmi5.show();
NetMatrix 2010-03-15
  • 打赏
  • 举报
回复
MainFrame是另一个类的对象
lryxxh 2010-03-14
  • 打赏
  • 举报
回复
你的MainFrame是什么东西?swing里没有这个类吧
Defonds 2010-03-14
  • 打赏
  • 举报
回复
又是 Swing。

62,624

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧