📄 kjhk.java
字号:
boxv2.add(text2);
boxv2.add(Box.createVerticalStrut(8));
boxv2.add(text3);
boxv2.add(Box.createVerticalStrut(26));
boxv2.add(button2);
boxh1=Box.createHorizontalBox();//行式
boxh1.add(boxv1);
boxh1.add(Box.createHorizontalStrut(12));
boxh1.add(boxv2);
add(boxh1);
button1.addActionListener(this);//监视器
button2.addActionListener(this);
}
public void actionPerformed (ActionEvent e )//实现监视
{
if(e.getSource()==button1)
{
int nv= JOptionPane.showConfirmDialog(this,"确定要修改密码吗?","确认对话框",
JOptionPane.YES_NO_OPTION);//弹出确认对话框
if(nv==JOptionPane.YES_OPTION)//如果点yes.则执行
{ try{ 修改密码();}
catch(SQLException ee) {}
}
else if(nv==JOptionPane.NO_OPTION) //如果点no.则退出清空
text1.setText(null);
} // 数据库在函数中
else if(e.getSource()==button2)
{
text1.setText(null);
}
}
public void 修改密码() throws SQLException //数据库函数
{ String mima,kahao;
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e) {}
Connection con=DriverManager.getConnection("jdbc:odbc:redsun","","");
Statement sq1=con.createStatement();
ResultSet rs=sq1.executeQuery("SELECT * FROM 表1 ");
while(rs.next())
{ mima=rs.getString("密码");
kahao=rs.getString("卡号");
if(kahao.equals(text1.getText().trim())&&mima.equals(text2.getText().trim()))
{ String mima1=text3.getText().trim();
String temp="UPDATE 表1 SET 密码="+mima1+" WHERE 卡号="+kahao;
con=DriverManager.getConnection("jdbc:odbc:redsun","","");
sq1.executeUpdate(temp);
JOptionPane.showMessageDialog(this,"您的新密码"+mima1,"消息对话框",
JOptionPane.WARNING_MESSAGE); a=1;
con.close();
text1.setText(null); break;
}
}
if(a==0)
{JOptionPane.showMessageDialog(this," 卡号或者密码输入错误","消息对话框",
JOptionPane.WARNING_MESSAGE); }
}
}
//***************************************************************8*//
class win extends Frame implements ActionListener //窗口创建
{
MenuBar bar=null; //菜单条对象
Menu menu=null; // 菜单
MenuItem item1,item2,item3,item4,item5,item6; //菜单项对象
MenuShortcut kjj1=new MenuShortcut(KeyEvent.VK_1);//快捷键
MenuShortcut kjj2=new MenuShortcut(KeyEvent.VK_2);
MenuShortcut kjj3=new MenuShortcut(KeyEvent.VK_3);
MenuShortcut kjj4=new MenuShortcut(KeyEvent.VK_4);
MenuShortcut kjj5=new MenuShortcut(KeyEvent.VK_5);
MenuShortcut kjj6=new MenuShortcut(KeyEvent.VK_6);
查询 cx; //创建面板对象
开户 kh;
存款 ck;
取款 qk;
挂失 gs;
修改 xg;
Font f=new Font("宋体",Font.BOLD,12);//字体
win()
{ super("简易银行卡管理系统");
bar= new MenuBar(); menu=new Menu("服务菜单");
setBackground(Color.gray);
setFont(f);
item1=new MenuItem("查询");
item2=new MenuItem("开户");
item3=new MenuItem("存款");
item4=new MenuItem("取款");
item5=new MenuItem("挂失");
item6=new MenuItem("修改");
item1.setShortcut(kjj1);// 快捷键
item2.setShortcut(kjj3);
item3.setShortcut(kjj4);
item4.setShortcut(kjj5);
item5.setShortcut(kjj6);
item6.setShortcut(kjj2);
menu.add(item1);
menu.add(item6);
menu.add(item2);
menu.add(item3);
menu.add(item4);
menu.add(item5);
bar.add(menu);
setMenuBar(bar);
cx=new 查询();
kh=new 开户();
ck=new 存款();
qk=new 取款();
gs=new 挂失();
xg=new 修改();
item1.addActionListener(this);//对菜单项监视
item2.addActionListener(this);
item3.addActionListener(this);
item4.addActionListener(this);
item5.addActionListener(this);
item6.addActionListener(this);
setVisible(true); validate(); setBounds(100,120,300,240);
add(cx);
}
public void actionPerformed (ActionEvent e )//实现监视
{ if(e.getSource()==item1)
{
removeAll();
add(cx,"Center");// 添加查询界面
validate();
}
else if(e.getSource()==item6)
{
removeAll();
add(xg,"Center");// 添加开户界面
validate();
}
else if(e.getSource()==item2)
{
removeAll();
add(kh,"Center");// 添加开户界面
validate();
}
else if(e.getSource()==item3)
{
removeAll();
add(ck,"Center");// 添加存款界面
validate();
}
if(e.getSource()==item4)
{
removeAll();
add(qk,"Center");// 添加取款界面
validate();
}
if(e.getSource()==item5)
{
removeAll();
add(gs,"Center");// 添加挂失界面
validate();
}
}
}
public class xiewenhai
{ public static void main(String args[])
{ win w=new win();
w.setVisible(true);
w.addWindowFocusListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -