Bank系统简单界面设计

import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
class Bank
{

public static ResultSet sqlconnection()
{
String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
"databaseName=student;user=sa;password=sa";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
String SQL = "SELECT * FROM dbo.stuinfo";
stmt = con.createStatement();
rs = stmt.executeQuery(SQL);

return rs;
}
catch (Exception e) {
e.printStackTrace();
return rs;
}

}
}
class BankMainUI implements MouseListener
{
JFrame f;
JPanel p;
JMenuBar bar;
JMenu m1,m2,m3,m4,m5,m6,m7;
BankMainUI(String title)
{
f=new JFrame(title);
p=new JPanel();
bar=new JMenuBar();
m1=new JMenu("添加账户");
m2=new JMenu("删除账户");
m3=new JMenu("修改账户信息");
m4=new JMenu("查询账户信息");
m5=new JMenu("浏览");
m6=new JMenu("存款");
m7=new JMenu("退出");
m1.addMouseListener(this);
m2.addMouseListener(this);
m3.addMouseListener(this);
m4.addMouseListener(this);
m5.addMouseListener(this);
m6.addMouseListener(this);
m7.addMouseListener(this);
f.setSize(500,500);
bar.add(m1);
bar.add(m2);
bar.add(m3);
bar.add(m4);
bar.add(m5);
bar.add(m6);
bar.add(m7);
f.setJMenuBar(bar);
f.add(p);
f.setVisible(true);
f.addWindowListener(new MainFrame());
}
public void mouseClicked(MouseEvent e)
{
if(e.getSource()==m1)
{
new AddAccount("添加账户");

}
else if(e.getSource()==m2)
{ new DelAccount("删除账户");}
else if(e.getSource()==m3)
{ new UpdateAccount("修改账户");}
else if(e.getSource()==m4)
{ new SelectInfo("查询账户信息");}
else if(e.getSource()==m5)
{new BrowseInfo("浏览");}
else if(e.getSource()==m6)
{new SaveMoney("存款");}
else if(e.getSource()==m7)
{ System.exit(0);}

}
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{}
public void mouseEntered(MouseEvent e)
{}
public void mouseExited(MouseEvent e)
{}
}


class MyWindowListener implements WindowListener
{
public void windowClosing (WindowEvent e)
{
System.out.println("我退出了!");
e.getWindow().setVisible(false);
((Window)e.getComponent()).dispose();
System.exit(0);
}
public void windowActivated(WindowEvent e){ }
public void windowClosed(WindowEvent e){ }
public void windowDeactivated(WindowEvent e){ }
public void windowDeiconified(WindowEvent e){ }
public void windowIconified(WindowEvent e){ }
public void windowOpened(WindowEvent e){ }
}

class AddAccount
{
JFrame f;
JPanel p;
JButton b1,b2;
JTextField t1,t2,t3;
AddAccount(String title)
{
f=new JFrame(title);
p=new JPanel();
JLabel l1=new JLabel("账号:");
JLabel l2=new JLabel("姓名:");
JLabel l3=new JLabel("金额:");
b1=new JButton("添加");
b2=new JButton("取消");
t1=new JTextField();
t2=new JTextField();
t3=new JTextField();
f.setSize(400,300);
p.setLayout(null);
l1.setBounds(50,50,60,40);
l2.setBounds(50,100,60,40);
l3.setBounds(50,150,60,40);
t1.setBounds(120,50,200,30);
t2.setBounds(120,100,200,30);
t3.setBounds(120,150,200,30);
b1.setBounds(120,200,80,40);
b2.setBounds(220,200,80,40);
p.add(l1);
p.add(l2);
p.add(l3);
p.add(b1);
p.add(b2);
p.add(t1);
p.add(t2);
p.add(t3);
f.add(p);

f.setVisible(true);
f.addWindowListener(new MainFrame());
}
}

 


class DelAccount
{
JFrame f;
JTable table;
JTextField text;
JLabel l;
JPanel p1,p2;
JButton but;
DelAccount(String title)
{

String[] columnNames = {"Product","Number of Boxes","Price"};
Object[][] data =
{
{"Apples", new Integer(5),"5.00"},
{"Oranges", new Integer(3),"6.00"},
{"Pears", new Integer(2),"4.00"},
{"Grapes", new Integer(3),"2.00"},
};
f=new JFrame(title);
text=new JTextField();
p1=new JPanel();
p2=new JPanel();
l=new JLabel("输入账号:");
but=new JButton("确定");
table = new JTable(data, columnNames);
f.setSize(500,500);
f.setLayout(new GridLayout(2,1));
p1.setLayout(null);

l.setBounds(50,10,80,30);
text.setBounds(135,10,150,30);
but.setBounds(290,10,80,30);

p2.add(table);
p1.add(text);
p1.add(l);
p1.add(but);

f.add(p1);
f.add(p2);
f.setVisible(true);
f.addWindowListener(new MainFrame());

}
}

class UpdateAccount
{
JFrame f;
JPanel p;
JButton b1,b2;
JTextField t1,t2,t3;
UpdateAccount(String title)
{
f=new JFrame(title);
p=new JPanel();
JLabel l1=new JLabel("账号:");
JLabel l2=new JLabel("姓名:");
JLabel l3=new JLabel("金额:");
JLabel l4=new JLabel("修改日期");
b1=new JButton("修改");
b2=new JButton("取消");
t1=new JTextField();
t2=new JTextField();
t3=new JTextField();
f.setSize(400,300);
p.setLayout(null);
l1.setBounds(50,50,60,40);
l2.setBounds(50,100,60,40);
l3.setBounds(50,150,60,40);
l4.setBounds(50,200,60,40);
t1.setBounds(120,50,200,30);
t2.setBounds(120,100,200,30);
t3.setBounds(120,150,200,30);
b1.setBounds(120,250,80,40);
b2.setBounds(220,250,80,40);
p.add(l1);
p.add(l2);
p.add(l3);
p.add(l4);
p.add(b1);
p.add(b2);
p.add(t1);
p.add(t2);
p.add(t3);
f.add(p);

f.setVisible(true);
f.addWindowListener(new MainFrame());
}
}
class SaveMoney
{
JFrame f;
JPanel p;
JButton b1,b2;
JTextField t1,t2,t3;
SaveMoney(String title)
{
f=new JFrame(title);
p=new JPanel();
JLabel l1=new JLabel("账号:");
JLabel l2=new JLabel("金额:");
JLabel l3=new JLabel("存款日期");
b1=new JButton("存款");
b2=new JButton("取消");
t1=new JTextField();
t2=new JTextField();
t3=new JTextField();
f.setSize(400,300);
p.setLayout(null);
l1.setBounds(50,50,60,40);
l2.setBounds(50,100,60,40);
l3.setBounds(50,150,60,40);
t1.setBounds(120,50,200,30);
t2.setBounds(120,100,200,30);
t3.setBounds(120,150,200,30);
b1.setBounds(120,200,80,40);
b2.setBounds(220,200,80,40);
p.add(l1);
p.add(l2);
p.add(l3);
p.add(b1);
p.add(b2);
p.add(t1);
p.add(t2);
p.add(t3);
f.add(p);

f.setVisible(true);
f.addWindowListener(new MainFrame());
}
}
class SelectInfo
{
JFrame f;
JTable table;
JTextField text;
JLabel l;
JPanel p1,p2;
JButton but;
SelectInfo(String title)
{

String[] columnNames = {"Product","Number of Boxes","Price"};
Object[][] data =
{
{"Apples", new Integer(5),"5.00"},
{"Oranges", new Integer(3),"6.00"},
{"Pears", new Integer(2),"4.00"},
{"Grapes", new Integer(3),"2.00"},
};
f=new JFrame(title);
text=new JTextField();
p1=new JPanel();
p2=new JPanel();
l=new JLabel("输入账号:");
but=new JButton("查询");
table = new JTable(data, columnNames);
f.setSize(500,500);
f.setLayout(new GridLayout(2,1));
p1.setLayout(null);

l.setBounds(50,10,80,30);
text.setBounds(135,10,150,30);
but.setBounds(290,10,80,30);

p2.add(table);
p1.add(text);
p1.add(l);
p1.add(but);

f.add(p1);
f.add(p2);
f.setVisible(true);
f.addWindowListener(new MainFrame());

}
}
class BrowseInfo
{
JFrame f;
JTable table;
JPanel p;
BrowseInfo(String title)
{

String[] columnNames = {"Product","Number of Boxes","Price"};
Object[][] data =
{
{"Apples", new Integer(5),"5.00"},
{"Oranges", new Integer(3),"6.00"},
{"Pears", new Integer(2),"4.00"},
{"Grapes", new Integer(3),"2.00"},
};
f=new JFrame(title);
p=new JPanel();
table = new JTable(data, columnNames);
f.setSize(500,500);
p.add(table);
f.add(p);
f.setVisible(true);
f.addWindowListener(new MainFrame());

}
}

public class MainFrame extends WindowAdapter
{
public static void main(String[] args)
{
BankMainUI b=new BankMainUI("银行系统");

}
}

运行效果:

posted on 2017-05-21 18:11  Iitb  阅读(189)  评论(0)    收藏  举报

导航