public void go() throws IOException { // DefaultRouteTable route = new DefaultRouteTable(); // System.out.println(route.routeInfo()); // route.routeInfo(); totalSize = Toolkit.getDefaultToolkit().getScreenSize(); // getting screen size int width = totalSize.width; int height = totalSize.height; frame = new JFrame(); // creating frame frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { FileInput data = null; try { data = new FileInput("input.txt"); } catch (Exception e) { } String[][] origRoutes = convertArrayListTo2DArray(data.routeArrayList(data.routesToken), 1); String[][] routesList = Main.convertArrayListTo2DArray(routesInfo, 1); Main.changesCheck(origRoutes, routesList); } }); frame.setTitle("Air Route Planner"); frame.add(Panels()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize((width * 3 / 4), (height * 3 / 4)); frame.setJMenuBar(menuBar()); frame.setResizable(false); frame.setVisible(true); frame.setLocationRelativeTo(null); }
private static void constructMenu() { final JFrame lFrame = (JFrame) viewModel.get("window.frame"); final JMenuBar lMenuBar = new JMenuBar(); lFrame.setJMenuBar(lMenuBar); viewModel.put("menu", lMenuBar); final JMenu lFileMenu = new JMenu("File"); lFileMenu.setMnemonic(KeyEvent.VK_F); viewModel.put("menu.file", lFileMenu); lMenuBar.add(lFileMenu); final JMenuItem lExitItem = new JMenuItem((Action) viewModel.get("action.exit")); viewModel.put("menu.file.exit", lExitItem); lFileMenu.add(lExitItem); final JMenuItem lHelpMenu = new JMenu("Help"); lHelpMenu.setMnemonic(KeyEvent.VK_H); viewModel.put("menu.help", lHelpMenu); lMenuBar.add(lHelpMenu); final JMenuItem lHelpTopicsItem = new JMenuItem((Action) viewModel.get("action.help")); viewModel.put("menu.help.topics", lHelpTopicsItem); lHelpMenu.add(lHelpTopicsItem); final JMenuItem lAboutItem = new JMenuItem((Action) viewModel.get("action.about")); viewModel.put("menu.help.about", lAboutItem); lHelpMenu.add(lAboutItem); }
/** Method to create the menu bar, menus, and menu items */ private void setUpMenuBar() { // create menu menuBar = new JMenuBar(); zoomMenu = new JMenu("Zoom"); twentyFive = new JMenuItem("25%"); fifty = new JMenuItem("50%"); seventyFive = new JMenuItem("75%"); hundred = new JMenuItem("100%"); hundred.setEnabled(false); hundredFifty = new JMenuItem("150%"); twoHundred = new JMenuItem("200%"); fiveHundred = new JMenuItem("500%"); // add the action listeners twentyFive.addActionListener(this); fifty.addActionListener(this); seventyFive.addActionListener(this); hundred.addActionListener(this); hundredFifty.addActionListener(this); twoHundred.addActionListener(this); fiveHundred.addActionListener(this); // add the menu items to the menus zoomMenu.add(twentyFive); zoomMenu.add(fifty); zoomMenu.add(seventyFive); zoomMenu.add(hundred); zoomMenu.add(hundredFifty); zoomMenu.add(twoHundred); zoomMenu.add(fiveHundred); menuBar.add(zoomMenu); // set the menu bar to this menu pictureFrame.setJMenuBar(menuBar); }
public void start() { menu.setMnemonic('f'); submenu.setMnemonic('m'); menu.add(submenu); submenu.add(item); bar.add(menu); frame.setJMenuBar(bar); frame.pack(); item.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { Sysout.println(e.toString()); synchronized (activated) { activated.set(true); activated.notifyAll(); } } }); frame.setVisible(true); Util.waitForIdle(robot); boolean isMacOSX = (OSInfo.getOSType() == OSInfo.OSType.MACOSX); if (isMacOSX) { robot.keyPress(KeyEvent.VK_CONTROL); robot.delay(20); } robot.keyPress(KeyEvent.VK_ALT); robot.delay(20); robot.keyPress(KeyEvent.VK_F); robot.delay(20); robot.keyRelease(KeyEvent.VK_F); robot.delay(20); robot.keyRelease(KeyEvent.VK_ALT); if (isMacOSX) { robot.keyRelease(KeyEvent.VK_CONTROL); robot.delay(20); } Util.waitForIdle(robot); robot.keyPress(KeyEvent.VK_M); robot.delay(20); robot.keyRelease(KeyEvent.VK_M); Util.waitForIdle(robot); robot.keyPress(KeyEvent.VK_SPACE); robot.delay(20); robot.keyRelease(KeyEvent.VK_SPACE); Util.waitForIdle(robot); if (!Util.waitForCondition(activated, 2000)) { throw new TestFailedException("a submenu wasn't activated by mnemonic key press"); } Sysout.println("Test passed."); }
/** * Creates and configures a frame, builds the menu bar, builds the content, locates the frame on * the screen, and finally shows the frame. */ private void buildInterface() { JFrame frame = new JFrame(); frame.setJMenuBar(buildMenuBar()); frame.setContentPane(buildContentPane()); frame.setSize(600, 400); locateOnScreen(frame); frame.setTitle("JGoodies :: Tiny"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
public Kayttoliittyma(Sovelluslogiikka logiikka) { this.logiikka = logiikka; frame = new JFrame("Aritmetiikkaharjoittelu"); frame.setPreferredSize(new Dimension(400, 600)); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); luoKomponentit(frame.getContentPane()); frame.setJMenuBar(menubar()); }
/* Create and show the graphical user interface. */ private static void createAndShowGUI() { JFrame frame = new JFrame("My Collapsing Puzzle"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Game game = new Game(); frame.setJMenuBar(game.createMenuBar()); frame.setContentPane(game.createContentPane()); frame.setSize(game.getGameSize()); frame.setVisible(true); }
/** The main routine simply opens a window that shows a PaintWithOffScreenCanvas panel. */ public static void main(String[] args) { JFrame window = new JFrame("PaintWithOffScreenCanvas"); AdvancedGUIEX1 content = new AdvancedGUIEX1(); window.setContentPane(content); window.setJMenuBar(content.getMenuBar()); window.pack(); window.setResizable(false); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); window.setLocation( (screenSize.width - window.getWidth()) / 2, (screenSize.height - window.getHeight()) / 2); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setVisible(true); }
private static void components() { Container c = frame.getContentPane(); JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); // Aca voy agregando los distintos menus menuBar.add(new MenuArchivo()); menuBar.add(new MenuProveedor()); // Aca voy agregando los componentes c.add(new PanelCentral(), BorderLayout.CENTER); c.add(new PanelSur(), BorderLayout.SOUTH); }
public static void main(String[] args) { int a = ROW * PREFERRED_GRID_SIZE_PIXELS; int b = ROW * PREFERRED_GRID_SIZE_PIXELS; BuildArray(); SquareGrid test = new SquareGrid(); JFrame f = new JFrame(); f.setTitle("ObjectVis"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(test); // setPreferredSize(new Dimension(80, 50)); f.setSize(a, 800); // f.setSize(f.MAXIMIZED_HORIZ, f.MAXIMIZED_VERT); Dimension d = f.getMaximumSize(); // int m=f.MAXIMIZED_BOTH; // f.setMaximumSize(d); // f.setLocation(100,100); f.setVisible(true); f.setJMenuBar(test.addMenu()); test.addComponentListener(test.cl); f.setJMenuBar(test.addMenu()); }
// Create the GUI and show it. For thread safety, this method should be invoked from the // event-dispatching thread. private static void CreateAndShowGUI() { // Create and set up the window. mainframe = new JFrame("No Drawbot Connected"); mainframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create and set up the content pane. DrawbotGUI demo = DrawbotGUI.getSingleton(); mainframe.setJMenuBar(demo.CreateMenuBar()); mainframe.setContentPane(demo.CreateContentPane()); // Display the window. mainframe.setSize(800, 700); mainframe.setVisible(true); }
public void start() { menu.setMnemonic('f'); item.setMnemonic('i'); menu.add(item); bar.add(menu); frame.add(text); frame.setJMenuBar(bar); frame.pack(); frame.setLocation(800, 0); frame.setVisible(true); test(); }
private static void components() { Container c = frame.getContentPane(); JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); c.add(new PanelCentral(), BorderLayout.CENTER); c.add(new PanelOeste(), BorderLayout.WEST); System.out.println("hola"); try { } catch (Exception e) { // TODO: handle exception } while (frame.action(null, null)) { System.out.println("hola"); } }
/** * Create the main frame's menu bar. * * @param frame The frame that the menu bar should be added to. */ private void makeMenuBar(JFrame frame) { JMenuBar menubar = new JMenuBar(); frame.setJMenuBar(menubar); // create the File menu JMenu fileMenu = new JMenu("File"); menubar.add(fileMenu); JMenuItem openItem = new JMenuItem("Open"); openItem.addActionListener(this); fileMenu.add(openItem); JMenuItem quitItem = new JMenuItem("Quit"); quitItem.addActionListener(this); fileMenu.add(quitItem); }
public static void main(String args[]) { server = new Server(); // Main panel contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); frame.setContentPane(contentPane); contentPane.setLayout(null); Menu(); TextPanel(); InfoPanel(); ServerPanel(); frame.setJMenuBar(menu); frame.setSize(660, 700); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
@Override public void run() { // Frame final JFrame frame = new JFrame("Keyword"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(800, 600); frame.setLocationRelativeTo(null); frame.setVisible(true); // FileChooser final JFileChooser fileChooser = new JFileChooser(); fileChooser.setSize(800, 600); // Menubar JMenuBar menubar = new JMenuBar(); frame.setJMenuBar(menubar); // Menus JMenu menuFile = new JMenu("File"); menuFile.setVisible(true); menubar.add(menuFile); // MenuItems JMenuItem itemOpenFile = new JMenuItem( new AbstractAction("Open File") { @Override public void actionPerformed(ActionEvent actionEvent) { int returnVal = fileChooser.showOpenDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); // This is where a real application would open the file. System.out.println("Opening: " + file.getPath() + "."); } else { System.out.println("Open command cancelled by user."); } } }); menuFile.add(itemOpenFile); }
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); }
/** Constructor */ private SimpleTabbedPanelExample() { frame.setSize(600, 400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setJMenuBar(createMenuBar()); frame.getContentPane().add(tabbedPanel, BorderLayout.CENTER); // Set the "close all tabs" button as a tab area component tabbedPanel.setTabAreaComponents(new JComponent[] {createCloseAllTabsButton(tabbedPanel)}); // Create 6 titled tabs and add them to the tabbed panel for (int i = 0; i < 6; i++) tabbedPanel.addTab(createTab()); // Apply the default theme tabbedPanel.getProperties().addSuperObject(themes[0].getTabbedPanelProperties()); titledTabProperties.addSuperObject(themes[0].getTitledTabProperties()); activeTheme = themes[0]; frame.setVisible(true); }
public SharedActions(final JFrame frame) { this.frame = frame; buildActionTable(); buildPopupMenu(); JTextPane textPane = new JTextPane(); textPane.setEditable(false); textPane.setText( "\n\tUse the MenuBar, ToolBar or right-click for a popup menu.\n\n" + "\tAction1 disables itself and enables Action2.\n" + "\tAction2 disables itself and enables Action1.\n" + "\tAction3 and Action4 support toggle buttons and checkboxes.\n" + "\tThe About action enables Actions 1 and 2 and selects Actions 3 and 4.\n\n" + "\tAll components use a common set of actions.\n" + "\tThe actions and corresponding components\n" + "\tare enabled and disabled in concert.\n\n" + "\tFor larger swing applications, I place all actions\n" + "\tin a separate package which maps to a directory structure\n" + "\tsomething like this...\n\n" + "\tmypackage \n" + "\t\tSharedActions.java\n" + "\tmypackage/action\n" + "\t\tExitAction.java\n" + "\t\tAction1.java\n" + "\t\tAction2.java\n" + "\t\tAboutAction.java\n"); frame.getContentPane().add(new MyToolBar(actionTable), BorderLayout.NORTH); frame.getContentPane().add(new JScrollPane(textPane), BorderLayout.CENTER); textPane.addMouseListener(new MousePopupListener()); frame.setJMenuBar(new MyMenuBar(actionTable)); frame.setSize(640, 480); // send window closing events to our "Exit" action handler. frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { getAction(SharedActions.EXIT_KEY).actionPerformed(null); } }); }
public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } Action action = new GloballyContextSensitiveAction("selectAll", "selectAll", "selectAll"); JMenuBar menubar = new JMenuBar(); JMenu menu = new JMenu("Actions"); menu.add(action); menubar.add(menu); JToolBar toolbar = new JToolBar(); toolbar.setRollover(true); toolbar.setFloatable(true); toolbar.add(action); JPanel contents = new JPanel(); String[] listData = new String[] {"item1", "item2", "item3", "item4", "item5 "}; JList list = new JList(listData); contents.add(new JScrollPane(list)); JTree tree = new JTree(); tree.setVisibleRowCount(10); contents.add(new JScrollPane(tree)); JTable table = new JTable(new DefaultTableModel(new String[] {"Name", "Type", "Modified"}, 10)); table.setPreferredScrollableViewportSize(new Dimension(100, 5 * table.getRowHeight())); contents.add(new JScrollPane(table)); contents.add(new JPanel()); JFrame frame = new JFrame("Globally Context Sensitive Actions - [email protected]"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setJMenuBar(menubar); frame.getContentPane().add(contents); frame.getContentPane().add(toolbar, BorderLayout.NORTH); frame.pack(); frame.show(); }
/** Create the menu bar for the GUI */ private void createMenu() { // Create menu bar menuBar = new JMenuBar(); clientFrame.setJMenuBar(menuBar); // Create menus fileMenu = new JMenu("File"); helpMenu = new JMenu("Help"); // Add menus to bar menuBar.add(fileMenu); menuBar.add(helpMenu); // Create File Menu Items hostItem = new JCheckBoxMenuItem("Allow Uploads", true); portItem = new JCheckBoxMenuItem("Use Passive Mode", true); exitItem = new JMenuItem("Exit"); // Add Items to File Menu fileMenu.add(hostItem); fileMenu.add(portItem); fileMenu.addSeparator(); fileMenu.add(exitItem); // Create Help Menu Items helpItem = new JMenuItem("Help"); aboutItem = new JMenuItem("About LeetFTP"); // Add Items to Help Menu helpMenu.add(helpItem); helpMenu.addSeparator(); helpMenu.add(aboutItem); // Create menu action handler and set it active MenuHandler menuHandler = new MenuHandler(); hostItem.addActionListener(menuHandler); portItem.addActionListener(menuHandler); exitItem.addActionListener(menuHandler); helpItem.addActionListener(menuHandler); aboutItem.addActionListener(menuHandler); }
public ImageProxyTestDrive() throws Exception { cds.put( "Ambient: Music for Airports", "http://images.amazon.com/images/P/B000003S2K.01.LZZZZZZZ.jpg"); cds.put("Buddha Bar", "http://images.amazon.com/images/P/B00009XBYK.01.LZZZZZZZ.jpg"); cds.put("Ima", "http://images.amazon.com/images/P/B000005IRM.01.LZZZZZZZ.jpg"); cds.put("Karma", "http://images.amazon.com/images/P/B000005DCB.01.LZZZZZZZ.gif"); cds.put("MCMXC A.D.", "http://images.amazon.com/images/P/B000002URV.01.LZZZZZZZ.jpg"); cds.put("Northern Exposure", "http://images.amazon.com/images/P/B000003SFN.01.LZZZZZZZ.jpg"); cds.put( "Selected Ambient Works, Vol. 2", "http://images.amazon.com/images/P/B000002MNZ.01.LZZZZZZZ.jpg"); URL initialURL = new URL((String) cds.get("Selected Ambient Works, Vol. 2")); menuBar = new JMenuBar(); menu = new JMenu("Favorite CDs"); menuBar.add(menu); frame.setJMenuBar(menuBar); for (Enumeration e = cds.keys(); e.hasMoreElements(); ) { String name = (String) e.nextElement(); JMenuItem menuItem = new JMenuItem(name); menu.add(menuItem); menuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { imageComponent.setIcon(new ImageProxy(getCDUrl(event.getActionCommand()))); frame.repaint(); } }); } // set up frame and menus Icon icon = new ImageProxy(initialURL); imageComponent = new ImageComponent(icon); frame.getContentPane().add(imageComponent); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(800, 600); frame.setVisible(true); }
// init private static void init() { if (frame != null) frame.setVisible(false); frame = new JFrame(); offscreenImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); onscreenImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); offscreen = offscreenImage.createGraphics(); onscreen = onscreenImage.createGraphics(); setXscale(); setYscale(); offscreen.setColor(DEFAULT_CLEAR_COLOR); offscreen.fillRect(0, 0, width, height); setPenColor(); setPenRadius(); setFont(); clear(); // add anti-aliasing RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); offscreen.addRenderingHints(hints); // frame stuff ImageIcon icon = new ImageIcon(onscreenImage); JLabel draw = new JLabel(icon); draw.addMouseListener(std); draw.addMouseMotionListener(std); frame.setContentPane(draw); frame.addKeyListener(std); // JLabel cannot get keyboard focus frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // closes all windows // frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // closes only current window frame.setTitle("Standard Draw"); frame.setJMenuBar(createMenuBar()); frame.pack(); frame.requestFocusInWindow(); frame.setVisible(true); }
/** * The main program for the AlerterTest class * * @param args The command line arguments */ public static void main(String[] args) { final JFrame frame = new JFrame("asdf"); // set up the main menubar JMenuBar menubar = new JMenuBar(); JMenu menu = new JMenu("Test"); JMenuItem item = new JMenuItem("Do Alert in 4 Seconds"); item.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { new Thread( new Runnable() { public void run() { try { Thread.currentThread().sleep(1000); } catch (Exception ex) { } try { System.out.println("calling"); Alerter alerter = Alerter.newInstance(); alerter.alert(frame); } catch (Exception e) { System.err.println("Couldn't load the library."); } } }) .start(); } }); menu.add(item); menubar.add(menu); // show the frame frame.setJMenuBar(menubar); frame.pack(); frame.setSize(100, 100); frame.show(); }
/** * Create the main frame's menu bar. * * @param frame The frame that the menu bar should be added to. */ private void makeMenuBar(JFrame frame) { final int SHORTCUT_MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); JMenuBar menubar = new JMenuBar(); frame.setJMenuBar(menubar); // create the File manu JMenu fileMenu = new JMenu("File"); menubar.add(fileMenu); JMenuItem openItem = new JMenuItem("Open"); openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, SHORTCUT_MASK)); openItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { openFile(); } }); fileMenu.add(openItem); JMenuItem quitItem = new JMenuItem("Quit"); quitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, SHORTCUT_MASK)); quitItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { quit(); } }); fileMenu.add(quitItem); JMenuItem helpItem = new JMenuItem("Help"); helpItem.setAccelerator(KeyStroke.getKeyStroke(133, SHORTCUT_MASK)); helpItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { Launch(); } }); fileMenu.add(helpItem); }
/** Este método crea un menú superior que esconde algunas opciones importantes. */ private void crearMenuSuperior() { barraDeMenu = new JMenuBar(); JMenu menuPrincipal = new JMenu("Opciones"); JMenuItem destaparCartas = new JMenuItem("Destapar cartas"); JMenuItem resetear = new JMenuItem("Volver a empezar"); JMenuItem salirJuego = new JMenuItem("Salir"); destaparCartas.addActionListener(this); resetear.addActionListener(this); salirJuego.addActionListener(this); menuPrincipal.add(destaparCartas); menuPrincipal.add(resetear); menuPrincipal.addSeparator(); menuPrincipal.addSeparator(); menuPrincipal.add(salirJuego); barraDeMenu.add(menuPrincipal); ventana.setJMenuBar(barraDeMenu); }
public SPanel(JFrame sframe) { balls = new Ball[B_WIDTH][B_HEIGHT]; setBackground(Color.black); JMenuBar mb = new JMenuBar(); sframe.setJMenuBar(mb); JMenu smenu = new JMenu("File"); mb.add(smenu); smenu.setMnemonic('F'); newgame = smenu.add("New Game"); newgame.setMnemonic('N'); smenu.addSeparator(); quitgame = smenu.add("Quit Game"); quitgame.setMnemonic('Q'); ButtonHandler b = new ButtonHandler(); quitgame.addActionListener(b); newgame.addActionListener(b); resetBoard(); addMouseListener(new MouseHandler()); addMouseMotionListener(new MouseMotionHandler()); }
/** * Register for special events available on the Mac, such as showing the about screen, showing the * preferences or double-clicking a file. * * @throws RuntimeException if the adapter methods could not be loaded. */ private void registerForMacOSXEvents() throws RuntimeException { if (!Platform.onMac()) return; try { // Generate and register the OSXAdapter, passing it a hash of all the methods we wish to // use as delegates for various com.apple.eawt.ApplicationListener methods OSXAdapter.setQuitHandler(this, getClass().getDeclaredMethod("quit", (Class[]) null)); OSXAdapter.setAboutHandler(this, getClass().getDeclaredMethod("showAbout", (Class[]) null)); OSXAdapter.setPreferencesHandler( this, getClass().getDeclaredMethod("showPreferences", (Class[]) null)); OSXAdapter.setFileHandler(this, getClass().getDeclaredMethod("readFromFile", String.class)); } catch (Exception e) { throw new RuntimeException("Error while loading the OS X Adapter.", e); } // On the Mac, if all windows are closed the menu bar will be empty. // To solve this, we create an off-screen window with the same menu bar as visible windows. hiddenFrame = new JFrame(); hiddenFrame.setJMenuBar(new NodeBoxMenuBar()); hiddenFrame.setUndecorated(true); hiddenFrame.setSize(0, 0); hiddenFrame.setLocation(-100, -100); hiddenFrame.pack(); hiddenFrame.setVisible(true); }
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); }