package PFMS;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
public class incomeinquireset extends JFrame{
incomeinquireset(){
this.setLayout(null);
setTitle("个人财务管理——修改收入");
Object[][] a = new Object[20][5] ;
Object name[] = {"编号","日期","金额","原因","备注"};
setLocation(650, 400);
JLabel jno=new JLabel("请输入编号:");
JLabel jdata=new JLabel("请输入日期:");
JLabel jcount=new JLabel("请输入金额:");
//JLabel jtest=new JLabel("备注:");
JButton jbdel=new JButton("删除");
JButton jbdata=new JButton("查询日期");
JButton jbcount=new JButton("查询金额");
JTextField jtno=new JTextField();
JTextField jtdata=new JTextField();
JTextField jtcount=new JTextField();
add(jdata);
add(jno);
add(jcount);
add(jbcount);
add(jtdata);
add(jtcount);
add(jbdel);
add(jbdata);
add(jtno);
jno.setBounds(new Rectangle(80, 10, 80, 30));
jdata.setBounds(new Rectangle(80, 50,80, 30));
jcount.setBounds(new Rectangle(80, 90, 80, 30));
jtno.setBounds(new Rectangle(170, 10, 80, 30));
jtdata.setBounds(new Rectangle(170, 50,80, 30));
jtcount.setBounds(new Rectangle(170, 90, 80, 30));
jbdel.setBounds(new Rectangle(300, 10, 100, 30));
jbdata.setBounds(new Rectangle(300,50,100,30));
jbcount.setBounds(new Rectangle(300,90,100,30));
JTable jtable1 = new JTable();
JScrollPane jscrollpane1 = new JScrollPane();
this.setSize(600, 400);
this.setVisible(true);
try
{
Class.forName(global.driverName);
Connection dbConn = DriverManager.getConnection(global.dbURL, global.userName, global.userPwd);
Statement ps = dbConn.createStatement();
ResultSet rs=ps.executeQuery("select * from 收入");
int k=0;
while(rs.next()){
a[k][0]=rs.getString(1);
a[k][1]=rs.getString(2);
a[k][2]=rs.getString(3);
a[k][3]=rs.getString(4);
a[k][4]=rs.getString(5);
k++;
}
jtable1 = new JTable(a, name);
add((jtable1));
jscrollpane1=new JScrollPane(jtable1);
add(jscrollpane1);
jscrollpane1.setBounds(new Rectangle(50,140,500,169));
}catch(Exception e1){
JOptionPane.showInputDialog(this, "查询失败");
}
jbdel.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
String no=jtno.getText().trim();
try
{
Class.forName(global.driverName);
Connection dbConn = DriverManager.getConnection(global.dbURL, global.userName, global.userPwd);
Statement ps = dbConn.createStatement();
int k;
k=ps.executeUpdate("DELETE FROM 收入 WHERE 编号='"+no+"'");
if(k==1) {
JOptionPane.showMessageDialog(null, "删除成功");
}else {
JOptionPane.showMessageDialog(null, "删除失败");
}
}catch(Exception e1){
JOptionPane.showMessageDialog(null, "请检查输入内容是否正确!");
}
try
{
Class.forName(global.driverName);
Connection dbConn = DriverManager.getConnection(global.dbURL, global.userName, global.userPwd);
Statement ps = dbConn.createStatement();
ResultSet rs=ps.executeQuery("select * from 收入");
int k=0;
Object[][] b = new Object[20][5] ;
while(rs.next()){
b[k][0]=rs.getString(1);
b[k][1]=rs.getString(2);
b[k][2]=rs.getString(3);
b[k][3]=rs.getString(4);
b[k][4]=rs.getString(5);
k++;
}
//JTable jtable1 = new JTable();
//jtable1 = new JTable(b, name);
//add(jtable1);
//JScrollPane jscrollpane1=new JScrollPane(jtable1);
//jscrollpane1.getViewport().add(jtable1);
//add(jscrollpane1);
//jscrollpane1.setViewportView(jtable1);
//jscrollpane1.validate();
//jscrollpane1.setBounds(new Rectangle(40,140,500,169));
}catch(Exception e1){
JOptionPane.showInputDialog(this, "查询失败");
}
}});}
public static void main(String[] args) {
incomeinquireset f = new incomeinquireset();
}
}
页面一加载就会画出表格,然后当删除按钮被按下的时候,表格会刷新。
这个按下按钮刷新表格的功能有没有大佬会啊,求助,谢谢大佬