void initControls() { JMenuItem jmi; jmi = new JMenuItem("JImage Menu"); jmi.setEnabled(false); popupMenu.add(jmi); jmi = new JMenuItem("Fit"); jmi.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { fit = true; repaint(); } }); popupMenu.add(jmi); JMenu scaleMenu = new JMenu("Set Scale"); popupMenu.add(scaleMenu); int scales[] = new int[] {25, 50, 100, 200, 400, 800}; for (int i = 0; i < scales.length; i++) { jmi = new JMenuItem(scales[i] + " %"); jmi.addActionListener(new ScaleAction(scales[i])); scaleMenu.add(jmi); } MyListener l = new MyListener(); addMouseMotionListener(l); addMouseListener(l); addMouseWheelListener(l); addKeyListener(l); }
protected JMenu makeFileMenu() { JMenu fileMenu = new JMenu("File"); fileMenu.add( new AbstractAction("Open/Count") { public void actionPerformed(ActionEvent ev) { doRead(); } }); fileMenu.add( new AbstractAction("Compress") { public void actionPerformed(ActionEvent ev) { doSave(); } }); fileMenu.add( new AbstractAction("Uncompress") { public void actionPerformed(ActionEvent ev) { doDecode(); } }); fileMenu.add( new AbstractAction("Quit") { public void actionPerformed(ActionEvent ev) { System.exit(0); } }); return fileMenu; }
/* constructor * Create a frame with JTextArea and a menubar * with a "File" dropdown menu. * * @param title: the title for the frame * @param whichFile: to indicate which load or save buuton */ public OpenFileDir(String title, String whichFile) { super(title); fileNo = whichFile; Container content_pane = getContentPane(); // Create a user interface. content_pane.setLayout(new BorderLayout()); // Use the helper method makeMenuItem // for making the menu items and registering // their listener. JMenu m = new JMenu("File"); // Modify task names to something relevant to // the particular program. m.add(fMenuLoad = makeMenuItem("Load")); m.add(fMenuSave = makeMenuItem("Save")); m.add(fMenuClose = makeMenuItem("Quit")); JMenuBar mb = new JMenuBar(); mb.add(m); setJMenuBar(mb); setSize(400, 200); } /* end of the constructor */
protected JMenu buildFileMenu() { JMenu file = new JMenu("File"); JMenuItem newWin = new JMenuItem("New"); JMenuItem open = new JMenuItem("Open"); JMenuItem quit = new JMenuItem("Quit"); newWin.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { newDocument(); } }); open.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { openDocument(); } }); quit.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { quit(); } }); file.add(newWin); file.add(open); file.addSeparator(); file.add(quit); return file; }
@Override public JPopupMenu getComponentPopupMenu() { if (popupMenu == null) { popupMenu = new JPopupMenu(Messages.CHART_COLON); timeRangeMenu = new JMenu(Messages.PLOTTER_TIME_RANGE_MENU); timeRangeMenu.setMnemonic(Resources.getMnemonicInt(Messages.PLOTTER_TIME_RANGE_MENU)); popupMenu.add(timeRangeMenu); menuRBs = new JRadioButtonMenuItem[rangeNames.length]; ButtonGroup rbGroup = new ButtonGroup(); for (int i = 0; i < rangeNames.length; i++) { menuRBs[i] = new JRadioButtonMenuItem(rangeNames[i]); rbGroup.add(menuRBs[i]); menuRBs[i].addActionListener(this); if (viewRange == rangeValues[i]) { menuRBs[i].setSelected(true); } timeRangeMenu.add(menuRBs[i]); } popupMenu.addSeparator(); saveAsMI = new JMenuItem(Messages.PLOTTER_SAVE_AS_MENU_ITEM); saveAsMI.setMnemonic(Resources.getMnemonicInt(Messages.PLOTTER_SAVE_AS_MENU_ITEM)); saveAsMI.addActionListener(this); popupMenu.add(saveAsMI); } return popupMenu; }
private JMenu addMenu( JMenuBar menuBar, String label, int mnemonic, String accessibleDescription) { JMenu menu = new JMenu(label); menu.setMnemonic(mnemonic); menu.getAccessibleContext().setAccessibleDescription(accessibleDescription); menuBar.add(menu); return menu; }
public static JMenu createLookAndFeelMenu() { JMenu menu = new JMenu("LookAndFeel"); ButtonGroup lookAndFeelRadioGroup = new ButtonGroup(); for (UIManager.LookAndFeelInfo lafInfo : UIManager.getInstalledLookAndFeels()) { menu.add( createLookAndFeelItem(lafInfo.getName(), lafInfo.getClassName(), lookAndFeelRadioGroup)); } return menu; }
private void creerMenu() { menuBar = new JMenuBar(); menuOption.add(menuNouvellePartie); menuOption.add(menuScore); menuBar.add(menuOption); menuBar.add(pause); menuBar.add(hint); setJMenuBar(menuBar); }
// create the menu bar (changed to private) private static JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); menuBar.add(menu); JMenuItem saveItem = new JMenuItem(" Save... "); saveItem.addActionListener(std); saveItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); menu.add(saveItem); return menuBar; }
public TestFileDialog() { JMenu menu = new JMenu("File"); JMenuItem openMI = new JMenuItem("Open"); JMenuItem saveMI = new JMenuItem("Save"); menu.add(openMI); menu.add(saveMI); JMenuBar bar = new JMenuBar(); bar.add(menu); setJMenuBar(bar); openMI.addActionListener(new OpenListener()); saveMI.addActionListener(new SaveListener()); }
/** * Create a menu for the app. By default this pulls the definition of the menu from the associated * resource file. */ protected JMenu createMenu(String key) { JMenu menu = new JMenu(getResourceString(key + labelSuffix)); for (String itemKey : getItemKeys(key)) { if (itemKey.equals("-")) { menu.addSeparator(); } else { JMenuItem mi = createMenuItem(itemKey); menu.add(mi); } } return menu; }
// set all menu items related to debugging enabled, all else disabled; // for insert, remove and fetch: continue, step // additionally for scripts: next and sometimes cancel private void enableDebug(boolean isScript, boolean enableCancel) { setAllEnabled(false); debugMenu.setEnabled(true); stepAction.setEnabled(true); cancelAction.setEnabled(enableCancel); nextAction.setEnabled(isScript); contAction.setEnabled(true); breakpointsItem.setEnabled(true); treeStatsMenu.setEnabled(true); utilItem.setEnabled(true); predSzItem.setEnabled(true); slotCntItem.setEnabled(true); }
/* * Creates the JMenuBar for the GUI. */ private JMenuBar menuBar() { menuBar = new JMenuBar(); menu = new JMenu("Menu"); load = new JMenuItem("Load..."); saveAs = new JMenuItem("Save As..."); load.addActionListener(new ActionListenerLoad()); saveAs.addActionListener(new ActionListenerSave()); // responseArea.addActionListener(new ActionListenerArea()); menu.add(load); menu.add(saveAs); menuBar.add(menu); return menuBar; }
/** * Create a menu for the app. By default this pulls the definition of the menu from the associated * resource file. */ protected JMenu createMenu(String key) { String[] itemKeys = SCSUtility.tokenize(getResourceString(key)); JMenu menu = new JMenu(getResourceString(key + "Label")); for (int i = 0; i < itemKeys.length; i++) { if (itemKeys[i].equals("-")) { menu.addSeparator(); } else { // System.out.println("Debug:TextViewer:itemkey: "+itemKeys[i]); JMenuItem mi = createMenuItem(itemKeys[i]); menu.add(mi); } } return menu; }
protected JMenu buildEditMenu() { JMenu edit = new JMenu("Edit"); JMenuItem undo = new JMenuItem("Undo"); JMenuItem copy = new JMenuItem("Copy"); JMenuItem cut = new JMenuItem("Cut"); JMenuItem paste = new JMenuItem("Paste"); JMenuItem prefs = new JMenuItem("Preferences..."); undo.setEnabled(false); copy.setEnabled(false); cut.setEnabled(false); paste.setEnabled(false); prefs.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { openPrefsWindow(); } }); edit.add(undo); edit.addSeparator(); edit.add(cut); edit.add(copy); edit.add(paste); edit.addSeparator(); edit.add(prefs); return edit; }
private void createJMenuBar() { menubar = new JMenuBar(); JMenu menu = null; JMenuItem item = null; menubar.add(menu = new JMenu("Edit")); menu.add(item = new JMenuItem("Edit Object...")); item.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { browser.editSelected(); } }); }
private void addMenuItem( JMenu menu, String label, int mnemonic, String accessibleDescription, String actionCallbackName) throws NoSuchMethodException { JMenuItem menuItem = new JMenuItem(label, mnemonic); menuItem .getAccessibleContext() .setAccessibleDescription((accessibleDescription != null) ? accessibleDescription : label); final Method callback = getClass().getMethod(actionCallbackName, new Class[] {ActionEvent.class}); menuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { callback.invoke(WordListScreen.this, new Object[] {e}); } catch (InvocationTargetException ex) { handleException(ex.getTargetException()); } catch (IllegalAccessException ex) { handleException(ex); } } }); menu.add(menuItem); }
// Method to open a file for sequential read-only. private void openFile() { // Define local primitive(s). String contents = new String(); // If a file is open, prompt to save the file before dismissing content // and reference. if (!file.toString().equals("")) { // Close the existing file. closeFile(); } // End of if file not null or not equal to a zero String. // Open a file. fileName = FileIO.findFile(this); // If a file name is returned. if (fileName != null) { // Read file. contents = FileIO.openFile(this, fileName); // Verify that the JTextAreaPanel is empty. if (sender.isTextAreaEmpty()) { // Set JTextAreaPanel. sender.setText(contents); } // End of if JTextAreaPanel is empty. else { // Reset JTextAreaPanel by replacing the range. sender.replaceRange(contents, 0, sender.getText().length()); } // End of else JTextAreaPanel is not empty. // Set file open flag to true. fileOpen = true; } // End of if a fileName is selected. } // End of openFile method.
private void addProfiles(JMenu menu, String[] profileNames, ActionListener listener) { for (int i = 0; i < profileNames.length; i++) { JMenuItem item = new JMenuItem(profileNames[i]); item.addActionListener(listener); menu.add(item); } }
public void populateMenu(JMenu menu, int flags) { if (flags == (Plugin.MENU_TOOLS | Plugin.MENU_MID)) { Sketch sketch = editor.getSketch(); JMenuItem item = new JMenu("Program Bootloader"); item.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { run(); } }); menu.add(item); PropertyFile props = sketch.mergeAllProperties(); String blProgs = props.get("bootloader.upload"); if (blProgs == null) { JMenuItem sub = new JMenuItem("No bootloader programmer defined!"); item.add(sub); return; } String[] progs = blProgs.split("::"); for (String prog : progs) { JMenuItem sub = new JMenuItem(sketch.parseString(props.get("upload." + prog + ".name"))); sub.setActionCommand(prog); sub.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doProgram(e.getActionCommand()); } }); item.add(sub); } } }
public void refreshSerialPortList() { String[] serialPortList = SerialPortList.getPortNames(); portMenu.removeAll(); portMenu.add(refreshItem); JMenuItem menuItem; for (String serialPort : serialPortList) { menuItem = new JMenuItem(serialPort); menuItem.addActionListener(e -> onSerialPortClicked(e.getActionCommand())); portMenu.add(menuItem); } }
protected JMenu buildSpeedMenu() { JMenu speed = new JMenu("Drag"); JRadioButtonMenuItem live = new JRadioButtonMenuItem("Live"); JRadioButtonMenuItem outline = new JRadioButtonMenuItem("Outline"); JRadioButtonMenuItem slow = new JRadioButtonMenuItem("Old and Slow"); ButtonGroup group = new ButtonGroup(); group.add(live); group.add(outline); group.add(slow); live.setSelected(true); slow.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // for right now I'm saying if you set the mode // to something other than a specified mode // it will revert to the old way // This is mostly for comparison's sake desktop.setDragMode(-1); } }); live.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { desktop.setDragMode(JDesktopPane.LIVE_DRAG_MODE); } }); outline.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); } }); speed.add(live); speed.add(outline); speed.add(slow); return speed; }
public SwingWorkerFrame() { chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); textArea = new JTextArea(TEXT_ROWS, TEXT_COLUMNS); add(new JScrollPane(textArea)); statusLine = new JLabel(" "); add(statusLine, BorderLayout.SOUTH); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu menu = new JMenu("File"); menuBar.add(menu); openItem = new JMenuItem("Open"); menu.add(openItem); openItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { // show file chooser dialog int result = chooser.showOpenDialog(null); // if file selected, set it as icon of the label if (result == JFileChooser.APPROVE_OPTION) { textArea.setText(""); openItem.setEnabled(false); textReader = new TextReader(chooser.getSelectedFile()); textReader.execute(); cancelItem.setEnabled(true); } } }); cancelItem = new JMenuItem("Cancel"); menu.add(cancelItem); cancelItem.setEnabled(false); cancelItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { textReader.cancel(true); } }); pack(); }
private void buildMenu() { jMenuBar = new javax.swing.JMenuBar(); mainMenu = new javax.swing.JMenu(); mainMenu.setText("Main"); loginMenuItem = new JMenuItem("Login..."); loginMenuItem.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { headerPanel.handleLoginLogout(); } }); mainMenu.add(loginMenuItem); exitMenuItem = new JMenuItem("Exit"); exitMenuItem.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { if (qsadminMain.isConnected() == true) { headerPanel.handleLoginLogout(); } System.exit(0); } }); mainMenu.add(exitMenuItem); helpMenu = new javax.swing.JMenu(); helpMenu.setText("Help"); aboutMenuItem = new JMenuItem("About..."); aboutMenuItem.setEnabled(true); aboutMenuItem.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { about(); } }); helpMenu.add(aboutMenuItem); jMenuBar.add(mainMenu); jMenuBar.add(helpMenu); parentFrame.setJMenuBar(jMenuBar); }
protected JMenu buildViewsMenu() { JMenu views = new JMenu("Views"); JMenuItem inBox = new JMenuItem("Open In-Box"); JMenuItem outBox = new JMenuItem("Open Out-Box"); outBox.setEnabled(false); inBox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { openInBox(); } }); views.add(inBox); views.add(outBox); return views; }
public void actionPerformed(ActionEvent ev) { JComponent src = (JComponent) ev.getSource(); if (src == saveAsMI) { saveAs(); } else { int index = timeRangeMenu.getPopupMenu().getComponentIndex(src); setViewRange(rangeValues[index]); } }
/** * Creates the attributes menu and its submenus. Clients override this method to add additional * menu items. */ protected JMenu createAttributesMenu() { JMenu menu = new JMenu("Attributes"); menu.add(createColorMenu("Fill Color", "FillColor")); menu.add(createColorMenu("Pen Color", "FrameColor")); menu.add(createArrowMenu()); menu.addSeparator(); menu.add(createFontMenu()); menu.add(createFontSizeMenu()); menu.add(createFontStyleMenu()); menu.add(createColorMenu("Text Color", "TextColor")); return menu; }
public ShowComp() throws InterruptedException, IOException { super("CONNECTED COMPUTERS"); int x = 0, d = 20; mb = new JMenuBar(); File = new JMenu("File"); mb.add(File); exit = new JMenuItem("Exit"); exit.addActionListener(this); File.add(exit); ta = new JTextArea(); ta.setBounds(20, 30, 315, 470); ta.setEditable(false); add(ta); setJMenuBar(mb); sel = new JLabel("The connected computers are.."); sel.setBounds(15, 5, 300, 30); add(sel); b1 = new JButton("<< BACK"); b1.setBounds(140, 510, 100, 30); b1.setToolTipText("Back to main page"); b1.addActionListener(this); add(b1); setLayout(null); while (x < 360) { x = x + d; setBounds(675, 50, x, 600); this.show(); } // setVisible(true); String s = "192.168.0.", temp = null; Printer printer = new Printer(); printer.start(); Connector connector = new Connector(printer); connector.start(); LinkedList targets = new LinkedList(); for (int i = 1; i <= 255; i++) { temp = s + Integer.toString(i); Target t = new Target(temp); targets.add(t); connector.add(t); } Thread.sleep(2000); connector.shutdown(); connector.join(); for (Iterator i = targets.iterator(); i.hasNext(); ) { Target t = (Target) i.next(); if (!t.shown) t.show(); } setDefaultCloseOperation(DISPOSE_ON_CLOSE); }
public void go() { frame = new JFrame("Quiz Card Player"); JPanel mainPanel = new JPanel(); Font bigFont = new Font("sanserif", Font.BOLD, 24); display = new JTextArea(10, 20); display.setFont(bigFont); display.setLineWrap(true); display.setEditable(false); JScrollPane qScroller = new JScrollPane(display); qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); nextButton = new JButton("Show Questions"); nextButton.addActionListener(new NextCardListener()); mainPanel.add(qScroller); mainPanel.add(nextButton); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenuItem loadMenuItem = new JMenuItem("Load Card Set"); loadMenuItem.addActionListener(new OpenMenuListener()); fileMenu.add(loadMenuItem); menuBar.add(fileMenu); frame.setJMenuBar(menuBar); frame.getContentPane().add(BorderLayout.CENTER, mainPanel); frame.setSize(640, 500); frame.setVisible(true); }
public void go() { // build gui frame = new JFrame("Quiz Card Buider"); JPanel mainPanel = new JPanel(); Font bigFont = new Font("sanserif", Font.BOLD, 24); question = new JTextArea(6, 20); question.setLineWrap(true); question.setWrapStyleWord(true); question.setFont(bigFont); JScrollPane qScroller = new JScrollPane(question); qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); answer = new JTextArea(6, 20); answer.setLineWrap(true); answer.setWrapStyleWord(true); answer.setFont(bigFont); JScrollPane aScroller = new JScrollPane(question); aScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); aScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); JButton nextButton = new JButton("Next Card"); cardList = new ArrayList<QuizCard>(); JLabel qLabel = new JLabel("Question"); JLabel aLabel = new JLabel("Answer"); mainPanel.add(qLabel); mainPanel.add(qScroller); mainPanel.add(aLabel); mainPanel.add(aScroller); mainPanel.add(nextButton); nextButton.addActionListener(new NextCardListener()); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenuItem newMenuItem = new JMenuItem("New"); JMenuItem saveMenuItem = new JMenuItem("Save"); newMenuItem.addActionListener(new NewMenuListener()); saveMenuItem.addActionListener(new SaveMenuListener()); fileMenu.add(newMenuItem); fileMenu.add(saveMenuItem); menuBar.add(fileMenu); frame.setJMenuBar(menuBar); frame.getContentPane().add(BorderLayout.CENTER, mainPanel); frame.setSize(500, 600); frame.setVisible(true); // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }