package denglu;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.sql.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Frame1 extends JFrame {
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JTextField jT1 = new JTextField();
JPasswordField jP1 = new JPasswordField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel3 = new JLabel();
JTextField jT2 = new JTextField();
JLabel jLabel4 = new JLabel();
JPasswordField jP2 = new JPasswordField();
JLabel jLabel5 = new JLabel();
JPasswordField jP3 = new JPasswordField();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jLabel1.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel1.setText("用户名:");
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(238, 257));
this.setTitle("用户登陆界面");
jLabel2.setText("密 码:");
jLabel2.setFont(new java.awt.Font("Dialog", 0, 14));
jT1.setText("");
jP1.setText("");
jButton1.setText("登陆");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
jButton2.setText("退出");
jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));
jLabel3.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel3.setText("提 示:");
jT2.setText("");
jLabel4.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel4.setText(" 新密码:");
jP2.setText("");
jLabel5.setText(" 新密码:");
jLabel5.setFont(new java.awt.Font("Dialog", 0, 14));
jP3.setText("");
contentPane.add(jButton2, new XYConstraints(131, 194, 58, 29));
contentPane.add(jButton1, new XYConstraints(37, 193, 58, 29));
contentPane.add(jT1, new XYConstraints(89, 6, 103, 28));
contentPane.add(jLabel1, new XYConstraints(30, 7, -1, -1));
contentPane.add(jLabel2, new XYConstraints(27, 39, -1, -1));
contentPane.add(jP1, new XYConstraints(90, 38, 105, 30));
contentPane.add(jLabel4, new XYConstraints(27, 70, -1, -1));
contentPane.add(jP2, new XYConstraints(90, 74, 105, 30));
contentPane.add(jLabel5, new XYConstraints(28, 111, -1, -1));
contentPane.add(jP3, new XYConstraints(91, 108, 105, 30));
contentPane.add(jLabel3, new XYConstraints(29, 156, -1, -1));
contentPane.add(jT2, new XYConstraints(93, 152, 103, 28));
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void jButton1_actionPerformed(ActionEvent e) {
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=Test";
String username = "sa";
String password = "";
Connection con = DriverManager.getConnection(url, username, password);
Statement stmt = con.createStatement();
String s1 ="select * from userandpwd where username='" +
jT1.getText().trim() +"' and pwd='"+jP1.getText().trim()+"'";
ResultSet rs = stmt.executeQuery(s1);
if (!rs.next())
jT2.setText("该用户不存在");
else if(!jP2.getText().trim().equals(jP3.getText().trim()))
jT2.setText("密码不对");
else {
s1="update userandpwd set pwd='"+jP2.getText().trim()+
"' where username='"+jT1.getText().trim()+"'";
stmt.executeUpdate(s1);
jT2.setText("密码修改成功");
}
}catch(Exception e1){
e1.printStackTrace();
}
}
void jButton2_actionPerformed(ActionEvent e) {
System.exit(0);
}
}
class Frame1_jButton1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_jButton1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class Frame1_jButton2_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_jButton2_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
评论0