?? querybyoperator.java
字號(hào):
package com.csbook.restaurant;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author pengtao * @version 1.0 */public class QueryByOperator extends JInternalFrame { JPanel jPanel1 = new JPanel(); JPanel jPanel2 = new JPanel(); JPanel jPanel3 = new JPanel(); JLabel jLabel1 = new JLabel(); JComboBox operator = new JComboBox(); GridLayout gridLayout1 = new GridLayout(1,4); JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); JPanel jPanel4 = new JPanel(); JPanel jPanel5 = new JPanel(); BorderLayout borderLayout1 = new BorderLayout(); JCheckBox byTime = new JCheckBox(); GridLayout gridLayout2 = new GridLayout(); JLabel jLabel8 = new JLabel(); JTextField endYear = new JTextField(); JTextField startDay = new JTextField(); JLabel jLabel4 = new JLabel(); JTextField startYear = new JTextField(); JTextField endMonth = new JTextField(); JTextField startMonth = new JTextField(); JLabel jLabel6 = new JLabel(); JLabel jLabel11 = new JLabel(); JLabel jLabel7 = new JLabel(); JLabel jLabel9 = new JLabel(); JLabel jLabel10 = new JLabel(); JTextField endDay = new JTextField(); JLabel jLabel5 = new JLabel(); GridLayout gridLayout3 = new GridLayout(2,7); JButton cancel = new JButton(); JButton ok = new JButton(); JDesktopPane desktop; public QueryByOperator(String title,boolean resizable,boolean closable,boolean maximizable,boolean iconifiable,JDesktopPane desktop) { super(title,resizable,closable,maximizable,iconifiable); this.desktop=desktop; try { jbInit(); pack(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { jLabel1.setText("業(yè)務(wù)員:"); jPanel1.setLayout(gridLayout1); jLabel2.setText(""); jLabel3.setText(""); jPanel2.setLayout(borderLayout1); byTime.setText("按時(shí)間查詢"); byTime.addActionListener(new QueryByOperator_byTime_actionAdapter(this)); jPanel5.setLayout(gridLayout2); jLabel8.setText("結(jié)束時(shí)間:"); endYear.setEditable(false); endYear.setText(""); startDay.setEditable(false); startDay.setText(""); jLabel4.setText("起始時(shí)間:"); startYear.setEditable(false); startYear.setText(""); endMonth.setEditable(false); endMonth.setText(""); startMonth.setEditable(false); startMonth.setText(""); jLabel6.setText("月"); jLabel11.setHorizontalTextPosition(SwingConstants.CENTER); jLabel11.setText("年"); jLabel7.setText("年"); jLabel9.setText("日"); jLabel10.setText("月"); endDay.setEditable(false); endDay.setText(""); endDay.setEditable(false); endDay.setText(""); jLabel5.setText("日"); jPanel4.setLayout(gridLayout3); cancel.setText("取消"); cancel.addActionListener(new QueryByOperator_cancel_actionAdapter(this)); ok.setText("確定"); ok.addActionListener(new QueryByOperator_ok_actionAdapter(this)); this.getContentPane().add(jPanel1, BorderLayout.NORTH); jPanel1.add(jLabel2, null); jPanel1.add(jLabel1, null); jPanel1.add(operator, null); jPanel1.add(jLabel3, null); this.getContentPane().add(jPanel2, BorderLayout.CENTER); this.getContentPane().add(jPanel3, BorderLayout.SOUTH); jPanel3.add(ok, null); jPanel3.add(cancel, null); jPanel2.add(jPanel5, BorderLayout.NORTH); jPanel5.add(byTime, null); jPanel2.add(jPanel4, BorderLayout.CENTER); jPanel4.add(jLabel4, null); jPanel4.add(startYear, null); jPanel4.add(jLabel11, null); jPanel4.add(startMonth, null); jPanel4.add(jLabel6, null); jPanel4.add(startDay, null); jPanel4.add(jLabel9, null); jPanel4.add(jLabel8, null); jPanel4.add(endYear, null); jPanel4.add(jLabel7, null); jPanel4.add(endMonth, null); jPanel4.add(jLabel10, null); jPanel4.add(endDay, null); jPanel4.add(jLabel5, null); this.prepareShow(); } void byTime_actionPerformed(ActionEvent e) { if(byTime.isSelected()){ this.startYear.setEditable(true); this.startMonth.setEditable(true); this.startDay.setEditable(true); this.endYear.setEditable(true); this.endMonth.setEditable(true); this.endDay.setEditable(true); } else{ this.startYear.setEditable(false); this.startMonth.setEditable(false); this.startDay.setEditable(false); this.endYear.setEditable(false); this.endMonth.setEditable(false); this.endDay.setEditable(false); } } void ok_actionPerformed(ActionEvent e) { String startDate; String endDate; if(byTime.isSelected()){ int startY = Integer.parseInt(startYear.getText()); int startM = Integer.parseInt(startMonth.getText()); int startD = Integer.parseInt(startDay.getText()); int endY = Integer.parseInt(endYear.getText()); int endM = Integer.parseInt(endMonth.getText()); int endD = Integer.parseInt(endDay.getText()); startDate = startY + "-" + startM + "-" + startD; endDate = endY + "-" + endM + "-" + endD; } else{ startDate = "1980-12-12"; endDate = "2100-12-12"; } QueryByOperatorResult dlg = new QueryByOperatorResult("查詢結(jié)果",operator.getSelectedItem().toString(),startDate,endDate); dlg.setVisible(true); desktop.add(dlg); try { dlg.setSelected(true); } catch (java.beans.PropertyVetoException ex) {} } private void prepareShow(){ Connection conn=null; PreparedStatement ps=null; ResultSet rs=null; try{ conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Restaurant;user=user;password=user"); ps=conn.prepareStatement("select id from operator"); rs=ps.executeQuery(); while(rs.next()){ operator.addItem(rs.getString("id")); } } catch(SQLException e){ e.printStackTrace(); } finally{ if(rs!=null)try{rs.close();}catch(SQLException ignore){} if(ps!=null)try{ps.close();}catch(SQLException ignore){} if(conn!=null)try{conn.close();}catch(SQLException ignore){} } } void cancel_actionPerformed(ActionEvent e) { this.dispose(); }}class QueryByOperator_byTime_actionAdapter implements java.awt.event.ActionListener { QueryByOperator adaptee; QueryByOperator_byTime_actionAdapter(QueryByOperator adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.byTime_actionPerformed(e); }}class QueryByOperator_ok_actionAdapter implements java.awt.event.ActionListener { QueryByOperator adaptee; QueryByOperator_ok_actionAdapter(QueryByOperator adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.ok_actionPerformed(e); }}class QueryByOperator_cancel_actionAdapter implements java.awt.event.ActionListener { QueryByOperator adaptee; QueryByOperator_cancel_actionAdapter(QueryByOperator adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.cancel_actionPerformed(e); }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -