📄 payforpanel.java~59~
字号:
package bank;
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.*;
import java.awt.Color;
//还贷界面........
public class PayForPanel extends JPanel{
public PayForPanel(String accountID,String branchname,String pswd){
try {
jbInit();
this.accountID=accountID;
this.branchname=branchname;
this.pswd=pswd;
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private String accountID;
private String branchname;
private String pswd;
private void jbInit() throws Exception {
jLabel2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 13));
jLabel2.setText("贷了多少时间:");
jTextField2.setEditable(false);
jLabel3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 13));
jLabel3.setText("总共要还:");
jTextField3.setEditable(false);
jLabel4.setFont(new java.awt.Font("Dialog", Font.PLAIN, 13));
jLabel4.setText("请输入你要还的金额:");
jButton1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
jButton1.setText("确定");
jButton1.addActionListener(new PayForPanel_jButton1_actionAdapter(this));
jButton2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
jButton2.setText("重置");
jButton2.addActionListener(new PayForPanel_jButton2_actionAdapter(this));
jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 13));
jTextField1.setEditable(false);
xYLayout1.setWidth(482);
xYLayout1.setHeight(333);
this.setBackground(new Color(212, 230, 144));
jLabel5.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jLabel5.setText("还剩下:");
jTextField5.setEditable(false);
this.add(jLabel1, new XYConstraints(46, 29, 82, 37));
this.add(jLabel1, new XYConstraints(74, 43, 82, 37));
this.add(jLabel1, new XYConstraints(74, 43, -1, -1));
this.add(jLabel1, new XYConstraints(74, 43, -1, -1));
jLabel1.setText("贷了的金额:");
this.setLayout(xYLayout1);
this.setFont(new java.awt.Font("Dialog", Font.PLAIN, 13));
this.add(jLabel1, new XYConstraints(183, 5, -1, -1));
this.add(jLabel2, new XYConstraints(39, 84, 102, 36));
this.add(jLabel3, new XYConstraints(40, 142, 91, 31));
this.add(jTextField4, new XYConstraints(174, 185, 184, 34));
this.add(jLabel1, new XYConstraints(40, 35, 82, 37));
this.add(jLabel4, new XYConstraints(39, 187, -1, 32));
this.add(jTextField2, new XYConstraints(173, 87, 185, 34));
this.add(jTextField3, new XYConstraints(174, 139, 184, 35));
this.add(jTextField1, new XYConstraints(174, 33, 184, 35));
this.add(jTextField5, new XYConstraints(173, 230, 188, 37));
this.add(jLabel5, new XYConstraints(45, 232, 109, 36));
this.add(jButton2, new XYConstraints(385, 246, 69, 33));
this.add(jButton1, new XYConstraints(383, 195, 68, 33));
try{
con=bankconnect.getconn();
stmt=con.createStatement();
int i=0;
String sql="select amount from loan where loan_number="+accountID;
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
String a="";
a=rs.getString("amount");
amount =Double.parseDouble(a);
jTextField1.setText(Double.toString(amount)+"RMB");
stmt.close();
con.close();
i=1;
}
if(i==0)jTextField1.setText("0 RMB");
}
catch(SQLException ex){
ex.printStackTrace();
}
}
JLabel jLabel1 = new JLabel();
XYLayout xYLayout1 = new XYLayout();
JTextField jTextField1 = new JTextField();
JLabel jLabel2 = new JLabel();
JTextField jTextField2 = new JTextField();
JLabel jLabel3 = new JLabel();
JTextField jTextField3 = new JTextField();
JLabel jLabel4 = new JLabel();
JTextField jTextField4 = new JTextField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
static double getm;
static double amount;
static double year;
static String loantime;
private Statement stmt;
private Connection con;
JLabel jLabel5 = new JLabel();
JTextField jTextField5 = new JTextField();
public static String gettime(String b)//截断时间的静态方法
{
char [] a={'0','0','0','0'};
for(int i=0;i<b.length();i++)
if(b.charAt(i)!='-') a[i]=b.charAt(i);
else break;
String cc=new String(a);
return cc;
}
public void jButton1_actionPerformed(ActionEvent e) {
if(!jTextField4.getText().trim().equals("")){
getm=Double.parseDouble(jTextField4.getText().trim());
try{
con=bankconnect.getconn();
stmt=con.createStatement();
String today=TodayTime.getDate();
String sql="select * from loan where loan_number="+accountID;
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
String a="";
a=rs.getString("amount");
amount=Double.parseDouble(a);
loantime=rs.getString("loan_time");
jTextField1.setText(a);
year=Float.parseFloat(gettime(today))-Float.parseFloat(gettime(loantime));
a=Double.toString(year);
jTextField2.setText(a+"Year");
jTextField3.setText(Double.toString(amount));
sql="select loan_lev from loan where loan_number="+accountID;
rs=stmt.executeQuery(sql);
double lev=0;
String b="";
while(rs.next()){
b=rs.getString("loan_lev");
}
lev=Double.parseDouble(b);
double lef=amount*Math.pow((1+lev),year)-getm;
double total=amount*Math.pow((1+lev),year);
if(lef>0) jTextField5.setText(lef+"RMB");
sql = "update loan set amount=" + lef + "where loan_number=" +
accountID;
stmt.executeUpdate(sql);
if(lef>=0) jTextField3.setText(Double.toString(total)+"RMB");
try{
con.setAutoCommit(false); //设置事务
if (lef <= 0) {
sql = "delete from borrower where loan_number=" +
accountID; //删除这个贷款信息
stmt.executeUpdate(sql);
sql = "delete from loan where loan_number=" + accountID;
stmt.executeUpdate(sql);
if(lef<0)
{
jTextField1.setText("0");
jTextField3.setText("");
getm=-lef;
jLabel4.setText("找您的零钱:");
jTextField4.setText(getm+"元");
}
}
con.commit();
con.setAutoCommit(true);
stmt.close();
con.close();
JOptionPane.showMessageDialog(null,"操作成功");
return;
}
catch(Exception exp){
con.rollback();
con.close();
exp.printStackTrace();
}
}
}
catch(SQLException ex){
ex.printStackTrace();
}
}
else JOptionPane.showMessageDialog(null,"请您输入要还的金额!谢谢合作!");
}
public void jButton2_actionPerformed(ActionEvent e) {
jTextField4.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField5.setText("");
jLabel4.setText("请输入你要还的金额:");
try{
con=bankconnect.getconn();
stmt=con.createStatement();
int i=0;
String sql="select amount from loan where loan_number="+accountID;
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
String a="";
a=rs.getString("amount");
amount =Double.parseDouble(a);
jTextField1.setText(a+" RMB");
stmt.close();
con.close();
i=1;
return ;
}
if(i==0) jTextField1.setText("0 RMB");
}
catch(SQLException ex){
ex.printStackTrace();
}
}
public void jButton3_actionPerformed(ActionEvent e) {
try{
con=bankconnect.getconn();
stmt=con.createStatement();
String sql="select amount from loan where loan_number="+accountID;
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
String a="";
a=rs.getString("amount");
amount =Double.parseDouble(a);
jTextField1.setText(a+"RMB");
stmt.close();
con.close();
return ;
}
}
catch(SQLException ex){
ex.printStackTrace();
}
}
}
class PayForPanel_jButton2_actionAdapter
implements ActionListener {
private PayForPanel adaptee;
PayForPanel_jButton2_actionAdapter(PayForPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class PayForPanel_jButton1_actionAdapter
implements ActionListener {
private PayForPanel adaptee;
PayForPanel_jButton1_actionAdapter(PayForPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -