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(); }
public static void main() { // Main frame = new JFrame("Java Playground"); frame.setSize(640, 480); // Make sure the divider is properly resized frame.addComponentListener( new ComponentAdapter() { public void componentResized(ComponentEvent c) { splitter.setDividerLocation(.8); } }); // Make sure the JVM is reset on close frame.addWindowListener( new WindowAdapter() { public void windowClosed(WindowEvent w) { new FrameAction().kill(); } }); // Setting up the keybinding // Ctrl+k or Cmd+k -> compile bind(KeyEvent.VK_K); // Ctrl+e or Cmd+e -> console bind(KeyEvent.VK_E); // Save, New file, Open file, Print. // Currently UNUSED until I figure out how normal java files and playground files will // interface. bind(KeyEvent.VK_S); bind(KeyEvent.VK_N); bind(KeyEvent.VK_O); bind(KeyEvent.VK_P); // Binds the keys to the action defined in the FrameAction class. frame.getRootPane().getActionMap().put("console", new FrameAction()); // The main panel for typing code in. text = new JTextPane(); textScroll = new JScrollPane(text); textScroll.setBorder(null); textScroll.setPreferredSize(new Dimension(640, 480)); // Document with syntax highlighting. Currently unfinished. doc = text.getStyledDocument(); doc.addDocumentListener( new DocumentListener() { public void changedUpdate(DocumentEvent d) {} public void insertUpdate(DocumentEvent d) {} public void removeUpdate(DocumentEvent d) {} }); ((AbstractDocument) doc).setDocumentFilter(new NewLineFilter()); // The output log; a combination compiler warning/error/runtime error/output log. outputText = new JTextPane(); outputScroll = new JScrollPane(outputText); outputScroll.setBorder(null); // "Constant" for the error font error = new SimpleAttributeSet(); error.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE); error.addAttribute(StyleConstants.Foreground, Color.RED); // "Constant" for the warning message font warning = new SimpleAttributeSet(); warning.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE); warning.addAttribute(StyleConstants.Foreground, Color.PINK); // "Constant" for the debugger error font progErr = new SimpleAttributeSet(); progErr.addAttribute(StyleConstants.Foreground, Color.BLUE); // Print streams to redirect System.out and System.err. out = new TextOutputStream(outputText, null); err = new TextOutputStream(outputText, error); System.setOut(new PrintStream(out)); System.setErr(new PrintStream(err)); // Sets up the output log outputText.setEditable(false); outputScroll.setVisible(true); // File input/output setup chooser = new JFileChooser(); // Setting up miscellaneous stuff compiler = ToolProvider.getSystemJavaCompiler(); JVMrunning = false; redirectErr = null; redirectOut = null; redirectIn = null; // Sets up the splitter pane and opens the program up splitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT, textScroll, outputScroll); consoleDisplayed = false; splitter.remove(outputScroll); // Initially hides terminal until it is needed splitter.setOneTouchExpandable(true); frame.add(splitter); frame.setVisible(true); // Sets the divider to the proper one, for debugging // splitter.setDividerLocation(.8); }
void jbInit() throws Exception { border1 = BorderFactory.createEmptyBorder(10, 10, 5, 5); panel1.setLayout(borderLayout1); jPanel1.setLayout(borderLayout2); jScrollPane1.getViewport().setBackground(Color.white); jPanel2.setLayout(gridBagLayout1); jLabel1.setText("Profile Name : "); nameTextField.setMinimumSize(new Dimension(4, 18)); nameTextField.setPreferredSize(new Dimension(63, 18)); jLabel2.setText("Profile Type : "); openButton.setMaximumSize(new Dimension(73, 24)); openButton.setMinimumSize(new Dimension(73, 24)); openButton.setPreferredSize(new Dimension(73, 24)); openButton.setText("Open"); openButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { openButton_actionPerformed(e); } }); cancelButton.setMaximumSize(new Dimension(73, 24)); cancelButton.setMinimumSize(new Dimension(73, 24)); cancelButton.setPreferredSize(new Dimension(73, 24)); cancelButton.setMargin(new Insets(0, 5, 0, 5)); cancelButton.setText("Cancel"); cancelButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { cancelButton_actionPerformed(e); } }); profileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); profileList.addMouseListener( new java.awt.event.MouseAdapter() { public void mouseClicked(MouseEvent e) { profileList_mouseClicked(e); } }); jPanel2.setBorder(border1); typeComboBox.setMaximumSize(new Dimension(32767, 18)); typeComboBox.setMinimumSize(new Dimension(122, 18)); typeComboBox.setPreferredSize(new Dimension(176, 18)); getContentPane().add(panel1); panel1.add(jPanel1, BorderLayout.CENTER); jPanel1.add(jScrollPane1, BorderLayout.CENTER); panel1.add(jPanel2, BorderLayout.SOUTH); jPanel2.add( jLabel1, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 7, 0), 0, 0)); jPanel2.add( nameTextField, new GridBagConstraints( 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 11, 7, 0), 0, 0)); jPanel2.add( jLabel2, new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 17, 0), 0, 0)); jScrollPane1.getViewport().add(profileList, null); jPanel2.add( openButton, new GridBagConstraints( 3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 11, 2, 10), 0, 0)); jPanel2.add( cancelButton, new GridBagConstraints( 3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 11, 9, 10), 0, 0)); jPanel2.add( typeComboBox, new GridBagConstraints( 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 11, 17, 0), 0, 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); }