예제 #1
0
  void initComponents() {
    JPanel mainPanel = new JPanel(new BorderLayout());
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    Color bgColor = Color.getHSBColor(0.58f, 0.17f, 0.95f);
    buttonPanel.setBackground(bgColor);
    Border empty = BorderFactory.createEmptyBorder(5, 5, 5, 5);
    buttonPanel.setBorder(empty);

    textField = new JTextField(75);
    buttonPanel.add(textField);

    buttonPanel.add(Box.createHorizontalStrut(10));
    searchPHI = new JButton("Search PHI");
    searchPHI.addActionListener(this);
    buttonPanel.add(searchPHI);

    buttonPanel.add(Box.createHorizontalStrut(10));
    searchTrial = new JButton("Search Trial IDs");
    searchTrial.addActionListener(this);
    buttonPanel.add(searchTrial);

    buttonPanel.add(Box.createHorizontalStrut(20));
    buttonPanel.add(Box.createHorizontalGlue());
    saveAs = new JCheckBox("Save As...");
    saveAs.setBackground(bgColor);
    buttonPanel.add(saveAs);

    mainPanel.add(buttonPanel, BorderLayout.NORTH);

    JScrollPane scrollPane = new JScrollPane();
    textPane = new ColorPane();
    // textPane.setEditable(false);
    scrollPane.setViewportView(textPane);
    mainPanel.add(scrollPane, BorderLayout.CENTER);

    JPanel footerPanel = new JPanel();
    footerPanel.setLayout(new BoxLayout(footerPanel, BoxLayout.X_AXIS));
    footerPanel.setBackground(bgColor);
    message = new JLabel("Ready...");
    footerPanel.add(message);
    mainPanel.add(footerPanel, BorderLayout.SOUTH);

    setTitle(windowTitle);
    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent evt) {
            System.exit(0);
          }
        });
    getContentPane().add(mainPanel, BorderLayout.CENTER);
    pack();
    centerFrame();
  }
예제 #2
0
  /** 程式的GUI畫面配置,並登入按鈕、選項監聽。 */
  private void GUI() {
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);

    JMenuItem file_newMenuItem = new JMenuItem("New");
    file_newMenuItem.setIcon(
        new ImageIcon(
            DocumentEditGUI.class.getResource("/javax/swing/plaf/metal/icons/ocean/file.gif")));
    file_newMenuItem.addActionListener(new SystemFileNew());
    fileMenu.add(file_newMenuItem);

    JMenuItem file_openMenuItem = new JMenuItem("Open File...");
    file_openMenuItem.setIcon(
        new ImageIcon(
            DocumentEditGUI.class.getResource(
                "/com/sun/java/swing/plaf/windows/icons/TreeOpen.gif")));
    file_openMenuItem.addActionListener(new SystemFileOpen());
    fileMenu.add(file_openMenuItem);

    JMenu file_saveMenu = new JMenu("Save");
    fileMenu.add(file_saveMenu);

    JMenuItem file_save_saveMenuItem = new JMenuItem("Save");
    file_save_saveMenuItem.setIcon(
        new ImageIcon(
            DocumentEditGUI.class.getResource(
                "/com/sun/java/swing/plaf/windows/icons/FloppyDrive.gif")));
    file_save_saveMenuItem.addActionListener(new SystemFileSave());
    file_save_saveMenuItem.setAccelerator(
        KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
    file_saveMenu.add(file_save_saveMenuItem);

    JMenuItem file_save_save_asMenuItem = new JMenuItem("Save as");
    file_save_save_asMenuItem.addActionListener(new SystemFileSaveAS());
    file_saveMenu.add(file_save_save_asMenuItem);

    JMenuItem file_save_save_allMenuItem = new JMenuItem("Save all");
    file_save_save_allMenuItem.setAccelerator(
        KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK));
    file_save_save_allMenuItem.addActionListener(new SystemFileSaveAll());
    file_saveMenu.add(file_save_save_allMenuItem);

    JMenu file_closeMenu = new JMenu("Close");
    fileMenu.add(file_closeMenu);

    JMenuItem file_close_closeMenuItem = new JMenuItem("Close File");
    file_close_closeMenuItem.addActionListener(new SystemFileClose());
    file_closeMenu.add(file_close_closeMenuItem);

    JMenuItem file_close_close_all_fileMenuItem = new JMenuItem("Close all File");
    file_close_close_all_fileMenuItem.addActionListener(new SystemFileCloseAll());
    file_closeMenu.add(file_close_close_all_fileMenuItem);

    JMenuItem file_exitMenuItem = new JMenuItem("Exit");
    file_exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_MASK));
    file_exitMenuItem.addActionListener(new SystemExit());
    fileMenu.add(file_exitMenuItem);

    JMenu editMenu = new JMenu("Edit");
    menuBar.add(editMenu);

    replace_searchMenuItem.addActionListener(replace_search);
    replace_searchMenuItem.setAccelerator(
        KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK));
    editMenu.add(replace_searchMenuItem);

    SystemEditCut_Copy_Paste cut_copy_paste = new SystemEditCut_Copy_Paste();
    cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
    cutMenuItem.addActionListener(cut_copy_paste);
    editMenu.add(cutMenuItem);
    copyMenutem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK));

    copyMenutem.addActionListener(cut_copy_paste);
    editMenu.add(copyMenutem);
    pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK));

    pasteMenuItem.addActionListener(cut_copy_paste);
    editMenu.add(pasteMenuItem);

    JMenuItem pathMenuItem = new JMenuItem("Default AutoSave-Path");
    pathMenuItem.addActionListener(new SystemEditSetPath());
    editMenu.add(pathMenuItem);

    JMenu helpMenu = new JMenu("Help");
    menuBar.add(helpMenu);

    JMenuItem HelpMenuItem = new JMenuItem("Help");
    HelpMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            JOptionPane.showMessageDialog(null, help, "Help!", JOptionPane.INFORMATION_MESSAGE);
          }
        });
    helpMenu.add(HelpMenuItem);

    JMenuItem AboutNewMenuItem = new JMenuItem("About");
    AboutNewMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, about, "About...", JOptionPane.INFORMATION_MESSAGE);
          }
        });
    helpMenu.add(AboutNewMenuItem);

    JToolBar toolBar = new JToolBar();
    getContentPane().add(toolBar, BorderLayout.NORTH);

    scrollPane.setViewportView(td);
    JButton newFileButton = new JButton("New");
    newFileButton.setIcon(
        new ImageIcon(
            DocumentEditGUI.class.getResource("/javax/swing/plaf/metal/icons/ocean/file.gif")));
    newFileButton.setToolTipText("New File.");
    newFileButton.addActionListener(new SystemFileNew());
    toolBar.add(newFileButton);

    JButton openFileButton = new JButton("Open");
    openFileButton.setIcon(
        new ImageIcon(
            DocumentEditGUI.class.getResource(
                "/javax/swing/plaf/metal/icons/ocean/directory.gif")));
    openFileButton.setToolTipText("Open File.");
    openFileButton.addActionListener(new SystemFileOpen());
    toolBar.add(openFileButton);

    JButton save_asFileButton = new JButton("Save as");
    save_asFileButton.setToolTipText("Save as File.");
    save_asFileButton.addActionListener(new SystemFileSaveAS());
    toolBar.add(save_asFileButton);

    JButton saveFileButton = new JButton("Save");
    saveFileButton.setIcon(
        new ImageIcon(
            DocumentEditGUI.class.getResource("/javax/swing/plaf/metal/icons/ocean/floppy.gif")));
    saveFileButton.setToolTipText("Savet his File.");
    saveFileButton.addActionListener(new SystemFileSave());
    toolBar.add(saveFileButton);

    JButton save_allFileButton = new JButton("Save all");
    save_allFileButton.setToolTipText("Save all File.");
    save_allFileButton.addActionListener(new SystemFileSaveAll());
    toolBar.add(save_allFileButton);

    JButton closeButton = new JButton("Close");
    closeButton.setToolTipText("Close this file.");
    closeButton.addActionListener(new SystemFileClose());
    toolBar.add(closeButton);

    JButton close_allButton = new JButton("Close all");
    close_allButton.setToolTipText("Close al File.");
    close_allButton.addActionListener(new SystemFileCloseAll());
    toolBar.add(close_allButton);
  }