AdminMain() { l = new JLabel(); l.setBounds(10, 20, 1340, 1000); l.setBackground(Color.black); Font ft = new Font("Arial", Font.BOLD, 30); Font ft1 = new Font("Arial", Font.BOLD, 14); Font ft2 = new Font("Arial", Font.BOLD, 20); f1 = new Frame("Soft Test Management (Beta)"); f1.setLayout(null); l1 = new Label("Test Instructions", l1.CENTER); l1.setBounds(10, 20, 1300, 60); l1.setForeground(Color.blue); l1.setBackground(Color.white); l1.setFont(ft); l2 = new JLabel("Deletion of Faculty/Students"); l2.setBounds(20, 30, 1000, 500); l2.setBackground(Color.blue); l2.setFont(ft2); l3 = new JLabel("Test Pattern"); l3.setBounds(20, 90, 1300, 500); l3.setBackground(Color.green); l3.setFont(ft2); b1 = new JButton("Go !"); b1.setBounds(300, 220, 120, 30); b1.setBackground(Color.white); b1.setForeground(Color.blue); b1.setFont(ft2); b2 = new JButton("Go"); b2.setBounds(300, 240, 120, 30); b2.setBackground(Color.white); b2.setForeground(Color.blue); b2.setFont(ft2); f1.add(l); l.add(l1); l2.add(b1); l.add(l2); l3.add(b2); l.add(l3); b1.addActionListener(this); b2.addActionListener(this); f1.setVisible(true); f1.setSize(1800, 800); }
/** * Creates the button panel with the query and reset buttons in a box layout. * * @return The constructed button panel. */ public JPanel createButtonPane() { // Set up the panel. buttonPane = new JPanel(); queryBtn = new JButton("Query"); // Create and add action listener to query and reset buttons. queryBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { parentCS.requestQuery(2, catCb1.getSelectedIndex(), catCb2.getSelectedIndex()); } }); resetBtn = new JButton("Reset"); resetBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { parentCS.switchContext(-1); } }); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS)); // Add buttons to panel. buttonPane.add(queryBtn); buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); buttonPane.add(resetBtn); return buttonPane; }
// GUI介面 public SystemEditReplace_Search() { jp.add(jl1); jp.add(tf1); jp.add(jl2); jp.add(tf2); jp.add(jb1); jb1.addActionListener(this); jp.add(jb2); jb2.addActionListener(this); }
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 TextFields() { t1.setDocument(ucd); ucd.addDocumentListener(new T1()); b1.addActionListener(new B1()); b2.addActionListener(new B2()); t1.addActionListener(new T1A()); setLayout(new FlowLayout()); add(b1); add(b2); add(t1); add(t2); add(t3); }
/** * Constructor that takes model as a parameter * * @param model */ public BoardFrame(Model model) { this.model = model; data = model.getData(); gameOver = false; initScreen(); setLayout(new BorderLayout()); setLocation(300, 200); // undoBtn is a controller that resets the turn and last state of board undoBtn = new JButton("Undo : " + this.model.getUndoCounter()); undoBtn.setPreferredSize(new Dimension(80, 50)); undoBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (BoardFrame.this.model.getUndoCounter() != 0) { BoardFrame.this.model.undo(); undoBtn.setText("Undo : " + BoardFrame.this.model.getUndoCounter()); } else ; } }); JPanel undoPanel = new JPanel(); undoPanel.add(undoBtn); // end of undoBtn code add(boardPanel, BorderLayout.CENTER); add(undoPanel, BorderLayout.SOUTH); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); setResizable(false); setVisible(true); }
/** Initializes the call button. */ private void initCallButton() { List<ProtocolProviderService> telephonyProviders = CallManager.getTelephonyProviders(); if (telephonyProviders != null && telephonyProviders.size() > 0) { if (callButton.getParent() != null) return; callButton.setAlignmentX(JButton.CENTER_ALIGNMENT); callButton.setMnemonic( GuiActivator.getResources().getI18nMnemonic("service.gui.CALL_CONTACT")); buttonPanel.add(callButton); callButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String searchText = parentWindow.getCurrentSearchText(); if (searchText == null) return; CallManager.createCall(searchText, callButton); } }); } else { buttonPanel.remove(callButton); } }
/** Returns the tool bar for the panel. */ protected JComponent getToolBar() { JToolBar tbarDir = new JToolBar(); JButton btnNew = new JButton(); // m_btnSave = new JButton("Save File"); // i118n // btnNew.setText("New Label"); btnNew.setText(Util.getAdmLabel("_adm_New_Label")); btnNew.setActionCommand("new"); // m_btnSave.setActionCommand("save"); ActionListener alTool = new ActionListener() { public void actionPerformed(ActionEvent e) { doAction(e); } }; btnNew.addActionListener(alTool); // m_btnSave.addActionListener(alTool); tbarDir.setFloatable(false); tbarDir.add(btnNew); /*tbarDir.add(new JLabel(" ")); tbarDir.add(m_btnSave);*/ return tbarDir; }
// 定义添加一行格式化文本框的方法 private void addRow(String labelText, final JFormattedTextField field) { mainPanel.add(new JLabel(labelText)); mainPanel.add(field); final JLabel valueLabel = new JLabel(); mainPanel.add(valueLabel); // 为"确定"按钮添加事件监听器 // 当用户单击“确定”按钮时,文本框后显示文本框内的值 okButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { Object value = field.getValue(); // 如果该值是数组,使用Arrays的toString方法输出数组 if (value.getClass().isArray()) { StringBuilder builder = new StringBuilder(); builder.append('{'); for (int i = 0; i < Array.getLength(value); i++) { if (i > 0) builder.append(','); builder.append(Array.get(value, i).toString()); } builder.append('}'); valueLabel.setText(builder.toString()); } else { // 输出格式化文本框的值 valueLabel.setText(value.toString()); } } }); }
/** * Create a button to go inside of the toolbar. By default this will load an image resource. The * image filename is relative to the classpath (including the '.' directory if its a part of the * classpath), and may either be in a JAR file or a separate file. * * @param key The key in the resource file to serve as the basis of lookups. */ protected JButton createToolbarButton(String key) { URL url = getResource(key + imageSuffix); JButton b = new JButton(new ImageIcon(url)) { @Override public float getAlignmentY() { return 0.5f; } }; b.setRequestFocusEnabled(false); b.setMargin(new Insets(1, 1, 1, 1)); String astr = getProperty(key + actionSuffix); if (astr == null) { astr = key; } Action a = getAction(astr); if (a != null) { b.setActionCommand(astr); b.addActionListener(a); } else { b.setEnabled(false); } String tip = getResourceString(key + tipSuffix); if (tip != null) { b.setToolTipText(tip); } return b; }
private void addButton(JPanel container, Action action, Hashtable actions, Icon icon) { String actionName = (String) action.getValue(Action.NAME); String actionCommand = (String) action.getValue(Action.ACTION_COMMAND_KEY); JButton button = new JButton(icon); button.setActionCommand(actionCommand); button.addActionListener(DeepaMehtaClientUtils.getActionByName(actionName, actions)); container.add(button); toolbarButtons[buttonIndex++] = button; }
private JButton makeToolbarButton(String name, String toolTipText, String action) { // Create and initialize the button. JButton button = new JButton(makeImageIcon(name)); button.setToolTipText(toolTipText); button.setActionCommand(action); button.addActionListener(this); return button; }
protected JButton createRunButton() { JButton run = new JButton("Run"); run.setEnabled(true); run.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { runSuite(); } }); return run; }
// Method to build the dialog box for help. private void buildDialogBox() { // Set the JDialog window properties. setTitle("Stack Trace Detail"); setResizable(false); setSize(dialogWidth, dialogHeight); // Append the stack trace output to the display area. displayArea.append(eStackTrace); // Create horizontal and vertical scrollbars for box. displayBox = Box.createHorizontalBox(); displayBox = Box.createVerticalBox(); // Add a JScrollPane to the Box. displayBox.add(new JScrollPane(displayArea)); // Define behaviors of container. c.setLayout(null); c.add(displayBox); c.add(okButton); // Set scroll pane bounds. displayBox.setBounds( (dialogWidth / 2) - ((displayAreaWidth / 2) + 2), (top + (offsetMargin / 2)), displayAreaWidth, displayAreaHeight); // Set the behaviors, bounds and action listener for the button. okButton.setBounds( (dialogWidth / 2) - (buttonWidth / 2), (displayAreaHeight + offsetMargin), buttonWidth, buttonHeight); // Set the font to the platform default Font for the object with the // properties of bold and font size of 11. okButton.setFont(new Font(okButton.getFont().getName(), Font.BOLD, 11)); // The class implements the ActionListener interface and therefore // provides an implementation of the actionPerformed() method. When a // class implements ActionListener, the instance handler returns an // ActionListener. The ActionListener then performs actionPerformed() // method on an ActionEvent. okButton.addActionListener(this); // Set the screen and display dialog window in relation to screen size. setLocation((dim.width / 2) - (dialogWidth / 2), (dim.height / 2) - (dialogHeight / 2)); // Display JDialog. show(); } // End of buildDialogBox method.
protected void showFooter() { footerPanel = new JPanel(); submitButton = new JButton("Abschicken"); submitButton.setMnemonic(KeyEvent.VK_A); submitButton.addActionListener(this); submitButton.setEnabled(checkIfFormIsComplete()); footerPanel.add(submitButton); closeButton = new JButton("Schließen"); closeButton.setMnemonic(KeyEvent.VK_S); closeButton.addActionListener(this); closeButton.setEnabled(true); footerPanel.add(closeButton); allPanel.add(footerPanel); }
public FindSynonymsActionHandler(String word, int position, Chapter c, AbstractEditorPanel p) { this.word = word; this.position = position; // this.chapter = c; this.editorPanel = p; this.projectViewer = this.editorPanel.getViewer(); final FindSynonymsActionHandler _this = this; // Show a panel of all the items. this.popup = new QPopup( "Synonyms for: " + word, Environment.getIcon(Constants.FIND_ICON_NAME, Constants.ICON_POPUP), null); JButton close = UIUtils.createButton( Constants.CLOSE_ICON_NAME, Constants.ICON_MENU, "Click to close", null); List<JButton> buts = new ArrayList(); buts.add(close); this.popup.getHeader().setControls(UIUtils.createButtonBar(buts)); close.addActionListener( new ActionAdapter() { public void actionPerformed(ActionEvent ev) { _this.popup.setVisible(false); _this.editorPanel.getEditor().removeHighlight(_this.highlight); } }); p.addPopup(this.popup, true, true); /* this.highlight = this.editorPanel.getEditor ().addHighlight (position, position + word.length (), null, true); */ this.popup.setOpaque(false); this.popup.setVisible(false); this.popup.setDraggable(this.editorPanel); }
// Method to build the dialog box for help. private void buildDialogBox() { // Set the JDialog window properties. setTitle("Learning about Java"); setResizable(false); setSize(dialogWidth, dialogHeight); // Define behaviors of container. c.setLayout(null); c.setBackground(Color.cyan); c.add(image); c.add(okButton); // Set the bounds for the image. image.setBounds( (dialogWidth / 2) - (imageWidth / 2), (top + (offsetMargin / 2)), imageWidth, imageHeight); // Set the behaviors, bounds and action listener for the button. okButton.setBounds( (dialogWidth / 2) - (buttonWidth / 2), (imageHeight + (int) 1.5 * offsetMargin), buttonWidth, buttonHeight); // Set the font to the platform default Font for the object with the // properties of bold and font size of 11. okButton.setFont(new Font(okButton.getFont().getName(), Font.BOLD, 11)); // Set foreground and background of JButton(s). okButton.setForeground(Color.white); okButton.setBackground(Color.blue); // The class implements the ActionListener interface and therefore // provides an implementation of the actionPerformed() method. When a // class implements ActionListener, the instance handler returns an // ActionListener. The ActionListener then performs actionPerformed() // method on an ActionEvent. okButton.addActionListener(this); // Set the screen and display dialog window in relation to screen size. dim = tk.getScreenSize(); setLocation((dim.width / 2) - (dialogWidth / 2), (dim.height / 2) - (dialogHeight / 2)); // Display the dialog. show(); } // End of buildDialogBox method.
private void init() { setSize(800, 600); cp = getContentPane(); cp.setLayout(null); btnResize.addActionListener(this); btnResize.setLocation(0, 0); btnResize.setSize(100, 30); sp.setLocation(0, 31); sp.setBorder(BorderFactory.createLineBorder(Color.blue, 2)); editorPane.setBorder(BorderFactory.createLineBorder(Color.red, 2)); step.setLocation(0, 31); step.setSize(100, 100); cp.add(step); // cp.add(sp); cp.add(btnResize); }
private void initialise() { setSize(180, 120); setLocation(300, 200); setTitle("Working..."); setVisible(false); setModal(true); setResizable(false); setDefaultCloseOperation(0); _stopped = false; getContentPane().setLayout(new BorderLayout()); JPanel topPanel = new JPanel(); topPanel.setLayout(new BorderLayout()); busyTextLabel = new JLabel("Busy - please wait"); topPanel.add(busyTextLabel, "Center"); busyIcon = FTAUtilities.loadImageIcon("busy.gif"); busyIconLabel = new JLabel(busyIcon); topPanel.add(busyIconLabel, "West"); progressBar = new JProgressBar(); topPanel.add(progressBar, "South"); getContentPane().add(topPanel); stopButton = new JButton("Stop"); stopButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // System.out.println("'Stop' button pressed"); _stopped = true; } }); this.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { _stopped = true; } }); // create panel to hold buttons JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(stopButton); getContentPane().add(buttonPanel, BorderLayout.SOUTH); }
private void initAddContactButton() { addButton.setAlignmentX(JButton.CENTER_ALIGNMENT); addButton.setMnemonic(GuiActivator.getResources().getI18nMnemonic("service.gui.ADD_CONTACT")); buttonPanel.add(addButton); addButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { AddContactDialog dialog = new AddContactDialog(parentWindow); dialog.setContactAddress(parentWindow.getCurrentSearchText()); dialog.setVisible(true); } }); }
/** Initializes the call button. */ private void initSMSButton() { if (!parentWindow.hasOperationSet(OperationSetSmsMessaging.class)) return; smsButton = new JButton(GuiActivator.getResources().getI18NString("service.gui.SEND_SMS")); smsButton.setIcon(GuiActivator.getResources().getImage("service.gui.icons.SMS_BUTTON_ICON")); buttonPanel.add(smsButton); smsButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final String searchText = parentWindow.getCurrentSearchText(); if (searchText == null) return; SMSManager.sendSMS(smsButton, searchText); } }); }
/** * Adds a row to the main panel. * * @param labelText the label of the field * @param field the sample field */ public void addRow(String labelText, final JFormattedTextField field) { mainPanel.add(new JLabel(labelText)); mainPanel.add(field); final JLabel valueLabel = new JLabel(); mainPanel.add(valueLabel); okButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { Object value = field.getValue(); Class<?> cl = value.getClass(); String text = null; if (cl.isArray()) { if (cl.getComponentType().isPrimitive()) { try { text = Arrays.class.getMethod("toString", cl).invoke(null, value).toString(); } catch (ReflectiveOperationException ex) { // ignore reflection exceptions } } else text = Arrays.toString((Object[]) value); } else text = value.toString(); valueLabel.setText(text); } }); }
protected void buildErrorPanel() { errorPanel = new JPanel(); GroupLayout layout = new GroupLayout(errorPanel); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); errorPanel.setLayout(layout); // errorPanel.setBorder(BorderFactory.createMatteBorder(2, 0, 0, 0, Color.BLACK)); errorMessage = new JTextPane(); errorMessage.setEditable(false); errorMessage.setContentType("text/html"); errorMessage.setText( "<html><body>Could not connect to the Processing server.<br>" + "Contributions cannot be installed or updated without an Internet connection.<br>" + "Please verify your network connection again, then try connecting again.</body></html>"); errorMessage.setFont(Toolkit.getSansFont(14, Font.PLAIN)); errorMessage.setMaximumSize(new Dimension(550, 50)); errorMessage.setOpaque(false); StyledDocument doc = errorMessage.getStyledDocument(); SimpleAttributeSet center = new SimpleAttributeSet(); StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER); doc.setParagraphAttributes(0, doc.getLength(), center, false); closeButton = new JButton("X"); closeButton.setContentAreaFilled(false); closeButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { contribDialog.makeAndShowTab(false, false); } }); tryAgainButton = new JButton("Try Again"); tryAgainButton.setFont(Toolkit.getSansFont(14, Font.PLAIN)); tryAgainButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { contribDialog.makeAndShowTab(false, true); contribDialog.downloadAndUpdateContributionListing(editor.getBase()); } }); layout.setHorizontalGroup( layout .createSequentialGroup() .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.CENTER) .addComponent(errorMessage) .addComponent( tryAgainButton, StatusPanel.BUTTON_WIDTH, StatusPanel.BUTTON_WIDTH, StatusPanel.BUTTON_WIDTH)) .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addComponent(closeButton)); layout.setVerticalGroup( layout .createSequentialGroup() .addGroup( layout.createParallelGroup().addComponent(errorMessage).addComponent(closeButton)) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(tryAgainButton)); errorPanel.setBackground(Color.PINK); errorPanel.validate(); }
/** * Creates an instance of <tt>ShowPreviewDialog</tt> * * @param chatPanel The <tt>ChatConversationPanel</tt> that is associated with this dialog. */ ShowPreviewDialog(final ChatConversationPanel chatPanel) { this.chatPanel = chatPanel; this.setTitle( GuiActivator.getResources().getI18NString("service.gui.SHOW_PREVIEW_DIALOG_TITLE")); okButton = new JButton(GuiActivator.getResources().getI18NString("service.gui.OK")); cancelButton = new JButton(GuiActivator.getResources().getI18NString("service.gui.CANCEL")); JPanel mainPanel = new TransparentPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); // mainPanel.setPreferredSize(new Dimension(200, 150)); this.getContentPane().add(mainPanel); JTextPane descriptionMsg = new JTextPane(); descriptionMsg.setEditable(false); descriptionMsg.setOpaque(false); descriptionMsg.setText( GuiActivator.getResources().getI18NString("service.gui.SHOW_PREVIEW_WARNING_DESCRIPTION")); Icon warningIcon = null; try { warningIcon = new ImageIcon( ImageIO.read( GuiActivator.getResources().getImageURL("service.gui.icons.WARNING_ICON"))); } catch (IOException e) { logger.debug("failed to load the warning icon"); } JLabel warningSign = new JLabel(warningIcon); JPanel warningPanel = new TransparentPanel(); warningPanel.setLayout(new BoxLayout(warningPanel, BoxLayout.X_AXIS)); warningPanel.add(warningSign); warningPanel.add(Box.createHorizontalStrut(10)); warningPanel.add(descriptionMsg); enableReplacement = new JCheckBox( GuiActivator.getResources() .getI18NString("plugin.chatconfig.replacement.ENABLE_REPLACEMENT_STATUS")); enableReplacement.setOpaque(false); enableReplacement.setSelected(cfg.getBoolean(ReplacementProperty.REPLACEMENT_ENABLE, true)); enableReplacementProposal = new JCheckBox( GuiActivator.getResources() .getI18NString("plugin.chatconfig.replacement.ENABLE_REPLACEMENT_PROPOSAL")); enableReplacementProposal.setOpaque(false); JPanel checkBoxPanel = new TransparentPanel(); checkBoxPanel.setLayout(new BoxLayout(checkBoxPanel, BoxLayout.Y_AXIS)); checkBoxPanel.add(enableReplacement); checkBoxPanel.add(enableReplacementProposal); JPanel buttonsPanel = new TransparentPanel(new FlowLayout(FlowLayout.CENTER)); buttonsPanel.add(okButton); buttonsPanel.add(cancelButton); mainPanel.add(warningPanel); mainPanel.add(Box.createVerticalStrut(10)); mainPanel.add(checkBoxPanel); mainPanel.add(buttonsPanel); okButton.addActionListener(this); cancelButton.addActionListener(this); this.setPreferredSize(new Dimension(390, 230)); }
/** Constructor for the class, sets up two fresh tabbed text areas for program feedback. */ public MessagesPane() { super(); this.setMinimumSize(new Dimension(0, 0)); assemble = new JTextArea(); run = new JTextArea(); assemble.setEditable(false); run.setEditable(false); // Set both text areas to mono font. For assemble // pane, will make messages more readable. For run // pane, will allow properly aligned "text graphics" // DPS 15 Dec 2008 Font monoFont = new Font(Font.MONOSPACED, Font.PLAIN, 12); assemble.setFont(monoFont); run.setFont(monoFont); JButton assembleTabClearButton = new JButton("Clear"); assembleTabClearButton.setToolTipText("Clear the Mars Messages area"); assembleTabClearButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { assemble.setText(""); } }); assembleTab = new JPanel(new BorderLayout()); assembleTab.add(createBoxForButton(assembleTabClearButton), BorderLayout.WEST); assembleTab.add( new JScrollPane( assemble, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER); assemble.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { String text; int lineStart = 0; int lineEnd = 0; try { int line = assemble.getLineOfOffset(assemble.viewToModel(e.getPoint())); lineStart = assemble.getLineStartOffset(line); lineEnd = assemble.getLineEndOffset(line); text = assemble.getText(lineStart, lineEnd - lineStart); } catch (BadLocationException ble) { text = ""; } if (text.length() > 0) { // If error or warning, parse out the line and column number. if (text.startsWith(ErrorList.ERROR_MESSAGE_PREFIX) || text.startsWith(ErrorList.WARNING_MESSAGE_PREFIX)) { assemble.select(lineStart, lineEnd); assemble.setSelectionColor(Color.YELLOW); assemble.repaint(); int separatorPosition = text.indexOf(ErrorList.MESSAGE_SEPARATOR); if (separatorPosition >= 0) { text = text.substring(0, separatorPosition); } String[] stringTokens = text.split("\\s"); // tokenize with whitespace delimiter String lineToken = ErrorList.LINE_PREFIX.trim(); String columnToken = ErrorList.POSITION_PREFIX.trim(); String lineString = ""; String columnString = ""; for (int i = 0; i < stringTokens.length; i++) { if (stringTokens[i].equals(lineToken) && i < stringTokens.length - 1) lineString = stringTokens[i + 1]; if (stringTokens[i].equals(columnToken) && i < stringTokens.length - 1) columnString = stringTokens[i + 1]; } int line = 0; int column = 0; try { line = Integer.parseInt(lineString); } catch (NumberFormatException nfe) { line = 0; } try { column = Integer.parseInt(columnString); } catch (NumberFormatException nfe) { column = 0; } // everything between FILENAME_PREFIX and LINE_PREFIX is filename. int fileNameStart = text.indexOf(ErrorList.FILENAME_PREFIX) + ErrorList.FILENAME_PREFIX.length(); int fileNameEnd = text.indexOf(ErrorList.LINE_PREFIX); String fileName = ""; if (fileNameStart < fileNameEnd && fileNameStart >= ErrorList.FILENAME_PREFIX.length()) { fileName = text.substring(fileNameStart, fileNameEnd).trim(); } if (fileName != null && fileName.length() > 0) { selectEditorTextLine(fileName, line, column); selectErrorMessage(fileName, line, column); } } } } }); JButton runTabClearButton = new JButton("Clear"); runTabClearButton.setToolTipText("Clear the Run I/O area"); runTabClearButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { run.setText(""); } }); runTab = new JPanel(new BorderLayout()); runTab.add(createBoxForButton(runTabClearButton), BorderLayout.WEST); runTab.add( new JScrollPane( run, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER); this.addTab("Mars Messages", assembleTab); this.addTab("Run I/O", runTab); this.setToolTipTextAt( 0, "Messages produced by Run menu. Click on assemble error message to select erroneous line"); this.setToolTipTextAt(1, "Simulated MIPS console input and output"); }
/** 程式的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); }
@Override public void actionPerformed(ActionEvent e) { licence_text = new String( "This program is free software: you can redistribute it and/or modify\n" + "it under the terms of the GNU General Public License as published by\n" + "the Free Software Foundation, either version 3 of the License, or\n" + "(at your option) any later version.\n" + "\n" + "This program is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details.\n" + "\n" + "You should have received a copy of the GNU General Public License\n" + "along with this program. If not, see <http://www.gnu.org/licenses/>.\n" + "\n\n\n"); try { InputStream ips = new FileInputStream(getClass().getResource("COPYING").getPath()); InputStreamReader ipsr = new InputStreamReader(ips); BufferedReader br = new BufferedReader(ipsr); String line; while ((line = br.readLine()) != null) { licence_text += line + '\n'; } br.close(); } catch (Exception e1) { } Dimension dimension = new Dimension(600, 400); JDialog licence = new JDialog(memento, "Licence"); JTextPane text_pane = new JTextPane(); text_pane.setEditable(false); text_pane.setPreferredSize(dimension); text_pane.setSize(dimension); StyledDocument doc = text_pane.getStyledDocument(); Style justified = doc.addStyle( "justified", StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE)); StyleConstants.setAlignment(justified, StyleConstants.ALIGN_JUSTIFIED); try { doc.insertString(0, licence_text, justified); } catch (BadLocationException ble) { System.err.println("Couldn't insert initial text into text pane."); } Style logicalStyle = doc.getLogicalStyle(0); doc.setParagraphAttributes(0, licence_text.length(), justified, false); doc.setLogicalStyle(0, logicalStyle); JScrollPane paneScrollPane = new JScrollPane(text_pane); paneScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); paneScrollPane.setPreferredSize(dimension); paneScrollPane.setMinimumSize(dimension); JPanel pan = new JPanel(); LayoutManager layout = new BorderLayout(); pan.setLayout(layout); pan.add(new JScrollPane(paneScrollPane), BorderLayout.CENTER); JButton close = new JButton("Fermer"); close.addActionListener(new ButtonCloseActionListener(licence)); JPanel button_panel = new JPanel(); FlowLayout button_panel_layout = new FlowLayout(FlowLayout.RIGHT, 20, 20); button_panel.setLayout(button_panel_layout); button_panel.add(close); pan.add(button_panel, BorderLayout.SOUTH); licence.add(pan); licence.pack(); licence.setLocationRelativeTo(memento); licence.setVisible(true); }
public MakeReservation() { new BorderLayout(); standardRoom.setMnemonic(KeyEvent.VK_K); standardRoom.setActionCommand("Standard Room"); standardRoom.setSelected(true); familyRoom.setMnemonic(KeyEvent.VK_F); familyRoom.setActionCommand("Family Room"); suiteRoom.setMnemonic(KeyEvent.VK_S); suiteRoom.setActionCommand("Suite"); // Add Booking Button ImageIcon bookRoomIcon = createImageIcon("images/book.png"); bookRoom = new JButton("Book Room", bookRoomIcon); bookRoom.setVerticalTextPosition(AbstractButton.BOTTOM); bookRoom.setHorizontalTextPosition(AbstractButton.CENTER); bookRoom.setMnemonic(KeyEvent.VK_M); bookRoom.addActionListener(this); bookRoom.setActionCommand("book"); // Group the radio buttons. group.add(standardRoom); group.add(familyRoom); group.add(suiteRoom); // Create the labels. nameLabel = new JLabel("Name: "); amountroomsLabel = new JLabel("How many rooms? "); checkoutdateLabel = new JLabel("Check-Out Date: "); checkindateLabel = new JLabel("Check-In Date: "); // Create the text fields and set them up. nameField = new JFormattedTextField(); nameField.setColumns(10); amountroomsField = new JFormattedTextField(new Integer(1)); amountroomsField.setValue(new Integer(1)); amountroomsField.setColumns(10); // java.util.Date dt_checkin = new java.util.Date(); LocalDate today = LocalDate.now(); // java.text.SimpleDateFormat sdf_checkin = new java.text.SimpleDateFormat("MM/dd/yyyy"); currentDate_checkin = today.toString(); checkindateField = new JFormattedTextField(currentDate_checkin); checkindateField.setColumns(10); // java.util.Date dt_checkout = new java.util.Date(); LocalDate tomorrow = today.plus(1, ChronoUnit.DAYS); // java.text.SimpleDateFormat sdf_checkout = new java.text.SimpleDateFormat("MM/dd/yyyy"); currentDate_checkout = tomorrow.toString(); checkoutdateField = new JFormattedTextField(currentDate_checkout); checkoutdateField.setColumns(10); // Tell accessibility tools about label/textfield pairs. nameLabel.setLabelFor(nameField); amountroomsLabel.setLabelFor(amountroomsField); checkoutdateLabel.setLabelFor(checkoutdateField); checkindateLabel.setLabelFor(checkindateField); // Lay out the labels in a panel. JPanel labelPane1 = new JPanel(new GridLayout(0, 1)); labelPane1.add(amountroomsLabel); JPanel labelPane3 = new JPanel(new GridLayout(0, 1)); labelPane3.add(checkindateLabel); JPanel labelPane2 = new JPanel(new GridLayout(0, 1)); labelPane2.add(checkoutdateLabel); JPanel labelPane4 = new JPanel(new GridLayout(0, 1)); labelPane4.add(nameLabel); // Layout the text fields in a panel. JPanel fieldPane1 = new JPanel(new GridLayout(0, 1)); fieldPane1.add(amountroomsField); JPanel fieldPane3 = new JPanel(new GridLayout(0, 1)); fieldPane3.add(checkindateField); JPanel fieldPane2 = new JPanel(new GridLayout(0, 1)); fieldPane2.add(checkoutdateField); JPanel fieldPane4 = new JPanel(new GridLayout(0, 1)); fieldPane4.add(nameField); // Put the radio buttons in a column in a panel. JPanel radioPanel = new JPanel(new GridLayout(0, 1)); radioPanel.add(standardRoom); radioPanel.add(familyRoom); radioPanel.add(suiteRoom); // Put the panels in this panel, labels on left, // text fields on right. setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); add(labelPane1, BorderLayout.LINE_START); add(fieldPane1, BorderLayout.LINE_END); add(labelPane3, BorderLayout.LINE_START); add(fieldPane3, BorderLayout.LINE_END); add(labelPane2, BorderLayout.LINE_START); add(fieldPane2, BorderLayout.LINE_END); add(labelPane4, BorderLayout.LINE_START); add(fieldPane4, BorderLayout.LINE_END); add(radioPanel, BorderLayout.LINE_END); add(bookRoom); }
public NewUser() { super("Adding New User"); label1 = new JLabel("Name"); label2 = new JLabel("Category"); username = new JLabel("Username"); password = new JLabel("Password"); confirm = new JLabel("Re-enter Password"); pass1 = new JPasswordField(); pass2 = new JPasswordField(); txtusername = new JTextField(); name = new JTextField(); combo1 = new JComboBox(); button1 = new JButton("Ok", new ImageIcon("Icon/i16x16/ok.png")); button2 = new JButton("Cancel", new ImageIcon("Icon/i16x16/exit.png")); panel1 = new JPanel(new GridLayout(6, 2)); panel1.add(label1); panel1.add(name); panel1.add(label2); panel1.add(combo1); panel1.add(username); panel1.add(txtusername); panel1.add(password); panel1.add(pass1); panel1.add(confirm); panel1.add(pass2); panel1.add(button1); panel1.add(button2); combo1.addItem("Manager"); combo1.addItem("Booking Clerk"); combo1.addItem("Supervisor"); panel2 = new JPanel(); panel2.add(panel1); getContentPane().add(panel2); setSize(350, 195); setVisible(true); setLocation((screen.width - 500) / 2, ((screen.height - 350) / 2)); setResizable(false); name.addKeyListener( new KeyAdapter() { public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); if (!(Character.isLetter(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_SPACE) || (c == KeyEvent.VK_DELETE))) { getToolkit().beep(); JOptionPane.showMessageDialog( null, "Invalid Character", "ERROR", JOptionPane.DEFAULT_OPTION); e.consume(); } } }); txtusername.addKeyListener( new KeyAdapter() { public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); if (!(Character.isLetter(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_SPACE) || (c == KeyEvent.VK_DELETE))) { getToolkit().beep(); JOptionPane.showMessageDialog( null, "Invalid Character", "ERROR", JOptionPane.DEFAULT_OPTION); e.consume(); } } }); button1.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { if (name.getText() == null || name.getText().equals("")) { JOptionPane.showMessageDialog( null, "Enter name", "ERROR", JOptionPane.DEFAULT_OPTION); name.requestFocus(); return; } if (txtusername.getText() == null || txtusername.getText().equals("")) { JOptionPane.showMessageDialog( null, "Enter username", "ERROR", JOptionPane.DEFAULT_OPTION); txtusername.requestFocus(); return; } if (pass1.getText() == null || pass1.getText().equals("")) { JOptionPane.showMessageDialog( null, "Enter password", "ERROR", JOptionPane.DEFAULT_OPTION); pass1.requestFocus(); return; } if (pass2.getText() == null || pass2.getText().equals("")) { JOptionPane.showMessageDialog( null, "Confirm your password", "ERROR", JOptionPane.DEFAULT_OPTION); pass2.requestFocus(); return; } if (!pass1.getText().equals(pass2.getText())) { JOptionPane.showMessageDialog( null, "passwords do not match.", "ERROR", JOptionPane.DEFAULT_OPTION); pass2.requestFocus(); return; } try { Statement statement = Connect.getConnection().createStatement(); { String temp = "INSERT INTO users (Name,Category,username, password) VALUES ('" + name.getText() + "', '" + combo1.getSelectedItem() + "', '" + txtusername.getText() + "', '" + pass1.getText() + "')"; int result = statement.executeUpdate(temp); JOptionPane.showMessageDialog( null, "User is succesfully added", "SUCCESS", JOptionPane.DEFAULT_OPTION); dispose(); } } catch (Exception in) { in.printStackTrace(); } } }); button2.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); }
// Method builds button action listeners. private void buildButtonActionListeners() { /* || Section adds action listeners for buttons: || ========================================== || - sendButton || - receiveButton || - JDBCButton || - fileButton || - rSendButton || - rReceiveButton */ // Send button. sendButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // Send message. setMessage(sender, receiver); } // End of actionPerformed() method. }); // End of sendButton action listener. // Receive button. receiveButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // Receive message. getMessage(receiver); } // End of actionPerformed() method. }); // End of receiveButton action listener. // JDBC button. JDBCButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // Print message until implemented. System.out.println("Database Connection .... "); } // End of actionPerformed() method. }); // End of JDBCButton action listener. // File button. fileButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // Print message until implemented. System.out.println("SQL Submission .... "); } // End of actionPerformed() method. }); // End of fileButton action listener. // Send button. rSendButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // Print message until implemented. System.out.println("Remote Sending .... "); } // End of actionPerformed() method. }); // End of rSendButton action listener. // Receive button. rReceiveButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // Print message until implemented. System.out.println("Remote Receiving .... "); } // End of actionPerformed() method. }); // End of rReceiveButton action listener. } // End of buildButtonActionListeners() method.