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

📄 mainpanel.java

📁 This project developed in java leads us to realize a flight reservation system in order to emulate d
💻 JAVA
字号:
/* * MainPanel.java * The package panels contains the different class executing the different windows of each function of the FlightSystem Reservation. */package reservation.system.panels;import reservation.*;import reservation.system.functions.*;import javax.swing.*;import javax.swing.filechooser.*;import java.awt.Dimension;import java.awt.event.*;import java.io.*;/** * Create the object MainPanel. It define the first window where the user can chose the command to execute and that displays the result of the command. * @author Texier Mathieu and Frederic Bidon */public class MainPanel extends Panels {        /** Creates new form MainPanel */    public MainPanel () {    }        /**     * Constructor of this class. Do all the instance for create the graphical window.     * @param mainDlg Parent object     */    public MainPanel (final CustomDialog mainDlg) {        actionLabel = new JLabel ();        actionComboBox = new JComboBox ();        jScrollPane1 = new JScrollPane ();        resultTextArea = new JTextArea ();                actionLabel.setText ("Action");        add (actionLabel);                actionComboBox.addActionListener (new ActionListener () {            public void actionPerformed (ActionEvent evt) {                Action (mainDlg);            }        });        add (actionComboBox);                resultTextArea.setEditable (false);        jScrollPane1.setViewportView (resultTextArea);        add (jScrollPane1);        init ();    }        /**     * Determine the command chosen by the user to create the apropriate window.     */    private void Action (CustomDialog mainDlg) {        int nAction = actionComboBox.getSelectedIndex ();        String retValue = "Not executed \n";        JFileChooser chooser = null;        ExampleFileFilter filter;        Functions action;                switch (nAction) {            case CustomDialog.STORE:                retValue = Store ();                break;                            case CustomDialog.READ_COMMAND:                retValue = ReadComand ();                break;                            case CustomDialog.RELOAD:                retValue = Reload ();                break;                            case CustomDialog.CREATE:            case CustomDialog.RESERVE:            case CustomDialog.CANCEL:            case CustomDialog.SELECT:            case CustomDialog.FLIGHTS:                CustomDialog dlg = new CustomDialog (mainDlg, true, (String) actionComboBox.getSelectedItem (),nAction);                dlg.process ();                retValue = dlg.getRetValue ();                break;            default:                CustomDialog.alert (new Exception ("Wrong slot value."));        }        init ();        resultTextArea.append (retValue);    }        /**     * Open a file selector dialog and read interprete the Request Comand Message that are contained     * @return the appropriate result     */        static public String ReadComand () {        JFileChooser chooser = new JFileChooser ();        ExampleFileFilter filter = new ExampleFileFilter ();        filter.addExtension ("rcm");        filter.setDescription ("request command message");        chooser.setFileFilter (filter);        if(chooser.showOpenDialog (null) == JFileChooser.APPROVE_OPTION) {            File file = chooser.getSelectedFile ();            try {                BufferedReader in = new BufferedReader (new InputStreamReader (new FileInputStream (file)));                Command mode = new Command (in,Mode.QUIET);                mode.process ();                return "File Loaded";            } catch (FileNotFoundException e){CustomDialog.alert (new Exception ("error while opening file :" + file.getAbsolutePath ()));}        }        return "Read command failed";    }        /**     * Open a file selector dialog and deserialize the containing Flight System     * @return the appropriate result     */        static public String Reload () {        Functions action = new Reload ();        JFileChooser chooser = new JFileChooser ();        ExampleFileFilter filter = new ExampleFileFilter ();        filter.addExtension ("out");        filter.setDescription ("*.out");        chooser.setFileFilter (filter);        if(chooser.showOpenDialog (null) == JFileChooser.APPROVE_OPTION) {            String fileName[] = new String [1];            File datafile = chooser.getSelectedFile ();            fileName[0] = datafile.getAbsolutePath ();            try {                return action.execute (fileName) + "\n";            }catch (Exception e) {CustomDialog.alert (e);}        }        return " Reload Failed";    }        /**     * Open a file selector dialog and store the serialzed Flight System     * @return the appropriate result     */        static public String Store () {        Functions action = new Store ();        JFileChooser chooser = new JFileChooser ();        ExampleFileFilter filter = new ExampleFileFilter ();        filter.addExtension ("out");        filter.setDescription ("*.out");        chooser.setFileFilter (filter);        if(chooser.showSaveDialog (null) == JFileChooser.APPROVE_OPTION) {            String fileName[] = new String [1];            File datafile = chooser.getSelectedFile ();            fileName[0] = datafile.getAbsolutePath ();            try {                return action.execute (fileName) + "\n";            }catch (Exception e) {CustomDialog.alert (e);}        }        return "Store failed";    }    /**     * Causes this container to lay out its components.     */    public void doLayout () {        actionLabel.setBounds (30, 10, 80, 20);        actionComboBox.setBounds (100, 10, 110, 20);        jScrollPane1.setBounds (20, 40, 450, 90);    }        /**     * Set the size of the panel     * @return an instance of Dimension that represents the minimum size of this container.     */    public Dimension getMinimumSize () {        return new Dimension (500,140);    }        /**     * Set the size of the panel     * @return an instance of Dimension that represents the preferred size of this container.     */    public Dimension getPreferredSize () {        return new Dimension (500,140);    }        /**     * Initialize the number of the field and fill them with default values.     * Dispaly the label of the Window.     */    public void init () {        actionComboBox.removeAllItems ();        try {            actionComboBox.insertItemAt ("Reload", CustomDialog.RELOAD);            actionComboBox.insertItemAt ("Read command", CustomDialog.READ_COMMAND);            actionComboBox.insertItemAt ("Create", CustomDialog.CREATE);            if (fs.getFlightList ().length > 0) {                actionComboBox.insertItemAt ("Store", CustomDialog.STORE);                actionComboBox.insertItemAt ("Reserve", CustomDialog.RESERVE);                actionComboBox.insertItemAt ("Flights", CustomDialog.FLIGHTS);                if (fs.getBookingList ().length > 0) {                    actionComboBox.insertItemAt ("Cancel", CustomDialog.CANCEL);                    actionComboBox.insertItemAt ("Select", CustomDialog.SELECT);                }            }        }        catch (Exception e) {CustomDialog.alert (e);}    }        /**     * Proceed the execution of the action     * @return the result of the request.     * @param unUsed Not used     * @throws Exception if the command is not executed.     */    public String execute (String[] unUsed) throws Exception {        return "";    }        private JComboBox actionComboBox;    private JLabel actionLabel;    private JScrollPane jScrollPane1;    private JTextArea resultTextArea;}

⌨️ 快捷键说明

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