import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;
public class landing_page extends JFrame
{
JLabel name,password;
JTextField nametext;
JPasswordField passwordtext;
JButton tijiao,quxiao;
public landing_page()
{
super("欢迎登陆开心一科网上选课系统");
Container con = getContentPane();
JPanel panel = new JPanel();
panel.setBackground(Color.pink);
name = new JLabel("请输入用户名:");
password = new JLabel("请输入用户密码:");
nametext = new JTextField(15);
passwordtext = new JPasswordField(13);
tijiao = new JButton("提交");
quxiao = new JButton("取消");
panel.add(name);
panel.add(nametext);
panel.add(password);
panel.add(passwordtext);
tijiao.addActionListener(new tijiaoAction_performed());
panel.add(tijiao);
quxiao.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e )
{
//System.exit(0);
setVisible(false);
}});
panel.add(quxiao);
con.add(panel);
setSize(300,150);
setVisible(true);
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class tijiaoAction_performed implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(nametext.getText().equals(""))
{
JOptionPane.showMessageDialog(landing_page.this, "用户名不能为空!");
passwordtext.setText("");
}
else if (passwordtext.getText().equals(""))
JOptionPane.showMessageDialog(landing_page.this,"用户密码不能为空!");
else
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("成功加载JDBC_ODBC驱动程序!");
}
catch(ClassNotFoundException ex)
{
System.out.println("加载JDBC_ODBC驱动程序失败!");
System.out.println(ex.getMessage());
return ;
}
try
{
Connection connection = DriverManager.getConnection(
"jdbc:odbc:myDatabase");
Statement stmt = connection.createStatement();
String query = "select * from people where name='"+nametext.getText()+"'";
ResultSet rs = stmt.executeQuery(query);
if (!rs.next())
{
int i =JOptionPane.showConfirmDialog(null, "该用户名不存在,请先注册!");
passwordtext.setText("");
if (i == JOptionPane.OK_OPTION)
{
setVisible(false);
new login_page();
}
else
{
setVisible(false);
new zhuye_page();
}
//setVisible(false);
}
else
{
String s = rs.getString("name");
System.out.println(s); //这里可以看到输入的用户名是正确的
s = rs.getString("password");
System.out.println(s);//输出密码
//为什么,即使passwordtext赋得值和上面输出的密码一样,下面仍然说密码不一致
//rs.getString("password");返回值有什么问题吗???
if (!(passwordtext.getText().equals(s)))
{
JOptionPane.showMessageDialog(null,"与上次输入密码不一致,请重新输入!");
passwordtext.setText("");
}
else
{
new transient_page("祝贺你,登陆成功!");
setVisible(false);
}
}
connection.close();
}
catch(SQLException ec)
{
System.out.println("查询数据库失败!");
System.out.println("SQLException:"+ec.getMessage());
}
}
}
}
public static void main(String[] args)
{
new landing_page();
}
}