?? guanligaimi.java
字號:
package don;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.sql.*;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class guanligaimi implements ActionListener
{
JFrame fglgm = new JFrame("修改密碼");
JLabel l0=new JLabel("輸入工號:");
JLabel l1 = new JLabel("輸入舊密碼:");
JLabel l2 = new JLabel("輸入新密碼:");
JLabel l3 = new JLabel("確認新密碼:");
JTextField t0=new JTextField(30);
JPasswordField t1=new JPasswordField(30);
JPasswordField t2=new JPasswordField(30);
JPasswordField t3=new JPasswordField(30);
JButton b1=new JButton("修改");
JButton b2=new JButton("取消");
public guanligaimi()
{
// fglgm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fglgm.setLayout(null);
fglgm.setSize(400, 350);
fglgm.setResizable(false);
l0.setBounds(60, 30, 100, 25);
l1.setBounds(60, 70, 100, 25);
l2.setBounds(60, 120, 100, 25);
l3.setBounds(60, 170, 100, 25);
t0.setBounds(150, 30, 100, 25);
t1.setBounds(150, 70, 100, 25);
t2.setBounds(150, 120, 100, 25);
t3.setBounds(150, 170, 100,25);
b1.setBounds(60, 220, 100,25);
b2.setBounds(200, 220, 100,25);
fglgm.getContentPane().add(l0);
fglgm.getContentPane().add(t0);
fglgm.getContentPane().add(l1);
fglgm.getContentPane().add(t1);
fglgm.getContentPane().add(l2);
fglgm.getContentPane().add(t2);
fglgm.getContentPane().add(l3);
fglgm.getContentPane().add(t3);
fglgm.getContentPane().add(b1);
fglgm.getContentPane().add(b2);
fglgm.setVisible(true);
b2.addActionListener(this);
b1.addActionListener
(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//System.out.println("wwwwww");
final String a;
final String b;
final String c;
final String d;
a=t0.getText();
b=t1.getText();
c=t2.getText().trim();
d=t3.getText().trim();
String message="工號或原密碼輸入有誤!";
DBSource db=new DBSource ();
String sql="select * from guanliyuan where dengluming='" + a + "' and gmima='" + b + "'";
System.out.println(sql);
ResultSet rs1=db.executeQuery(sql);
try {
if(rs1.next()){
//檢測新密碼
if(!c.equals(d)){
JOptionPane.showMessageDialog(fglgm,"兩次密碼不一致,請重新輸入!");
return;
}//否則修改密碼
else{
DBSource db1=new DBSource();
String sql1="update guanliyuan set gmima='" + c + "' where dengluming='" + a + "'";
System.out.println(sql1);
boolean bb=db1.execute(sql1);
if(bb){
JOptionPane.showMessageDialog(fglgm,"密碼修改成功!");
}
}
}else{
JOptionPane.showMessageDialog(fglgm,message);
return;
}
}
catch (HeadlessException e1)
{
e1.printStackTrace();
}
catch (SQLException e1)
{
e1.printStackTrace();
}
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b2)
{
fglgm.setVisible(false);
}
}
public static void main(String[] args)
{
new guanligaimi();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -