aa

来源:互联网 发布:谷歌tts语音数据 编辑:程序博客网 时间:2024/05/01 11:13


package com.flicker.simulator;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;import javax.swing.JButton;import javax.swing.JComponent;import javax.swing.JDialog;import javax.swing.JPanel;import javax.swing.JSeparator;import javax.swing.SpringLayout;public abstract class AbsSetDialog extends JDialog{    private static final long serialVersionUID = 1L;        // Static fields.        public static final int   DIALOG_WIDTH     = 400;    public static final int   DIALOG_HEIGHT    = 300;        protected JButton         connectBtn, cancelBtn;        public AbsSetDialog()    {        initUI();        initAction();                setSize(DIALOG_WIDTH, DIALOG_HEIGHT);        setResizable(false);        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();        setLocation((screenSize.width - DIALOG_WIDTH) / 2, (screenSize.height - DIALOG_HEIGHT) / 2);    }        private void initUI()    {        this.setLayout(new BorderLayout());                JComponent container = createContainer();        JPanel wzButtons = createWizardButtons();                this.add(container, BorderLayout.CENTER);        this.add(wzButtons, BorderLayout.SOUTH);    }        private void initAction()    {        connectBtn.addActionListener(new ActionListener() {            @Override            public void actionPerformed(ActionEvent e)            {                doConnect();            }        });                cancelBtn.addActionListener(new ActionListener() {            @Override            public void actionPerformed(ActionEvent e)            {                doCancel();            }        });    }        private JPanel createWizardButtons()    {        JPanel panel = new JPanel();                int WIZARD_WIDTH = 400;        int WIZARD_HEIGHT = 45;        panel.setPreferredSize(new Dimension(WIZARD_WIDTH, WIZARD_HEIGHT));        SpringLayout springLayout = new SpringLayout();        panel.setLayout(springLayout);                connectBtn = new JButton("Connect");        connectBtn.setPreferredSize(new Dimension(85, 23));        connectBtn.setMnemonic(KeyEvent.VK_F);        springLayout.putConstraint(SpringLayout.NORTH, connectBtn, 10, SpringLayout.NORTH, panel);        springLayout.putConstraint(SpringLayout.EAST, connectBtn, -10, SpringLayout.WEST, cancelBtn);        panel.add(connectBtn);                cancelBtn = new JButton("Cancel");        cancelBtn.setPreferredSize(new Dimension(85, 23));        cancelBtn.setMnemonic(KeyEvent.VK_C);        springLayout.putConstraint(SpringLayout.NORTH, cancelBtn, 10, SpringLayout.NORTH, panel);        springLayout.putConstraint(SpringLayout.EAST, cancelBtn, -10, SpringLayout.EAST, panel);        panel.add(cancelBtn);                JSeparator separator = new JSeparator();        separator.setPreferredSize(new Dimension(80, 23));        springLayout.putConstraint(SpringLayout.NORTH, separator, 0, SpringLayout.NORTH, panel);        springLayout.putConstraint(SpringLayout.WEST, separator, 0, SpringLayout.WEST, panel);        springLayout.putConstraint(SpringLayout.EAST, separator, 0, SpringLayout.EAST, panel);                return panel;    }        private void doConnect()    {        //        if (canFinish())        //        {        //            finishBtn.setEnabled(true);        //        }    }        private void doCancel()    {            }        public abstract JComponent createContainer();}


package com.flicker.simulator;import java.awt.BorderLayout;import java.awt.Dimension;import javax.swing.JComponent;import javax.swing.JPanel;import javax.swing.JScrollPane;public class FtpConnectSetDialog extends AbsSetDialog{    JPanel paramPanel = null;        @Override    public JComponent createContainer()    {        JScrollPane paramPanel = new JScrollPane();        paramPanel.setAutoscrolls(true);                JPanel centerPanel= new JPanel();        centerPanel.setLayout(new BorderLayout());                centerPanel.add(new JPanel(), BorderLayout.NORTH);                this.setPreferredSize(new Dimension(400, 250));        paramPanel.getViewport().add(centerPanel);        paramPanel.setLocation(getLocation());        return paramPanel;    }    }





package com.flicker.simulator;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;import java.awt.event.WindowEvent;import java.awt.event.WindowListener;import javax.swing.BorderFactory;import javax.swing.JCheckBoxMenuItem;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JPanel;import javax.swing.KeyStroke;import javax.swing.SwingUtilities;public class FtpSimulator extends JPanel{    private static final long serialVersionUID = 1L;        // Static fields.        public static final int   FRAME_WIDTH      = 600;    public static final int   FRAME_HEIGHT     = 450;        // Fields.    private AbsSetDialog      setDialog        = null;        // Constructors.        public FtpSimulator(JFrame frame)    {        super(new BorderLayout());                // Listen when the frame is closed. The workspace should be saved.        frame.addWindowListener(new WorkspaceSaver());                // These are the root docks.        TextPanel textPanel = new TextPanel("a text Panel");                // Add the root dock to the panel.        add(textPanel, BorderLayout.CENTER);                // Create the menubar.        JMenuBar menuBar = createMenu();        frame.setJMenuBar(menuBar);            }        /**     * Creates the menubar with two menus: File and Window.     * File has the Exit menu item. Window has check boxes for the dockables.     *      * @param     * @return              The created menu bar.     */    private JMenuBar createMenu()    {        // Create the menu bar.        JMenuBar menuBar = new JMenuBar();                // Build the File menu.        JMenu fileMenu = new JMenu("File");        fileMenu.setMnemonic(KeyEvent.VK_F);        fileMenu.getAccessibleContext().setAccessibleDescription("The file menu");        menuBar.add(fileMenu);                // Build the Window menu.        JMenu windowMenu = new JMenu("Window");        windowMenu.setMnemonic(KeyEvent.VK_W);        windowMenu.getAccessibleContext().setAccessibleDescription("The window menu");        menuBar.add(windowMenu);                // The JMenuItem for File        JMenuItem menuItemExit = new JMenuItem("Exit", KeyEvent.VK_E);        menuItemExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.ALT_MASK));        menuItemExit.getAccessibleContext().setAccessibleDescription("Exit the application");        menuItemExit.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent arg0)            {                saveWorkspace();                System.exit(0);            }        });        fileMenu.add(menuItemExit);                JMenuItem menuItemConn = new JMenuItem("Connect", null);        menuItemConn.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.ALT_MASK));        menuItemConn.getAccessibleContext().setAccessibleDescription("Set the connection");        menuItemConn.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent arg0)            {                setDialog = new FtpConnectSetDialog();                                setDialog.setVisible(true);            }        });        fileMenu.add(menuItemConn);                // The JMenuItem for Window        JCheckBoxMenuItem cbMenuItem = new JCheckBoxMenuItem();        windowMenu.add(cbMenuItem);                return menuBar;            }        private void saveWorkspace()    {            }        /**     * A listener for window closing events. Saves the workspace, when the application window is closed.     *      * @author Heidi Rakels.     */    private class WorkspaceSaver implements WindowListener    {                public void windowClosing(WindowEvent windowEvent)        {            saveWorkspace();        }                public void windowDeactivated(WindowEvent windowEvent)        {        }                public void windowDeiconified(WindowEvent windowEvent)        {        }                public void windowIconified(WindowEvent windowEvent)        {        }                public void windowOpened(WindowEvent windowEvent)        {        }                public void windowActivated(WindowEvent windowEvent)        {        }                public void windowClosed(WindowEvent windowEvent)        {        }            }        /**     * This is the class for the content.     */    private class TextPanel extends JPanel    {        private static final long serialVersionUID = 1L;                private JLabel            label;                public TextPanel(String text)        {            super(new FlowLayout());                        // The panel.            setMinimumSize(new Dimension(80, 80));            setPreferredSize(new Dimension(150, 150));            setBackground(Color.white);            setBorder(BorderFactory.createLineBorder(Color.lightGray));                        // The label.            label = new JLabel(text);            label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));            add(label);        }    }        // Main method.        public static void createAndShowGUI()    {        // Create the frame.        JFrame frame = new JFrame("Data Simulator");                // Create the panel and add it to the frame.        FtpSimulator panel = new FtpSimulator(frame);        frame.getContentPane().add(panel);                // Set the frame properties and show it.        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();        frame.setLocation((screenSize.width - FRAME_WIDTH) / 2, (screenSize.height - FRAME_HEIGHT) / 2);        frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);        frame.setVisible(true);    }        public static void main(String args[])    {        Runnable doCreateAndShowGUI = new Runnable() {            public void run()            {                createAndShowGUI();            }        };        SwingUtilities.invokeLater(doCreateAndShowGUI);    }    }







0 0
原创粉丝点击