?? xueshenggaimi.java
字號:
package don;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class xueshenggaimi implements ActionListener
{
JFrame fxgmm = 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 xueshenggaimi()
{
//fxgmm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fxgmm.setSize(400, 350);
fxgmm.setResizable(true);
fxgmm.setLayout(null);
l0.setBounds(60, 30, 100, 30);
l1.setBounds(60, 70, 100, 30);
l2.setBounds(60, 120, 100, 30);
l3.setBounds(60, 170, 100, 30);
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,30);
b2.setBounds(200, 220, 100,30);
fxgmm.add(l0);
fxgmm.add(t0);
fxgmm.add(l1);
fxgmm.add(t1);
fxgmm.add(l2);
fxgmm.add(t2);
fxgmm.add(l3);
fxgmm.add(t3);
fxgmm.add(b1);
fxgmm.add(b2);
fxgmm.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 geren where sno='" + a + "' and smima='" + b + "'";
System.out.println(sql);
ResultSet rs1=db.executeQuery(sql);
try {
if(rs1.next()){
//檢測新密碼
if(!c.equals(d)){
JOptionPane.showMessageDialog(fxgmm,"兩次密碼不一致,請重新輸入!");
return;
}//否則修改密碼
else{
DBSource db1=new DBSource();
String sql1="update geren set smima='" + c + "' where sno='" + a + "'";
System.out.println(sql1);
boolean bb=db1.execute(sql1);
if(bb){
JOptionPane.showMessageDialog(fxgmm,"密碼修改成功!");
}
}
}else{
JOptionPane.showMessageDialog(fxgmm,message);
return;
}
}
catch (HeadlessException e1)
{
e1.printStackTrace();
}
catch (SQLException e1)
{
e1.printStackTrace();
}
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b2)
{
//System.exit(0);
fxgmm.setVisible(false);
}
}
public static void main(String args[])
{
new xueshenggaimi();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -