📄 zhuanzhang.java~25~
字号:
package MainFrame;
import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.ResultSet;
public class ZhuanZhang extends JFrame {
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField();
JTextField jTextField3 = new JTextField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
public ZhuanZhang() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(xYLayout1);
jLabel1.setFont(new java.awt.Font("华文彩云", Font.BOLD, 25));
jLabel1.setForeground(Color.green);
jLabel1.setText("转帐操作界面");
jButton2.addActionListener(new ZhuanZhang_jButton2_actionAdapter(this));
jLabel2.setForeground(Color.blue);
jLabel3.setForeground(Color.blue);
jLabel4.setForeground(Color.blue);
jButton1.setForeground(Color.red);
jButton2.setForeground(Color.red);
this.getContentPane().add(jLabel1, new XYConstraints(111, 22, 225, 40));
jButton2.setFont(new java.awt.Font("宋体", Font.BOLD, 15));
jButton2.setText("取消");
jButton1.setFont(new java.awt.Font("宋体", Font.BOLD, 15));
jButton1.setText("交易");
jButton1.addActionListener(new ZhuanZhang_jButton1_actionAdapter(this));
xYLayout1.setWidth(400);
xYLayout1.setHeight(326);
jLabel4.setFont(new java.awt.Font("宋体", Font.BOLD, 18));
jLabel4.setText("转出金额");
jLabel3.setFont(new java.awt.Font("宋体", Font.BOLD, 18));
jLabel3.setText("转出帐号ID");
this.getContentPane().add(jLabel2, new XYConstraints(20, 65, 100, 35));
this.getContentPane().add(jLabel3, new XYConstraints(20, 120, 100, 35));
this.getContentPane().add(jLabel4, new XYConstraints(20, 175, 100, 35));
this.getContentPane().add(jTextField1,
new XYConstraints(140, 70, 170, 35));
this.getContentPane().add(jTextField2,
new XYConstraints(140, 124, 170, 35));
this.getContentPane().add(jTextField3,
new XYConstraints(140, 175, 170, 35));
this.getContentPane().add(jButton1, new XYConstraints(61, 269, 86, 38));
this.getContentPane().add(jButton2, new XYConstraints(231, 269, 85, 37));
jLabel2.setFont(new java.awt.Font("宋体", Font.BOLD, 18));
jLabel2.setText("转入帐号ID");
}
public static void main(String[] args) {
ZhuanZhang z = new ZhuanZhang();
z.setBounds(200,200,400,400);
z.setVisible(true);
}
public void jButton1_actionPerformed(ActionEvent e) {
try {String a=jTextField1.getText();
String b=jTextField2.getText();
String c=jTextField3.getText();
if(a.equals("")){
JOptionPane.showMessageDialog(null,"沒有輸入转入ID!","輸入錯誤",JOptionPane.ERROR_MESSAGE);}
else {if(b.equals("")){
JOptionPane.showMessageDialog(null,"沒有輸出转入ID!","輸入錯誤",JOptionPane.ERROR_MESSAGE);}
else { if(c.equals("")){
JOptionPane.showMessageDialog(null,"沒有輸入金额","輸入錯誤",JOptionPane.ERROR_MESSAGE);}
else{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;databaseName=ATM",
"sa", "huang100");
Statement Stat = conn.createStatement();
ResultSet rs1 = Stat.executeQuery("select * from userTable where userpassword='"+ a+"'");
if(rs1.next()){
ResultSet rs2 = Stat.executeQuery("select * from userTable where userpassword='"+ b+"'");
if(rs2.next()){
Stat.executeUpdate("update userTable set usermoney=usermoney-'"+c+"' where userpassword='"+b+"'");
Stat.executeUpdate("update userTable set usermoney=usermoney+'"+c+"' where userpassword='"+a+"'");
JOptionPane.showMessageDialog(null,"操作成功");
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
}}}
}
}
} catch (Exception ex) {
}
}
public void jButton2_actionPerformed(ActionEvent e) {
this.dispose();
ZhuJieMian z = new ZhuJieMian();
z.setBounds(200,200,400,400);
z.setVisible(true);
}
}
class ZhuanZhang_jButton2_actionAdapter implements ActionListener {
private ZhuanZhang adaptee;
ZhuanZhang_jButton2_actionAdapter(ZhuanZhang adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class ZhuanZhang_jButton1_actionAdapter implements ActionListener {
private ZhuanZhang adaptee;
ZhuanZhang_jButton1_actionAdapter(ZhuanZhang adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -