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

📄 customdialog.java

📁 This project developed in java leads us to realize a flight reservation system in order to emulate d
💻 JAVA
字号:
/* * CustomDialog.java * The package reservation contains the different class allowing to choose the action to realise. */package reservation;import reservation.system.panels.*;import reservation.system.FlightSystem;import javax.swing.*;import java.awt.event.*;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.Font;/** * This class hold CustomDialog structure. This object analyse the instruction written by the user and determine according to the first element the command to execute. * Then it instancie a new object which depends to the command and which will execute the instruction of the user. * The new object instantiated create a new window corresponding to the command to execute. * @author Texier Mathieu and Frederic Bidon */public class CustomDialog extends JDialog implements Mode {        /**Integer defining the command RELOAD.*/    static final public int RELOAD = 0;    /**Integer defining the command READ_COMMAND.*/    static final public int READ_COMMAND = 1;    /**Integer defining the command CREATE.*/    static final public int CREATE = 2;    /**Integer defining the command STORE.*/    static final public int STORE = 3;    /**Integer defining the command RESERVE.*/    static final public int RESERVE = 4;    /**Integer defining the command FLIGHTS.*/    static final public int FLIGHTS = 5;    /**Integer defining the command CANCEL.*/    static final public int CANCEL = 6;    /**Integer defining the command SELECT.*/    static final public int SELECT = 7;        /**Create a new instance with the level of verbosity QUIET*/    public CustomDialog () {        this (QUIET);    }        /**     * Create a new instance of CustomDialog     * @param verboseMode Integer defining the level of verbosity to execute the program.     */    public CustomDialog (int verboseMode) {        super ();        setModal (true);        String title = "Flight System";        this.VerboseMode = VerboseMode;                String laf = UIManager.getSystemLookAndFeelClassName ();        try {            UIManager.setLookAndFeel (laf);        } catch (UnsupportedLookAndFeelException exc) {            System.err.println ("Warning: UnsupportedLookAndFeel: " + laf);        } catch (Exception exc) {            System.err.println ("Error loading " + laf + ": " + exc);        }                addWindowListener (new WindowAdapter () {            public void windowClosing (WindowEvent evt) {                try {                    if (FlightSystem.getInstance ().getFlightList ().length > 0) {                        int res = JOptionPane.showConfirmDialog (null, "Would you like to save the dataBase ?", "save", JOptionPane.YES_NO_OPTION);                        if (res == JOptionPane.OK_OPTION)                            MainPanel.Store ();                    }                } catch (Exception e) {alert (e);}                System.exit (0);            }        });                setResizable (false);        setTitle (title);        action = new MainPanel (this);                JLabel titleLabel = new JLabel ();        titleLabel.setFont (new Font ("MS Sans Serif", 1, 18));        titleLabel.setHorizontalAlignment (SwingConstants.CENTER);        titleLabel.setText (title);                getContentPane ().add (titleLabel, BorderLayout.NORTH);        getContentPane ().add ((Panels)action, BorderLayout.CENTER);        pack ();    }        /**     * This method determine the number of element of the user's instruction and analyse the first element of this one.     * If it corresponds to an available command of the system, it create a new object depending of the command.     * This new object will execute the instruction with the other elements of the command.     * @param owner Dilog or frame from which the CustomDialog is issue     * @param modal Modal mode     * @param title The title of the window     * @param command The identifier of the command (RELOAD, CREATE, CANCEL ...)     */    public CustomDialog (CustomDialog owner, boolean modal, String title, int command) {        super (owner, modal);        this.owner = owner;                String laf = UIManager.getSystemLookAndFeelClassName ();        try {            UIManager.setLookAndFeel (laf);        } catch (UnsupportedLookAndFeelException exc) {            System.err.println ("Warning: UnsupportedLookAndFeel: " + laf);        } catch (Exception exc) {            System.err.println ("Error loading " + laf + ": " + exc);        }                setDefaultCloseOperation (WindowConstants.DISPOSE_ON_CLOSE);        setResizable (false);        setTitle (title);                JLabel titleLabel = new JLabel ();        titleLabel.setFont (new java.awt.Font ("MS Sans Serif", 1, 18));        titleLabel.setHorizontalAlignment (SwingConstants.CENTER);        titleLabel.setText (title);                switch(command){            case CREATE:                action = new CreatePanel ();                break;            case RESERVE:                action = new ReservePanel ();                break;            case CANCEL:                action = new CancelPanel ();                break;            case SELECT:                action = new SelectPanel ();                break;            case FLIGHTS:                action = new FlightsPanel ();                break;            default:                action = new MainPanel ();                break;        }        ((Panels) action).init ();        FootPanel footPanel = new FootPanel ();                getContentPane ().add (titleLabel, BorderLayout.NORTH);        getContentPane ().add ( (Panels) action, BorderLayout.CENTER);        getContentPane ().add (footPanel, BorderLayout.SOUTH);        pack ();    }            /**     * This method create a new dialog window according to the selected command.     */    public void process () {        if (owner != null)            ((Panels) owner.action).init ();        show ();    }            /**     * This method allows to access the private string retValue.     * @return the string retValue.     */    public String getRetValue () {        return retValue;    }            /**     * Open a new window to specify the produced error by the user.     * @param exception The message that will be displayed in the message box     */    static public void alert (Exception exception) {        JOptionPane.showMessageDialog (null, exception.getMessage (), "Error", JOptionPane.ERROR_MESSAGE);        if (VerboseMode == DEBUG)            exception.printStackTrace ();    }            /**     * Open a new dialog window to give more informations to the user.     * @param info The message that will be displayed in the message box     */    static public void alert (String info) {        JOptionPane.showMessageDialog (null, info, "Information", JOptionPane.INFORMATION_MESSAGE);    }            /**     * Hide the dialog     */    protected void quit (){        hide ();    }        private CustomDialog owner;        private  Action action = new MainPanel ();        private String retValue = new String ();        static private int VerboseMode = NORMAL;        private class FootPanel extends JPanel {                /** Creates new form footPanel */        public FootPanel () {            validButton = new JButton ();            cancelButton = new JButton ();                        validButton.setText ("Valid");            add (validButton);                        validButton.addActionListener (new ActionListener () {                public void actionPerformed (ActionEvent evt) {                    try {                        retValue = action.execute (null);                    } catch (Exception e) {                        CustomDialog.alert (e);                    }                    quit ();                }            });            cancelButton.setText ("Cancel");            cancelButton.addActionListener (new ActionListener () {                public void actionPerformed (ActionEvent evt) {                    quit ();                }            });            add (cancelButton);        }        private JButton cancelButton;        private JButton validButton;    }}

⌨️ 快捷键说明

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