日期:2014-05-20 浏览次数:20740 次
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.table.*;
import java.lang.Object.*;
import java.util.*;
import java.sql.*;
public class DengLu extends JFrame implements ActionListener{
public static void main(String[] args){
new DengLu();
//i.t();
}
JButton b1=new JButton("登陆");
JLabel l1=new JLabel("用户名");
JLabel l2=new JLabel("密码");
JTextField t1=new JTextField(10);
JTextField t2=new JTextField(10);
String id=null;
String password=null;
String passwordD;
public int screanWidth1,screanHeight1;
public DengLu()
{
Toolkit tool=getToolkit();
Dimension dim=tool.getScreenSize();
screanWidth1=dim.width;
screanHeight1=dim.height;
setTitle("超市管理系统登录界面");
setLayout(null);
add(b1);
add(l1);
add(l2);
add(t1);
add(t2);
l1.setBounds(130,45,50,40);
t1.setBounds(210,55,100,25);
l2.setBounds(130, 120, 50,40);
t2.setBounds(210,130,100,25);
b1.setBounds(210, 200, 60, 20);
b1.addActionListener(this);
// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(dim.width/3,dim.height/3,500,300);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b1) {
id=t1.getText();
password=t2.getText();
Connection con;
Statement sql;
ResultSet rs;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:SuperMaket";
con=DriverManager.getConnection(url);
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM CustomMessage where ID='"+id+"'");
while(rs.next())
{
passwordD=rs.getString(2);
}
// persontyD=rs.getString(3);}
con.close();
}
catch?(SQLException g)
{
System.out.println(g);
}
if(password.equals(passwordD))
{
new ZhuJieMian();
this.setVisible(false);
}
else
{
JOptionPane.showMessageDialog(this,"帐户或密码错误\n请重新输入","提示",JOptionPane.WARNING_MESSAGE);
}
}
}