📄 money_search.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.sql.*;
public class money_search extends JFrame{
String sql;
JButton jb,jb2,jb3,jb4;
TextArea text;
money_search(){
super("帐单查询");
Container cp=getContentPane();
text=new TextArea();
text.setEditable(false);
text.setBackground(Color.white);
jb=new JButton("退出");
jb2=new JButton("详细查询");
jb3=new JButton("清空");
jb4=new JButton("总数查询");
JPanel jp2=new JPanel();
jp2.setBorder( new TitledBorder("查询结果"));
jp2.setLayout(new FlowLayout());
jp2.add(text);
jp2.add(jb3);
jp2.add(jb4);
jp2.add(jb2);
jp2.add(jb);
cp.add(jp2,BorderLayout.CENTER);
setSize(500,400);
setVisible(true);
action();
}
public void exit(){
this.dispose();
}
private void action(){
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
exit();
}
});
jb2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:kehudata","","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from all_money");
text.setText("");
while(rs.next()){
text.append("\t"+"\t"+"ID:"+rs.getString("id")+"\n");
text.append("\t"+"\t"+"房间号码:"+rs.getString("room_num")+"\n");
text.append("\t"+"\t"+"已付的钱:"+rs.getString("all_money")+"\n");
text.append("\t"+"\t"+"退房时间:"+rs.getString("this_time")+"\n");
text.append("\n");
}
// if(rs.next()) JOptionPane.showMessageDialog(null,"此房间空着");
rs.close();
stmt.close();
con.close();
}catch(Exception q){q.printStackTrace();
}
}
});
jb3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
text.setText("");
}
});
jb4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Integer money_all=0;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:kehudata","","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from all_money");
while(rs.next()){
money_all+=Integer.parseInt((rs.getString("all_money")));
}
text.setText("\t"+"\t"+"帐上已退房的所有资金:"+money_all.toString());
rs.close();
stmt.close();
con.close();
}catch(Exception q){q.printStackTrace();
}
}
});
}
/*
public static void main(String[] args){
new money_search();
}*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -