📄 staticpanel.java
字号:
package manpowersystem;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */import java.io.*;import java.util.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import javax.swing.border.*;import javax.swing.table.*;import com.borland.jbcl.layout.*;public class StaticPanel extends JFrame { XYLayout xYLayout1 = new XYLayout(); JButton jDelRecordButton = new JButton(); JButton jExitButton = new JButton(); JScrollPane jStaticScrollPane = new JScrollPane(); JTable jStaticTable = new JTable(); boolean bCanDel = true; int intDelLines; //显示所选的行数 String[] arrField = {"工 号", "姓 名", "上班时间", "下班时间","请假时间","备 注"}; Object[][] arrData = {}; //设定表格的字段 Database database = new Database(); //数据库存取对象 RecordItem item = new RecordItem(); //每一条数据记录 DefaultTableModel tableModel; //表格模型 int intRow; //显示所选的行数 int intCol; //显示所选的行数 int intEmploreeID; //员工工号 String strName; //员工姓名 Date dateTime; //确切记录 String strDescribe; //备注 public StaticPanel() { try { jbInit(); } catch ( Exception e ) { e.printStackTrace(); } } public static void main( String[] args ) { StaticPanel tablePanel1 = new StaticPanel(); tablePanel1.validate(); tablePanel1.setVisible( true ); } private void jbInit() throws Exception { DefaultTableModel tableModel = new DefaultTableModel( arrData, arrField ); jStaticTable = new JTable(tableModel); jExitButton.addActionListener(new ActionListener(this)); jStaticScrollPane.getViewport().add( jStaticTable, null ); this.setTitle("信息统计页面"); this.getContentPane().setBackground( new Color( 210, 138, 177 ) ); this.getContentPane().setLayout( xYLayout1 ); jDelRecordButton.setBackground( new Color( 212, 158, 217 ) ); jDelRecordButton.setFont( new java.awt.Font( "DialogInput", 1, 16 ) ); jDelRecordButton.setText( "删除记录" ); jDelRecordButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed( ActionEvent e ) { jDelRecordButton_actionPerformed( e ); } } ); jExitButton.setBackground( new Color( 212, 158, 217 ) ); jExitButton.setFont( new java.awt.Font( "DialogInput", 1, 16 ) ); jExitButton.setText( "退出" ); jExitButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed( ActionEvent e ) { jExitButton_actionPerformed( e ); } } ); addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { dispose(); } } ); jStaticScrollPane.getViewport().setBackground(new Color(210, 138, 177)); this.getContentPane().add(jStaticScrollPane, new XYConstraints(4, 4, 462, 420)); this.getContentPane().add(jExitButton, new XYConstraints(266, 462, 102, 52)); this.getContentPane().add(jDelRecordButton, new XYConstraints(85, 462, 102, 52)); jStaticScrollPane.getViewport().add(jStaticTable, null); this.getContentPane().add(jStaticScrollPane, new XYConstraints(4, 2, 463, 420)); this.setSize( 470, 550 ); this.setLocation( 230, 100 ); this.setResizable( false ); UpdateRecord(); } void jExitButton_actionPerformed( ActionEvent e ) { this.dispose(); } void jDelRecordButton_actionPerformed( ActionEvent e ) { DelRecord(); } public void DelRecord() { jStaticScrollPane.getViewport().add( jStaticTable, null ); intRow = jStaticTable.getSelectedRow(); if (intRow == -1) return; try { database.DeleteData( tableModel.getValueAt( intRow, 0 ).toString() ); } catch ( Exception e ) { e.printStackTrace(); } UpdateRecord(); //更新表格 } public void UpdateRecord() { Object[][] arrTmp = {}; //设定表格的字段 tableModel = new DefaultTableModel( arrTmp, arrField ); jStaticTable = new JTable( tableModel ); jStaticScrollPane.getViewport().add( jStaticTable, null ); try { RecordItem[] result = new RecordItem[ 100 ]; for ( int j = 0; j < 100; j++ ) result[ j ] = new RecordItem(); result = database.AccessData(); for ( int i = 0; i < result.length; i++ ) { Object newdata[] = {result[ i ].GetEmployeeID(), result[ i ].GetEmployeeName(), result[ i ].GetOnWorkTime(), result[ i ].GetOffWorkTime(), result[ i ].GetLeaveWorkTime(), result[ i ].GetDescribe()}; String strTmp = result[ i ].GetEmployeeID(); if ( strTmp.trim().length() == 0 ) continue; tableModel.addRow( newdata ); } } catch ( Exception e ) { e.printStackTrace(); } }}class ActionListener implements java.awt.event.ActionListener { StaticPanel adaptee; ActionListener(StaticPanel adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jExitButton_actionPerformed(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -