📄 showstore.java
字号:
package control.view.store;import control.view.*;import javax.swing.*;import javax.swing.table.*;import java.util.ArrayList;import java.awt.*;import java.awt.event.*;import control.dao.prodstore.ProdStoreDAOImpl;import beans.ProdStore;public class ShowStore extends MainFrame{ private static JTable thisTable=null; private JButton jb_print=new JButton("打印此表",new ImageIcon("images/print.gif")); private JButton jb_refresh=new JButton("刷新",new ImageIcon("images/refresh.gif")); private JButton jb_exit=new JButton("退出",new ImageIcon("images/exit.gif")); public void actionPerformed(ActionEvent e){ super.actionPerformed(e); if(e.getSource() instanceof JButton){ JButton b=(JButton)e.getSource(); if(b == jb_print){ try{ thisTable.print(); }catch(Exception ee){ ee.printStackTrace(); } }else if (b == jb_refresh){ try{ fresh(); }catch(Throwable te){ } }else if(b == jb_exit){ if( (JOptionPane.showConfirmDialog(this, new String("是否真的退出?")))== JOptionPane.YES_OPTION) { this.dispose(); } } } } public ShowStore(String title){ super(title); setMid(900,600,this); this.setResizable(false); addComponent(); this.show(true); } public void addComponent(){ JPanel fraPane=(JPanel)this.getContentPane(); fraPane.setLayout(new BorderLayout()); fraPane.setBackground(new java.awt.Color(189,230,247)); thisTable=addTable(); JScrollPane sp=new JScrollPane(thisTable); fraPane.add(sp,BorderLayout.NORTH); JPanel jp=new JPanel(); jp.setBackground(new java.awt.Color(189,230,247)); jp.setLayout(null); jp.setPreferredSize(new Dimension(900,100)); jb_print.setBounds(370,10,130,35); jb_refresh.setBounds(520,10,100,35); jb_exit.setBounds(640,10,120,35); jp.add(jb_print); jp.add(jb_refresh); jp.add(jb_exit); jb_refresh.addActionListener(this); jb_print.addActionListener(this); jb_exit.addActionListener(this); fraPane.add(jp,BorderLayout.SOUTH); } public JTable addTable(){ ProdStoreDAOImpl pdi=new ProdStoreDAOImpl(); ArrayList lists=pdi.showAll(); Object[][] data=new Object[lists.size()+1][7]; for(int i=0; i<lists.size();i++){ data[i][0]=i+1; data[i][1]=((ProdStore)lists.get(i)).getPSID(); data[i][2]=((ProdStore)lists.get(i)).getPName(); data[i][3]=((ProdStore)lists.get(i)).getPINum(); data[i][4]=((ProdStore)lists.get(i)).getPONum(); data[i][5]=((ProdStore)lists.get(i)).getPSNum(); data[i][6]=((ProdStore)lists.get(i)).getPDate(); } MyModel myModel=new MyModel(data,lists.size(),7); JTable table=new JTable(myModel); table.getColumnModel().getColumn(0).setHeaderValue(new String("序号")); table.getColumnModel().getColumn(1).setHeaderValue(new String("台帐编号")); table.getColumnModel().getColumn(2).setHeaderValue(new String("产品名称")); table.getColumnModel().getColumn(3).setHeaderValue(new String("当日入库数量")); table.getColumnModel().getColumn(4).setHeaderValue(new String("当日出库数量")); table.getColumnModel().getColumn(5).setHeaderValue(new String("当日剩余库存")); table.getColumnModel().getColumn(6).setHeaderValue(new String("日期")); return table; } class MyModel extends AbstractTableModel{ Object data[][]; int rows,cols; public MyModel(Object[][] d,int rows,int cols){ this.rows=rows; this.cols=cols; this.data=d; } public int getColumnCount(){ return this.cols; } public int getRowCount(){ return this.rows; } public Object getValueAt(int row,int col){ return data[row][col].toString(); } public boolean isCellEditable(int row,int col){ return true; } public void setValueAt(Object value,int row,int col){ data[row][col]=(String)value; this.fireTableCellUpdated(row, col); } } public void fresh(){ this.dispose(); new ShowStore("库存台帐(每日合计)"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -