📄 login1.java
字号:
package denglu;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Login1 extends JPanel {
private volatile boolean isLogin;
private JButton ok,close;
public static JTextField userName;
private JPasswordField pwd;
private Image bg,login;
private JFrame jf;
private JLabel l1,l2,l3;
static String NF,sqlusername,sqlpsw;
Connection con;
Statement sql;
ResultSet rs;
public Login1() {
initOther();
initWindow();
}
private void initWindow(){
this.setLayout(null);
ok=new JButton("确定");
ok.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
isLogin=true;
repaint();
new Thread(new Runnable(){
String name=userName.getText().toString().trim();
String pwsd=pwd.getText().toString().trim();
String regex="\\d{1,}";
public void run(){
try{
Thread.sleep(1);
}
catch(Exception exe){
exe.printStackTrace();
}
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(ClassNotFoundException eve){
System.out.println(""+eve);
}
try{
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://202.115.80.180:2433;DatabaseName=JY06;user=jy06;password=jy06;");
sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs=sql.executeQuery("select * from UserMessage where username='" +
name + "' and pwsd='" + pwsd + "'");
if(name.matches(regex)){
if(rs.next()){
NF=rs.getString(1);
sqlusername=rs.getString(2);
sqlpsw=rs.getString(3);
if(NF.equals("0")){
new jilu();
new jiemian();
jf.dispose();
}
else{
JOptionPane.showMessageDialog(Login1.this,"对不起!此帐户已被冻结!","错误!",JOptionPane.ERROR_MESSAGE);
qingchu();
userName.setText(null);
}
}
else{
JOptionPane.showMessageDialog(Login1.this,"请输入正确的密码!","错误!",JOptionPane.ERROR_MESSAGE);
qingchu();
}
}
else
{
JOptionPane.showMessageDialog(Login1.this,"用户帐号只能是数字!","警告!",JOptionPane.WARNING_MESSAGE);
userName.setText(null);
qingchu();
}
}
catch(SQLException eve){
System.out.println(eve);
}
}
}).start();
}
});
close=new JButton("退出");
close.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
userName=new JTextField(10);
pwd=new JPasswordField(10);
l1=new JLabel("用户账号:");
l2=new JLabel("用户密码:");
l3=new JLabel("欢迎光临XX银行!");
l1.setBounds(200,180,200,30);
l2.setBounds(200,240,60,30);
l3.setBounds(300,100,154,30);
userName.setBounds(270,180,170,30);
pwd.setBounds(270,240,170,30);
ok.setBounds(370,300,83,31);
close.setBounds(250,300,83,31);
this.add(l3);
this.add(l1);
this.add(userName);
this.add(pwd);
this.add(l2);
this.add(ok);
this.add(close);
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(this);
} catch(Exception exe){
exe.printStackTrace();
}
jf=new JFrame("");
jf.getContentPane().add(this,null);
jf.setSize(700,500);
jf.setUndecorated(true);
jf.setLocationRelativeTo(null);
jf.setResizable(false);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void initOther(){
bg=Toolkit.getDefaultToolkit().createImage(this.getClass().getResource("login/bj2.jpg"));
login=Toolkit.getDefaultToolkit().createImage(this.getClass().getResource("login/login.gif"));
MediaTracker mt=new MediaTracker(this);
mt.addImage(bg,0);//添加图片bg并注标识符0;
mt.addImage(login,1);
try{
mt.waitForAll();
} catch(Exception exe){
exe.printStackTrace();
}
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
g.drawImage(bg,0,0,this);
if(isLogin==true){
g.drawImage(login,250,350,this);
}
}
private void qingchu(){
isLogin=false;
repaint();
pwd.setText(null);
}
public static void main(String[] args){
new Login1();
}
}
class jilu{
static String gettime;
String username=Login1.sqlusername;
public jilu ()
{
Date nowTime=new Date();
SimpleDateFormat m=new SimpleDateFormat("yyyy-M-d H:m:s");
gettime=String.valueOf(m.format(nowTime));
Connection con;
Statement stmt;
ResultSet rs;
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String dbURL = "jdbc:sqlserver://202.115.80.180:2433;DatabaseName=JY06;user=jy06;password=jy06;";
String sql ="INSERT INTO AceessNoteTable (SaveCash,GetCash,TranCash,ChangePwd,ActionDate,CustomalID,CashCheck,TansferCash) VALUES (0,0,0,0,'"+gettime+"','"+username+"',0,0)";
try{
try
{
Class.forName(driverName);
}catch(ClassNotFoundException ex){
System.out.println("this is error!");
}
con = DriverManager.getConnection(dbURL);
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.out.println("this is SQL error!");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -