public DistributedTextEditor() { area1.setFont(new Font("Monospaced", Font.PLAIN, 12)); area2.setFont(new Font("Monospaced", Font.PLAIN, 12)); ((AbstractDocument) area1.getDocument()).setDocumentFilter(dec); area2.setEditable(false); Container content = getContentPane(); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); JScrollPane scroll1 = new JScrollPane( area1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); content.add(scroll1, BorderLayout.CENTER); JScrollPane scroll2 = new JScrollPane( area2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); content.add(scroll2, BorderLayout.CENTER); content.add(ipaddress, BorderLayout.CENTER); content.add(portNumber, BorderLayout.CENTER); JMenuBar JMB = new JMenuBar(); setJMenuBar(JMB); JMenu file = new JMenu("File"); JMenu edit = new JMenu("Edit"); JMB.add(file); JMB.add(edit); file.add(Listen); file.add(Connect); file.add(Disconnect); file.addSeparator(); file.add(Save); file.add(SaveAs); file.add(Quit); edit.add(Copy); edit.add(Paste); edit.getItem(0).setText("Copy"); edit.getItem(1).setText("Paste"); Save.setEnabled(false); SaveAs.setEnabled(false); Disconnect.setEnabled(false); setDefaultCloseOperation(EXIT_ON_CLOSE); pack(); area1.addKeyListener(k1); area1.addMouseListener(m1); setTitle("Disconnected"); setVisible(true); area1.insert("Welcome to Hjortehandlerne's distributed text editor. \n", 0); this.addWindowListener(w1); }
private JMenuBar buildMenuBar() { // This function builds the menu bar JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); fileMenu.add(makeMenuItem("New")); fileMenu.add(makeMenuItem("Open")); fileMenu.addSeparator(); fileMenu.add(makeMenuItem("Save")); fileMenu.add(makeMenuItem("Save As")); fileMenu.addSeparator(); fileMenu.add(makeMenuItem("Exit")); menuBar.add(fileMenu); // edit menu JMenu editMenu = new JMenu("Edit"); editMenu.add(makeMenuItem(cutAction)); editMenu.add(makeMenuItem(copyAction)); editMenu.add(makeMenuItem(pasteAction)); menuBar.add(editMenu); 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) { 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; }
/** * 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; }
// Method builds menu components. private JMenuBar buildMenu() { // Add menus to the menu bar. menuBar.add(file); menuBar.add(comm); menuBar.add(data); menuBar.add(help); // Set mnemonics for menu selections. file.setMnemonic('F'); comm.setMnemonic('C'); data.setMnemonic('D'); help.setMnemonic('H'); // Menu items for file menu. file.add(menuItemNew); file.addSeparator(); file.add(menuItemOpen); file.add(menuItemClose); file.addSeparator(); file.add(menuItemSave); file.add(menuItemSaveAs); file.addSeparator(); file.add(menuItemExit); // Menu items for comm menu. comm.add(menuItemSend); comm.add(menuItemReceive); // Menu items for comm menu. data.add(menuItemConnect); data.add(menuItemSubmit); // Set mnemonics for menu item selections for file menu. menuItemNew.setMnemonic('N'); menuItemOpen.setMnemonic('O'); menuItemClose.setMnemonic('C'); menuItemSave.setMnemonic('S'); menuItemSaveAs.setMnemonic('A'); menuItemExit.setMnemonic('X'); // Set mnemonics for comm item selections for file menu. menuItemSend.setMnemonic('S'); menuItemReceive.setMnemonic('R'); // Set mnemonics for data item selections for file menu. menuItemConnect.setMnemonic('C'); menuItemSubmit.setMnemonic('R'); // Menu items to help menu. help.add(menuCheckBoxItemDebug); help.addSeparator(); help.add(menuItemHelp); // Set mnemonics for menu item selections for edit menu. menuCheckBoxItemDebug.setMnemonic('D'); menuItemHelp.setMnemonic('A'); // Build menu action listeners. buildMenuActionListeners(); // Set the menu bar in the frame and return menu bar. setJMenuBar(menuBar); // Return JMenuBar return menuBar; } // End of buildMenu() method.
/** Constructor to create the frame and its components */ public CoreyTextEditor() { // Create a scroll pane area.setFont(new Font("Monospaced", Font.PLAIN, 12)); JScrollPane scroll = new JScrollPane( area, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); add(scroll, BorderLayout.CENTER); // Adds the system default look and feel try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | UnsupportedLookAndFeelException | IllegalAccessException e) { e.printStackTrace(); } // Create a menu bar JMenuBar JMB = new JMenuBar(); setJMenuBar(JMB); JMenu file = new JMenu("File"); JMenu edit = new JMenu("Edit"); JMB.add(file); JMB.add(edit); // Finishing our menu bar file.add(New); file.add(Open); file.add(Save); file.add(SaveAs); file.addSeparator(); file.add(Quit); edit.add(Cut); edit.add(Copy); edit.add(Paste); edit.getItem(0).setText("Cut"); edit.getItem(0).setIcon(new ImageIcon("cut.gif")); edit.getItem(1).setText("Copy"); edit.getItem(1).setIcon(new ImageIcon("copy.gif")); edit.getItem(2).setText("Paste"); edit.getItem(2).setIcon(new ImageIcon("paste.gif")); // Time to make a toolbar! JToolBar tool = new JToolBar(); add(tool, BorderLayout.NORTH); tool.add(New); tool.add(Open); tool.add(Save); tool.addSeparator(); JButton cut = tool.add(Cut); JButton cop = tool.add(Copy); JButton pas = tool.add(Paste); cut.setText(null); cut.setIcon(new ImageIcon("cut.gif")); cop.setText(null); cop.setIcon(new ImageIcon("copy.gif")); pas.setText(null); pas.setIcon(new ImageIcon("paste.gif")); Save.setEnabled(false); SaveAs.setEnabled(false); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); pack(); /* KeyListener to change Save and SaveAs */ KeyListener k1 = new KeyAdapter() { public void keyPressed(KeyEvent e) { changed = true; Save.setEnabled(true); SaveAs.setEnabled(true); } }; area.addKeyListener(k1); setTitle(currentFile + " - CoreyTextEditor"); setVisible(true); }