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

📄 bookpanel.java

📁 jsp2.0动态网站开发实例指南原代码
💻 JAVA
字号:
package ui;
import OrderPack.Order;

import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.Date;
import java.sql.Time;
import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.swing.*;

import AccountsPack.User;
/*
 * Created on 2005-4-10
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author zinniazxp
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class BookPanel extends JPanel {

	private JTextField jTextField = null;
	private JLabel jLabel = null;
	private JLabel jLabel1 = null;
	private JTextField jTextField1 = null;
	private JLabel jLabel2 = null;
	private JLabel jLabel3 = null;
	private JPanel jPanel = null;
	private JComboBox jComboBox = null;
	private JComboBox jComboBox1 = null;
	private JComboBox jComboBox2 = null;
	private JComboBox jComboBox3 = null;
	private JLabel jLabel4 = null;
	private JLabel jLabel5 = null;
	private JComboBox jComboBox4 = null;
	private JLabel jLabel6 = null;
	private JComboBox jComboBox5 = null;
	private JComboBox jComboBox6 = null;
	private JComboBox jComboBox7 = null;
	private JPanel jPanel1 = null;
	private JLabel jLabel7 = null;
	private JComboBox jComboBox8 = null;
	private JPanel jPanel2 = null;
	private JLabel jLabel8 = null;
	private JComboBox jComboBox9 = null;
	private JPanel jPanel3 = null;
	private JButton jButton = null;
	private JButton jButton1 = null;
	private JPanel jPanel4 = null;

    private Handler _handler = new Handler();
    private Order _currentOrder;


	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */    
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setText("");
			jTextField.setPreferredSize(new java.awt.Dimension(125,20));
		}
		return jTextField;
	}
	/**
	 * This method initializes jTextField1	
	 * 	
	 * @return javax.swing.JTextField	
	 */    
	private JTextField getJTextField1() {
		if (jTextField1 == null) {
			jTextField1 = new JTextField();
			jTextField1.setText("");
			jTextField1.setPreferredSize(new java.awt.Dimension(140,20));
		}
		return jTextField1;
	}
	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */    
	private JPanel getJPanel() {
		if (jPanel == null) {
			jPanel = new JPanel();
			jPanel.setPreferredSize(new java.awt.Dimension(70,20));
			jPanel.setForeground(java.awt.Color.black);
			jPanel.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,0));
			jPanel.setEnabled(true);
			jPanel.setVisible(true);
		}
		return jPanel;
	}
	/**
	 * This method initializes jComboBox	
	 * 	
	 * @return javax.swing.JComboBox	
	 */    
	private JComboBox getJComboBox() {
		if (jComboBox == null) 
		{
			String[] items = {"Single", "Twin","* Single","* Twin","** Single","** Twin","Suite"};
			jComboBox = new JComboBox(items);
			jComboBox.setPreferredSize(new java.awt.Dimension(80,20));
		}
		return jComboBox;
	}
	/**
	 * This method initializes jComboBox1	
	 * 	
	 * @return javax.swing.JComboBox	
	 */    
	private JComboBox getJComboBox1() {
		if (jComboBox1 == null) 
		{
			String[] items = {"2005", "2006","2007"};
			jComboBox1 = new JComboBox(items);
			jComboBox1.setPreferredSize(new java.awt.Dimension(80,20));
		}
		return jComboBox1;
	}
	/**
	 * This method initializes jComboBox2	
	 * 	
	 * @return javax.swing.JComboBox	
	 */    
	private JComboBox getJComboBox2() {
		if (jComboBox2 == null) 
		{
			String[] items = {"January", "February","March","April","May","June","July","August","September","October","November","December"};
			jComboBox2 = new JComboBox(items);
			jComboBox2.setPreferredSize(new java.awt.Dimension(100,20));
		}
		return jComboBox2;
	}
	/**
	 * This method initializes jComboBox3	
	 * 	
	 * @return javax.swing.JComboBox	
	 */    
	private JComboBox getJComboBox3() {
		if (jComboBox3 == null) 
		{
			String days[] = new String[31];
			for( int i =0;i<31;i++)
				days[i] = new String(String.valueOf(i+1));
			jComboBox3 = new JComboBox(days);
			jComboBox3.setPreferredSize(new java.awt.Dimension(50,20));
		}
		return jComboBox3;
	}
	/**
	 * This method initializes jComboBox4	
	 * 	
	 * @return javax.swing.JComboBox	
	 */    
	private JComboBox getJComboBox4() {
		if (jComboBox4 == null) 
		{
			String items[] = {"Cash","Card","Check"};
			jComboBox4 = new JComboBox(items);
			jComboBox4.setPreferredSize(new java.awt.Dimension(80,20));
		}
		return jComboBox4;
	}
	/**
	 * This method initializes jComboBox5	
	 * 	
	 * @return javax.swing.JComboBox	
	 */    
	private JComboBox getJComboBox5() {
		if (jComboBox5 == null) {
			String[] items = {"2005", "2006","2007"};
			jComboBox5 = new JComboBox(items);
			jComboBox5.setPreferredSize(new java.awt.Dimension(80,20));
		}
		return jComboBox5;
	}
	/**
	 * This method initializes jComboBox6	
	 * 	
	 * @return javax.swing.JComboBox	
	 */    
	private JComboBox getJComboBox6() {
		if (jComboBox6 == null) {
			String[] items = {"January", "February","March","April","May","June","July","August","September","October","November","December"};
			jComboBox6 = new JComboBox(items);
			jComboBox6.setPreferredSize(new java.awt.Dimension(100,20));
		}
		return jComboBox6;
	}
	/**
	 * This method initializes jComboBox7	
	 * 	
	 * @return javax.swing.JComboBox	
	 */    
	private JComboBox getJComboBox7() {
		if (jComboBox7 == null) 
		{
			String days[] = new String[31];
			for( int i =0;i<31;i++)
				days[i] = new String(String.valueOf(i+1));
			jComboBox7 = new JComboBox(days);
			jComboBox7.setPreferredSize(new java.awt.Dimension(50,20));
		}
		return jComboBox7;
	}
	/**
	 * This method initializes jPanel1	
	 * 	
	 * @return javax.swing.JPanel	
	 */    
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jPanel1 = new JPanel();
			jPanel1.setPreferredSize(new java.awt.Dimension(70,20));
			jPanel1.setForeground(java.awt.Color.black);
			jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,0));
			jPanel1.setEnabled(true);
			jPanel1.setVisible(true);
		}
		return jPanel1;
	}
	/**
	 * This method initializes jComboBox8	
	 * 	
	 * @return javax.swing.JComboBox	
	 */    
	private JComboBox getJComboBox8() {
		if (jComboBox8 == null) {
			String items[] ={"Male","Female"};
			jComboBox8 = new JComboBox(items);
			jComboBox8.setPreferredSize(new java.awt.Dimension(90,20));
		}
		return jComboBox8;
	}
	/**
	 * This method initializes jPanel2	
	 * 	
	 * @return javax.swing.JPanel	
	 */    
	private JPanel getJPanel2() {
		if (jPanel2 == null) {
			jPanel2 = new JPanel();
			jPanel2.setPreferredSize(new java.awt.Dimension(40,20));
		}
		return jPanel2;
	}
	/**
	 * This method initializes jComboBox9	
	 * 	
	 * @return javax.swing.JComboBox	
	 */    
	private JComboBox getJComboBox9() {
		if (jComboBox9 == null) {
			String days[] = new String[10];
			for( int i =0;i<10;i++)
				days[i] = new String(String.valueOf(i+1));

			jComboBox9 = new JComboBox(days);
			jComboBox9.setPreferredSize(new java.awt.Dimension(50,20));
		}
		return jComboBox9;
	}
	/**
	 * This method initializes jPanel3	
	 * 	
	 * @return javax.swing.JPanel	
	 */    
	private JPanel getJPanel3() {
		if (jPanel3 == null) {
			jPanel3 = new JPanel();
			jPanel3.setPreferredSize(new java.awt.Dimension(600,100));
			jPanel3.add(getJPanel4(), null);
			jPanel3.add(getSubmitButton(), null);
			jPanel3.add(getCancelButton(), null);
		}
		return jPanel3;
	}
	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */    
	private JButton getSubmitButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setText("Submit");
            jButton.addActionListener(_handler);
            jButton.setActionCommand("SUBMIT");
		}
		return jButton;
	}
	/**
	 * This method initializes jButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */    
	public JButton getCancelButton() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setText("Cancel");
            jButton1.addActionListener(_handler);
            jButton1.setActionCommand("CANCEL");
		}
		return jButton1;
	}
	/**
	 * This method initializes jPanel4	
	 * 	
	 * @return javax.swing.JPanel	
	 */    
	private JPanel getJPanel4() {
		if (jPanel4 == null) {
			jPanel4 = new JPanel();
			jPanel4.setPreferredSize(new java.awt.Dimension(590,40));
		}
		return jPanel4;
	}

	/**
	 * This is the default constructor
	 */
	public BookPanel() {
		super();
        jLabel8 = new JLabel();
        jLabel7 = new JLabel();
        jLabel6 = new JLabel();
        jLabel5 = new JLabel();
        jLabel4 = new JLabel();
        jLabel3 = new JLabel();
        jLabel2 = new JLabel();
        jLabel1 = new JLabel();
        jLabel = new JLabel();
        setLayout(new FlowLayout());
        jLabel.setText("ID Number");
        jLabel.setPreferredSize(new java.awt.Dimension(70,20));
        jLabel1.setText("Name");
        jLabel1.setPreferredSize(new java.awt.Dimension(40,20));
        jLabel2.setText("Room Type");
        jLabel2.setPreferredSize(new java.awt.Dimension(70,20));
        jLabel3.setText("Check-in Date");
        jLabel3.setPreferredSize(new java.awt.Dimension(100,20));
        jLabel4.setText("                             Book a room...");
        jLabel4.setPreferredSize(new java.awt.Dimension(600,60));
        jLabel4.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 18));
        jLabel5.setText("Payment");
        jLabel5.setPreferredSize(new java.awt.Dimension(70,20));
        jLabel6.setText("Check-out Date");
        jLabel6.setPreferredSize(new java.awt.Dimension(100,20));
        jLabel7.setText("Gender");
        jLabel7.setPreferredSize(new java.awt.Dimension(45,20));
        jLabel8.setText("Number of rooms");
        jLabel8.setPreferredSize(new java.awt.Dimension(110,20));
        add(jLabel4, null);
        add(jLabel, null);
        add(getJTextField(), null);
        add(jLabel1, null);
        add(getJTextField1(), null);
        add(jLabel7, null);
        add(getJComboBox8(), null);
        add(getJPanel2(), null);
        add(jLabel2, null);
        add(getJComboBox(), null);
        add(jLabel3, null);
        add(getJComboBox1(), null);
        add(getJComboBox2(), null);
        add(getJComboBox3(), null);
        add(getJPanel(), null);
        add(jLabel5, null);
        add(getJComboBox4(), null);
        add(jLabel6, null);
        add(getJComboBox5(), null);
        add(getJComboBox6(), null);
        add(getJComboBox7(), null);
        add(getJPanel1(), null);
        add(jLabel8, null);
        add(getJComboBox9(), null);
        add(getJPanel3(), null);
        setValues(null);
	}

	public void showOrderInfo(Order order) {
        if(order !=null){
            jComboBox1.setSelectedIndex(order.get_roomType());
            jComboBox9.setSelectedIndex(order.get_roomCount());

            GregorianCalendar tmpCalendar = new GregorianCalendar();
            tmpCalendar.setTime(new Date(order.get_startTime().getTime()));
            jComboBox2.setSelectedIndex(tmpCalendar.get(Calendar.YEAR) - 2005);
            jComboBox3.setSelectedIndex(tmpCalendar.get(Calendar.MONTH) - 1);
            jComboBox4.setSelectedIndex(tmpCalendar.get(Calendar.DATE) - 1);
            tmpCalendar.setTime(new Date(order.get_endTime().getTime()));
            jComboBox6.setSelectedIndex(tmpCalendar.get(Calendar.YEAR) - 2005);
            jComboBox7.setSelectedIndex(tmpCalendar.get(Calendar.MONTH) - 1);
            jComboBox8.setSelectedIndex(tmpCalendar.get(Calendar.DATE) - 1);
        }
	}
	
    public void setValues(Order order){
        if(order == null){
            //add a order
            /*
            todo set value of default value
            */
            showOrderInfo(null);
        }
        else{
            //modify a order
            /*
            todo set value of order
            */
            _currentOrder = order;
            showOrderInfo(order);
        }
        User cu = MainFrame.getMainFrame().getCurrentUser();
        if(cu.get_identity()==User.GRP_CUSTOMER){
            getJTextField1().setEditable(false);
            getJTextField1().setText(cu.get_userName());
        }
    }
    
    public void OnSubmit(){
        Order order = new Order();
        order.set_roomType(jComboBox1.getSelectedIndex());
        order.set_roomCount(jComboBox9.getSelectedIndex() + 1);
        order.set_userName(MainFrame.getMainFrame().getCurrentUser().get_userName());
        Calendar cldStart = new GregorianCalendar(jComboBox2.getSelectedIndex() + 2005,
                jComboBox3.getSelectedIndex() + 1,
                jComboBox4.getSelectedIndex() + 1);
        Calendar cldEnd = new GregorianCalendar(jComboBox6.getSelectedIndex() + 2005,
                jComboBox7.getSelectedIndex() + 1,
                jComboBox8.getSelectedIndex() + 1);
        order.set_startTime(new Time(cldStart.getTime().getTime()));
        order.set_endTime(new Time(cldEnd.getTime().getTime()));
        if (order.Submit()) {
            JOptionPane.showMessageDialog(this, "Order succeeded!", "Message", JOptionPane.OK_OPTION);
        }else {
            JOptionPane.showMessageDialog(this, "Order failed!", "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    private class Handler implements ActionListener{
        public void actionPerformed(ActionEvent ev) {
            if("SUBMIT" == ev.getActionCommand()){
                /*
                todo submit process
                */
                OnSubmit();
                _currentOrder = null;
                System.out.println("bookpanel submit button clicked");
            }
            else if("CANCEL" == ev.getActionCommand()){

                setValues(_currentOrder);
                System.out.println("bookpanel cancel button cliked");
            }
            else if("EXIT" == ev.getActionCommand()){
                JFrame parent = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class,(JButton)ev.getSource());
                parent.dispose();
            }

        }
    }
    public static void main(String[] args)
    {
        JFrame frame = new JFrame("Book");
        frame.setResizable(false);
		frame.setSize(640, 320);
        frame.setContentPane(new BookPanel());
        //frame.pack();
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setLocation(100,100);
        frame.setVisible(true);
	}
}

⌨️ 快捷键说明

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