import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.net.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
public class CreditCardManagement extends JWindow implements Runnable{
Thread spalshThread=null;
static JFrame frame=new JFrame("简易银行卡管理系统");
static JTextField field1=new JTextField(15);
static JPasswordField field2=new JPasswordField(15);
public CreditCardManagement()
{
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
JPanel splash=new JPanel(new BorderLayout());
URL url=getClass().getResource("/images/flowers.jpg");
if(url!=null){
splash.add(new JLabel(new ImageIcon(url)),BorderLayout.CENTER);
}
setContentPane(splash);
Dimension screen=getToolkit().getScreenSize();
pack();
setLocation((screen.width-getSize().width)/2,
(screen.height-getSize().height)/2);
}
public void start()
{
this.toFront();
spalshThread=new Thread(this);
spalshThread.start();
}
public void run()
{
try{
show();
Thread.sleep(3000);
frame.setVisible(true);
}
catch(Exception ex){ex.printStackTrace();}
this.dispose();
}
static void showFrame()
{
frame.setSize(320,220);frame.setResizable(false);
JLabel label1=new JLabel(" 用户登录/LOGIN");
label1.setFont(new Font("default",1,20));
JLabel label2=new JLabel(" ———————————");
label2.setFont(new Font("default",1,20));
JLabel label3=new JLabel(" 用户名:");
label3.setFont(new Font("default",1,16));
JLabel label4=new JLabel(" 密码: ");
label4.setFont(new Font("default",1,16));
JButton button1=new JButton("登录");
JButton button2=new JButton("开户");
JButton button3=new JButton("退出");
JPanel panel1=new JPanel();JPanel panel2=new JPanel();
JPanel panel3=new JPanel();JPanel panel5=new JPanel();
JPanel panel6=new JPanel();ImagePanel panel7=new ImagePanel();
panel1.setOpaque(false);panel2.setOpaque(false);panel3.setOpaque(false);
panel5.setOpaque(false);panel6.setOpaque(false);
panel1.setLayout(new BorderLayout());
panel3.setLayout(new FlowLayout());
panel1.add("Center",label1);panel1.add("South",label2);
panel5.add(label3);panel5.add(field1);
panel6.add(label4);panel6.add(field2);
panel2.add("Center",panel5);panel2.add("South",panel6);
panel3.add(button1);panel3.add(button2);panel3.add(button3);
button1.addMouseListener(new buttonListener());
button2.addMouseListener(new buttonListener());
button3.addMouseListener(new buttonListener());
panel7.setLayout(new BorderLayout());
panel7.add("North",panel1);panel7.add("Center",panel2);panel7.add("South",panel3);
frame.add(panel7);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize=frame.getSize();
if(frameSize.height>screenSize.height){frameSize.height=screenSize.height;}
if(frameSize.width>screenSize.width){frameSize.width=screenSize.width;}
frame.setLocation((screenSize.width-frameSize.width)/2,
(screenSize.height-frameSize.height)/2);
frame.setVisible(false);
}
public static void main(String args[])
{
CreditCardManagement splash=new CreditCardManagement();
showFrame();
splash.start();
}
}
class buttonListener extends MouseAdapter
{
Login log;kaihu kai;database data;解挂_frame frame;
public void mouseClicked(MouseEvent e) {
JButton butObj=(JButton)(e.getSource());
if(butObj.getLabel()=="退出")
{
System.exit(0);
}
if(butObj.getLabel()=="开户")
{
kai =new kaihu();CreditCardManagement.frame.setVisible(false);
}
if(butObj.getLabel()=="登录")
{
boolean bo=false,boo=false;
String url="jdbc:sqlserver://localhost:1433;" +
"databaseName=atm;user=sa;password=148620;";
String query="SELECT Cno,Password,Loss FROM atm";
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
DriverManager.setLogStream(System.out);
Connection con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(query);
ResultSetMetaData rsmd=rs.getMetaData();
boolean more=rs.next();
while(more)
{
if(rs.getString(1).trim().equalsIgnoreCase(CreditCardManagement.field1.getText().trim())
&&(rs.getString(2).trim().equalsIgnoreCase(CreditCardManagement.field2.getText().trim())))
{
if(rs.getString(3).trim().equalsIgnoreCase("1"))
{
boo=true;
}
bo=true;break;
}
more=rs.next();
}
rs.close();
stmt.close();
con.close();
}
catch(SQLException ex){}
catch (ClassNotFoundException ep) {ep.printStackTrace();}
if(bo==true&&boo==false){
log=new Login();CreditCardManagement.frame.setVisible(false);
}
else if(boo==true)
{
int n=JOptionPane.showConfirmDialog(CreditCardManagement.frame, "该账号已被挂失!是否凭有效证件解挂?","确认对话框",JOptionPane.YES_NO_OPTION);
if(n==JOptionPane.YES_OPTION)
{
frame=new 解挂_frame();
}
else if(n==JOptionPane.NO_OPTION)
{
System.exit(0);
}
}
else
{
JOptionPane.showMessageDialog(CreditCardManagement.frame, "账号或密码有误,请查正后登录!","有误",JOptionPane.WARNING_MESSAGE);
CreditCardManagement.field1.setText(null);CreditCardManagement.field2.setText(null);
}
}
}
}
class kaihu extends JFrame implements ActionListener
{
JFrame frame2=new JFrame("开户"); Login log;
JButton button,button1;JTextField field1;
database data;JDialog diaObj;JLabel textLab;
JButton butObj2=new JButton("登录");
static String mess1="",mess2="";
kaihu()
{
frame2.setSize(300,200);frame2.setResizable(false);
diaObj=new JDialog(frame2);diaObj.setSize(300,200);
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize=frame2.getSize();
Dimension diaSize=diaObj.getSize();
if(frameSize.height>screenSize.height){frameSize.height=screenSize.height;}
if(frameSize.width>screenSize.width){frameSize.width=screenSize.width;}
frame2.setLocation((screenSize.width-frameSize.width)/2,
(screenSize.height-frameSize.height)/2);
JLabel label1=new JLabel("身份证/ID:");label1.setFont(new Font("default",1,18));
JLabel label3=new JLabel("请输入4位身份证号码:");label3.setFont(new Font("default",1,18));
field1=new JTextField(13);
button=new JButton("提交");button.setFont(new Font("default",1,18));
button1=new JButton("取消");button1.setFont(new Font("default",1,18));
button.addActionListener(this);button1.addActionListener(this);
JPanel panel1=new JPanel();JPanel panel3=new JPanel();JPanel panel6=new JPanel();
panel1.add(label1);panel1.add(field1);
panel3.add(label3);panel6.add(button);panel6.add(button1);
frame2.setLayout(new BorderLayout());
frame2.add("Center",panel1);frame2.add("North",panel3);frame2.add("South",panel6);
frame2.setVisible(true);
diaObj.setLayout(new FlowLayout(FlowLayout.CENTER,40,20));
textLab=new JLabel("");
diaObj.add(textLab);
diaObj.add(butObj2);
butObj2.addActionListener(this);
if(diaSize.height>screenSize.height){diaSize.height=screenSize.height;}