⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 actionwayjpanel.java

📁 培训时做的学生管理系统.基于J2SE平台开发
💻 JAVA
字号:
package cn.com.studentsystem.debt;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;

import cn.com.util.DBConnection;

public class ActionWayJPanel extends JPanel {
	JComboBox io_box;
    JLabel io_label;
    JButton select_button;
	JButton refresh_button ;
    JButton cancel_button;
    Vector vector = new Vector();
	public ActionWayJPanel(){
		init();
	}
	
	public void init(){
		io_box = new JComboBox();
		io_box.addItem("收入款");
		io_box.addItem("支出款");
		io_label = new JLabel("  请选择收支方式       ");
		select_button = new JButton("查询");
		refresh_button = new JButton("刷新");
		cancel_button = new JButton("取消");
		
		this.add(io_label);
		this.add(io_box);
		this.add(select_button);
		this.add(refresh_button);
		this.add(cancel_button);
		
		FlowLayout flow = new FlowLayout(FlowLayout.CENTER,20,20);
		this.setLayout(flow);
		
		class ActionWayAction implements ActionListener{

			public void actionPerformed(ActionEvent arg0) {
				
				if(arg0.getActionCommand().equals("查询")){
					DefaultTableModel model = (DefaultTableModel)Debt.jtable.getModel();
	    			int now_row = model.getRowCount();
	    			for(int i=now_row-1;i>=0;i--){
						model.removeRow(i);	
	    			}
	                
				    Connection con = DBConnection.getConnectionOracle();
							
					try {
							
						PreparedStatement ps = con.prepareStatement("select itemnumber,datetime,moneytype,actionway,iomoney,ioperson,ioreason from debt where actionway = ? order by itemnumber");
						ps.setString(1, io_box.getSelectedItem().toString());
						ResultSet rs = ps.executeQuery();
							    
					    while(rs.next()){
											    		 
					    	int no = rs.getInt(1);
							String date = rs.getString(2);
						    String moneytype = rs.getString(3);
						    String ioway = rs.getString(4);
						    String iomoney = rs.getString(5);
						    String ioperson = rs.getString(6);
						    String ioreason = rs.getString(7);
					   
						    DebtVo vo = new DebtVo(no,date,moneytype,ioway,iomoney,ioperson,ioreason);
						    vector.add(vo);
							 }
					
						Iterator ite = vector.iterator();
							    
						while(ite.hasNext()){
						DebtVo nv = (DebtVo)ite.next();
						Object[] obj = {nv.getItemnumber(),nv.getDatetime(),nv.getMoneytype(),nv.getActionway(),
								nv.getIomoney(),nv.getIoperson(),nv.getIoreason()};
						Debt.table_model.addRow(obj);
							    	 
							 }
						SelectDebt.jf.dispose();
							     
					
				    } catch (SQLException e) {
					    e.printStackTrace();
				    }
					
				}else if(arg0.getActionCommand().equals("刷新")){
					DefaultTableModel model = (DefaultTableModel)Debt.jtable.getModel();
	    			int now_row = model.getRowCount();
	    			for(int i=now_row-1;i>=0;i--){
						model.removeRow(i);	
	    			}
	                
				    Connection con = DBConnection.getConnectionOracle();
							
					try {
							
						PreparedStatement ps = con.prepareStatement("select itemnumber,datetime,moneytype,actionway,iomoney,ioperson,ioreason from debt order by itemnumber");
						ResultSet rs = ps.executeQuery();
							    
					    while(rs.next()){
											    		 
					    	int no = rs.getInt(1);
							String date = rs.getString(2);
						    String moneytype = rs.getString(3);
						    String ioway = rs.getString(4);
						    String iomoney = rs.getString(5);
						    String ioperson = rs.getString(6);
						    String ioreason = rs.getString(7);
					   
						    DebtVo vo = new DebtVo(no,date,moneytype,ioway,iomoney,ioperson,ioreason);
						    vector.add(vo);
							 }
					
						Iterator ite = vector.iterator();
							    
						while(ite.hasNext()){
						DebtVo nv = (DebtVo)ite.next();
						Object[] obj = {nv.getItemnumber(),nv.getDatetime(),nv.getMoneytype(),nv.getActionway(),
								nv.getIomoney(),nv.getIoperson(),nv.getIoreason()};
						Debt.table_model.addRow(obj);
							    	 
							 }
						SelectDebt.jf.dispose();
							     
					
				    } catch (SQLException e) {
					    e.printStackTrace();
				    }
				}else if(arg0.getActionCommand().equals("取消")){
					SelectDebt.jf.dispose();
				}
				
			}
			
		}
		
		ActionWayAction actionway_action = new ActionWayAction();
		select_button.addActionListener(actionway_action);
		refresh_button.addActionListener(actionway_action);
		cancel_button.addActionListener(actionway_action);
		
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -