Exemple #1
0
  // 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);
  }
  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);
  }
Exemple #3
0
  /** 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 static void makeMenuBar(JFrame frame, final AirspaceBuilderController controller) {
      JMenuBar menuBar = new JMenuBar();
      final JCheckBoxMenuItem resizeNewShapesItem;
      final JCheckBoxMenuItem enableEditItem;

      JMenu menu = new JMenu("File");
      {
        JMenuItem item = new JMenuItem("Open...");
        item.setAccelerator(
            KeyStroke.getKeyStroke(
                KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        item.setActionCommand(OPEN);
        item.addActionListener(controller);
        menu.add(item);

        item = new JMenuItem("Open URL...");
        item.setActionCommand(OPEN_URL);
        item.addActionListener(controller);
        menu.add(item);

        item = new JMenuItem("Save...");
        item.setAccelerator(
            KeyStroke.getKeyStroke(
                KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        item.setActionCommand(SAVE);
        item.addActionListener(controller);
        menu.add(item);

        menu.addSeparator();

        item = new JMenuItem("Load Demo Shapes");
        item.setActionCommand(OPEN_DEMO_AIRSPACES);
        item.addActionListener(controller);
        menu.add(item);
      }
      menuBar.add(menu);

      menu = new JMenu("Shape");
      {
        JMenu subMenu = new JMenu("New");
        for (final AirspaceFactory factory : defaultAirspaceFactories) {
          JMenuItem item = new JMenuItem(factory.toString());
          item.addActionListener(
              new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                  controller.createNewEntry(factory);
                }
              });
          subMenu.add(item);
        }
        menu.add(subMenu);

        resizeNewShapesItem = new JCheckBoxMenuItem("Fit new shapes to viewport");
        resizeNewShapesItem.setActionCommand(SIZE_NEW_SHAPES_TO_VIEWPORT);
        resizeNewShapesItem.addActionListener(controller);
        resizeNewShapesItem.setState(controller.isResizeNewShapesToViewport());
        menu.add(resizeNewShapesItem);

        enableEditItem = new JCheckBoxMenuItem("Enable shape editing");
        enableEditItem.setActionCommand(ENABLE_EDIT);
        enableEditItem.addActionListener(controller);
        enableEditItem.setState(controller.isEnableEdit());
        menu.add(enableEditItem);
      }
      menuBar.add(menu);

      menu = new JMenu("Selection");
      {
        JMenuItem item = new JMenuItem("Deselect");
        item.setAccelerator(
            KeyStroke.getKeyStroke(
                KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        item.setActionCommand(CLEAR_SELECTION);
        item.addActionListener(controller);
        menu.add(item);

        item = new JMenuItem("Delete");
        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
        item.setActionCommand(REMOVE_SELECTED);
        item.addActionListener(controller);
        menu.add(item);
      }
      menuBar.add(menu);

      frame.setJMenuBar(menuBar);

      controller.addPropertyChangeListener(
          new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent e) {
              if (SIZE_NEW_SHAPES_TO_VIEWPORT.equals((e.getPropertyName()))) {
                resizeNewShapesItem.setSelected(controller.isResizeNewShapesToViewport());
              } else if (ENABLE_EDIT.equals(e.getPropertyName())) {
                enableEditItem.setSelected(controller.isEnableEdit());
              }
            }
          });
    }
Exemple #5
0
  public View(Model model) {

    this.model = model;
    model.makeMeObserver(this);

    frame = new JFrame();

    statusbar = new JLabel(" 0");
    board = new Board();
    frame.add(board);

    JMenuBar menubar = new JMenuBar();
    JMenu file = new JMenu("Settings");
    file.setMnemonic(KeyEvent.VK_F);

    JMenuItem eMenuItem = new JMenuItem("New game");
    eMenuItem.setToolTipText("Start a new game");
    eMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            menuEvent = -1;
            setChanged();
            notifyObservers();
            menuEvent = 0;
          }
        });
    file.add(eMenuItem);

    eMenuItem = new JMenuItem("Pause");
    eMenuItem.setMnemonic(KeyEvent.VK_P);
    eMenuItem.setToolTipText("Set pause");
    eMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            menuEvent = 1;
            setChanged();
            notifyObservers();
            menuEvent = 0;
          }
        });
    file.add(eMenuItem);

    JMenu imp = new JMenu("Set level");
    imp.setMnemonic(KeyEvent.VK_M);

    JMenuItem lvl1 = new JMenuItem("level 1");
    lvl1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            menuEvent = 2;
            setChanged();
            notifyObservers();
            menuEvent = 0;
          }
        });

    JMenuItem lvl2 = new JMenuItem("level 2");
    lvl2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            menuEvent = 3;
            setChanged();
            notifyObservers();
            menuEvent = 0;
          }
        });

    JMenuItem lvl3 = new JMenuItem("level 3");
    lvl3.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            menuEvent = 4;
            setChanged();
            notifyObservers();
            menuEvent = 0;
          }
        });

    JMenuItem lvl4 = new JMenuItem("level 4");
    lvl4.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            menuEvent = 5;
            setChanged();
            notifyObservers();
            menuEvent = 0;
          }
        });

    JMenuItem lvl5 = new JMenuItem("level 5");
    lvl5.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            menuEvent = 6;
            setChanged();
            notifyObservers();
            menuEvent = 0;
          }
        });

    imp.add(lvl1);
    imp.add(lvl2);
    imp.add(lvl3);
    imp.add(lvl4);
    imp.add(lvl5);

    file.add(imp);

    eMenuItem = new JMenuItem("Table of recorgs");
    eMenuItem.setToolTipText("Show table of records");
    eMenuItem.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent event) {
            recordDialog ad;
            try {
              ad = new recordDialog();
              ad.setVisible(true);
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        });
    file.add(eMenuItem);

    eMenuItem = new JMenuItem("Exit");
    eMenuItem.setMnemonic(KeyEvent.VK_C);
    eMenuItem.setToolTipText("Exit application");
    eMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            System.exit(0);
          }
        });
    file.add(eMenuItem);

    menubar.add(file);
    frame.setJMenuBar(menubar);

    statusbar.setPreferredSize(new Dimension(-1, 22));
    statusbar.setBorder(LineBorder.createGrayLineBorder());
    frame.add(statusbar, BorderLayout.SOUTH);

    frame.setSize(200, 400);
    frame.setTitle("Tetris");
    frame.setLocationRelativeTo(null);
  }
Exemple #6
0
  // The constructor which sets up all the JFrame, Canvas, JPanels, and sets the buffer strategy.
  public Bomberman() {
    // makes the Canvas visible
    setVisible(true);

    // Creates window and sets it up
    window = new JFrame("BOMBERMAN");
    window.setBounds(0, 0, WIDTH, HEIGHT);
    window.setResizable(false);
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.addKeyListener(this);
    setBounds(0, 0, WIDTH, HEIGHT);
    window.getContentPane().setLayout(new CardLayout());

    // Creates the menu bar
    window.setJMenuBar(new Menu());

    // Creates an option panel that has all the options
    optionsPanel = new Options();
    window.getContentPane().add(optionsPanel, "OptionsPanel");

    // Creates a title panel which is the title screen
    titlePanel = new JPanel();
    titlePanel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
    titlePanel.setLayout(new GridLayout(1, 1));
    titlePanel.add(
        new JLabel(new ImageIcon(getClass().getClassLoader().getResource("titleScreen.png"))));
    window.getContentPane().add(titlePanel, "TitlePanel");

    // Creates and sets up the game panel where the game is played on
    gamePanel = new JPanel();
    gamePanel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
    gamePanel.setLayout(null);
    gamePanel.add(this);
    window.getContentPane().add(gamePanel, "GamePanel");

    // Creates a rules screen panel which is the rules screen
    rulesPanel = new JPanel();
    rulesPanel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
    rulesPanel.setLayout(new GridLayout(1, 1));
    rulesPanel.add(new JLabel(new ImageIcon(getClass().getClassLoader().getResource("rules.png"))));
    window.getContentPane().add(rulesPanel, "RulesPanel");

    // Creates a controls screen panel which is the controls screen
    controlsPanel = new JPanel();
    controlsPanel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
    controlsPanel.setLayout(new GridLayout(1, 1));
    controlsPanel.add(
        new JLabel(new ImageIcon(getClass().getClassLoader().getResource("controls.png"))));
    window.getContentPane().add(controlsPanel, "ControlsPanel");

    // Creates a controls screen panel which is the controls screen
    creditsPanel = new JPanel();
    creditsPanel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
    creditsPanel.setLayout(new GridLayout(1, 1));
    creditsPanel.add(
        new JLabel(new ImageIcon(getClass().getClassLoader().getResource("credits.png"))));
    window.getContentPane().add(creditsPanel, "CreditsPanel");

    // Makes certain panels visible/invisible
    gamePanel.setVisible(false);
    optionsPanel.setVisible(false);
    rulesPanel.setVisible(false);
    controlsPanel.setVisible(false);
    creditsPanel.setVisible(false);
    titlePanel.setVisible(true);
    window.setVisible(true);

    // double buffering
    createBufferStrategy(2);
    bs = getBufferStrategy();
  }
Exemple #7
0
  /**
   * Create a new, empty, not-visible TaxRef window. Really just activates the setup frame and setup
   * memory monitor components, then starts things off.
   */
  public MainFrame() {
    setupMemoryMonitor();

    // Set up the main frame.
    mainFrame = new JFrame(basicTitle);
    mainFrame.setJMenuBar(setupMenuBar());
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Set up the JTable.
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setSelectionBackground(COLOR_SELECTION_BACKGROUND);
    table.setShowGrid(true);

    // Add a blank table model so that the component renders properly on
    // startup.
    table.setModel(blankDataModel);

    // Add a list selection listener so we can tell the matchInfoPanel
    // that a new name was selected.
    table
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e) {
                if (currentCSV == null) return;

                int row = table.getSelectedRow();
                int column = table.getSelectedColumn();

                columnInfoPanel.columnChanged(column);

                Object o = table.getModel().getValueAt(row, column);
                if (Name.class.isAssignableFrom(o.getClass())) {
                  matchInfoPanel.nameSelected(currentCSV.getRowIndex(), (Name) o, row, column);
                } else {
                  matchInfoPanel.nameSelected(currentCSV.getRowIndex(), null, -1, -1);
                }
              }
            });

    // Set up the left panel (table + matchInfoPanel)
    JPanel leftPanel = new JPanel();

    matchInfoPanel = new MatchInformationPanel(this);
    leftPanel.setLayout(new BorderLayout());
    leftPanel.add(matchInfoPanel, BorderLayout.SOUTH);
    leftPanel.add(new JScrollPane(table));

    // Set up the right panel (columnInfoPanel)
    JPanel rightPanel = new JPanel();

    columnInfoPanel = new ColumnInformationPanel(this);

    progressBar.setStringPainted(true);

    rightPanel.setLayout(new BorderLayout());
    rightPanel.add(columnInfoPanel);
    rightPanel.add(progressBar, BorderLayout.SOUTH);

    // Set up a JSplitPane to split the panels up.
    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, leftPanel, rightPanel);
    split.setResizeWeight(1);
    mainFrame.add(split);
    mainFrame.pack();

    // Set up a drop target so we can pick up files
    mainFrame.setDropTarget(
        new DropTarget(
            mainFrame,
            new DropTargetAdapter() {
              @Override
              public void dragEnter(DropTargetDragEvent dtde) {
                // Accept any drags.
                dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
              }

              @Override
              public void dragOver(DropTargetDragEvent dtde) {}

              @Override
              public void dropActionChanged(DropTargetDragEvent dtde) {}

              @Override
              public void dragExit(DropTargetEvent dte) {}

              @Override
              public void drop(DropTargetDropEvent dtde) {
                // Accept a drop as long as its File List.

                if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                  dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

                  Transferable t = dtde.getTransferable();

                  try {
                    java.util.List<File> files =
                        (java.util.List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);

                    // If we're given multiple files, pick up only the last file and load that.
                    File f = files.get(files.size() - 1);
                    loadFile(f, DarwinCSV.FILE_CSV_DELIMITED);

                  } catch (UnsupportedFlavorException ex) {
                    dtde.dropComplete(false);

                  } catch (IOException ex) {
                    dtde.dropComplete(false);
                  }
                }
              }
            }));
  }
Exemple #8
0
  public SceneLayoutApp() {
    super();
    new Pair();
    final JFrame frame = new JFrame("Scene Layout");

    final JPanel panel = new JPanel(new BorderLayout());
    frame.setContentPane(panel);
    final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setMaximumSize(screenSize);
    frame.setSize(screenSize);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JMenuBar mb = new JMenuBar();
    frame.setJMenuBar(mb);

    final JMenu jMenu = new JMenu("File");
    mb.add(jMenu);
    mb.add(new JMenu("Edit"));
    mb.add(new JMenu("Help"));
    JMenu menu = new JMenu("Look and Feel");

    //
    // Get all the available look and feel that we are going to use for
    // creating the JMenuItem and assign the action listener to handle
    // the selection of menu item to change the look and feel.
    //
    UIManager.LookAndFeelInfo[] lookAndFeelInfos = UIManager.getInstalledLookAndFeels();
    for (int i = 0; i < lookAndFeelInfos.length; i++) {
      final UIManager.LookAndFeelInfo lookAndFeelInfo = lookAndFeelInfos[i];
      JMenuItem item = new JMenuItem(lookAndFeelInfo.getName());
      item.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              try {
                //
                // Set the look and feel for the frame and update the UI
                // to use a new selected look and feel.
                //
                UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());
                SwingUtilities.updateComponentTreeUI(frame);
              } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
              } catch (InstantiationException e1) {
                e1.printStackTrace();
              } catch (IllegalAccessException e1) {
                e1.printStackTrace();
              } catch (UnsupportedLookAndFeelException e1) {
                e1.printStackTrace();
              }
            }
          });
      menu.add(item);
    }

    mb.add(menu);
    jMenu.add(new JMenuItem(new scene.action.QuitAction()));

    panel.add(new JScrollPane(desktopPane), BorderLayout.CENTER);
    final JToolBar bar = new JToolBar();

    panel.add(bar, BorderLayout.NORTH);

    final JComboBox comboNewWindow =
        new JComboBox(
            new String[] {"320:180", "320:240", "640:360", "640:480", "1280:720", "1920:1080"});

    comboNewWindow.addActionListener(new CreateSceneWindowAction());

    comboNewWindow.setBorder(BorderFactory.createTitledBorder("Create New Window"));
    bar.add(comboNewWindow);
    bar.add(
        new AbstractAction("Progress Bars") {

          /** Invoked when an action occurs. */
          @Override
          public void actionPerformed(ActionEvent e) {
            new ProgressBarAnimator();
          }
        });
    bar.add(
        new AbstractAction("Sliders") {

          /** Invoked when an action occurs. */
          @Override
          public void actionPerformed(ActionEvent e) {
            new SliderBarAnimator();
          }
        });

    final JCheckBox permaViz = new JCheckBox();
    permaViz.setText("Show the dump window");
    permaViz.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));

    dumpWindow = new JInternalFrame("perma dump window");
    dumpWindow.setContentPane(new JScrollPane(permText));

    permaViz.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            dumpWindow.setVisible(permaViz.isSelected());
          }
        });

    comboNewWindow.setMaximumSize(comboNewWindow.getPreferredSize());

    permaViz.setSelected(false);
    bar.add(new CreateWebViewV1Action());
    bar.add(new CreateWebViewV2Action());
    bar.add(permaViz);
    desktopPane.add(dumpWindow);
    dumpWindow.setSize(400, 400);
    dumpWindow.setResizable(true);
    dumpWindow.setClosable(false);
    dumpWindow.setIconifiable(false);
    final JMenuBar m = new JMenuBar();
    final JMenu cmenu = new JMenu("Create");
    m.add(cmenu);
    final JMenuItem menuItem =
        new JMenuItem(
            new AbstractAction("new") {
              @Override
              public void actionPerformed(ActionEvent e) {
                Runnable runnable =
                    new Runnable() {
                      public void run() {
                        Object[] in = (Object[]) XSTREAM.fromXML(permText.getText());

                        final JInternalFrame ff = new JInternalFrame();

                        final ScenePanel c = new ScenePanel();
                        ff.setContentPane(c);
                        desktopPane.add(ff);
                        final Dimension d = (Dimension) in[0];
                        c.setMaximumSize(d);
                        c.setPreferredSize(d);

                        ff.setSize(d.width + 50, d.height + 50);
                        ScenePanel.panes.put(c, (List<Pair<Point, ArrayList<URL>>>) in[1]);

                        c.invalidate();
                        c.repaint();

                        ff.pack();
                        ff.setClosable(true);

                        ff.setMaximizable(false);
                        ff.setIconifiable(false);
                        ff.setResizable(false);
                        ff.show();
                      }
                    };

                SwingUtilities.invokeLater(runnable);
              }
            });
    cmenu.add(menuItem);
    //        JMenuBar menuBar = new JMenuBar();

    //        getContentPane().add(menuBar);

    dumpWindow.setJMenuBar(m);
    frame.setVisible(true);
  }
Exemple #9
0
  /** Constructor to set everything up */
  public TicTac() {
    // Set defaults before settings are changed via menus
    // (defaults are vs AI, play as X, with graphics on)
    multiPlayers = false;
    temp = false;
    currentPlayer = Symbol.X;
    ai = Symbol.O;
    difficulty = Difficulty.IMPOSSIBLE;

    frame = new JFrame("Tic Tac Toe");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    // Set preferred size so game fills window nicely
    this.setPreferredSize(new Dimension(cellSize * ROWS, cellSize * COLS));
    frame.add(this);

    // Load images
    try {
      sword = ImageIO.read(new File("swordsBlue.png"));
      saber = ImageIO.read(new File("saber2.png"));
      skull = ImageIO.read(new File("skull.png"));
      ring = ImageIO.read(new File("ring.png"));
      smiley = ImageIO.read(new File("smiley.png"));
      hydra = ImageIO.read(new File("hydra.png"));
      finalfantasy = ImageIO.read(new File("finalfantasy.jpg"));
      dragon = ImageIO.read(new File("dargon.jpg"));
      night = ImageIO.read(new File("night.jpg"));
    } catch (IOException e) {
      System.out.println("Could not open image files, turning images off!");
      useImages = false;
    }

    imageX = saber;
    imageO = ring;
    background = dragon;

    // Create menu bars.  Each one item will need a listener
    menuBar = new JMenuBar();
    JMenu menu = new JMenu("Mode");
    JMenu menu2 = new JMenu("Side");
    JMenu menu3 = new JMenu("Graphics");
    JMenu menu4 = new JMenu("Other");
    JMenu menu5 = new JMenu("Difficulty");
    JMenu xImageMenu = new JMenu("Image for X");
    JMenu oImageMenu = new JMenu("Image for O");
    JMenu backgroundMenu = new JMenu("Set Background");
    menuBar.add(menu);
    menuBar.add(menu2);
    menuBar.add(menu5);
    menuBar.add(menu3);
    menuBar.add(menu4);

    // Create checkbox menu items for choices
    final JCheckBoxMenuItem item = new JCheckBoxMenuItem("2 Player");
    final JCheckBoxMenuItem item2 = new JCheckBoxMenuItem("VS Computer");
    final JCheckBoxMenuItem item3 = new JCheckBoxMenuItem("Play as X");
    final JCheckBoxMenuItem item4 = new JCheckBoxMenuItem("Play as O");
    final JCheckBoxMenuItem item5 = new JCheckBoxMenuItem("On");
    final JCheckBoxMenuItem item6 = new JCheckBoxMenuItem("Off");
    JMenuItem item7 = new JMenuItem("Restart");
    JMenuItem item8 = new JMenuItem("Exit");
    final JCheckBoxMenuItem item9 = new JCheckBoxMenuItem("Easy");
    final JCheckBoxMenuItem item10 = new JCheckBoxMenuItem("Hard");
    final JCheckBoxMenuItem item11 = new JCheckBoxMenuItem("Impossible");
    final JCheckBoxMenuItem itemSword = new JCheckBoxMenuItem("Sword");
    final JCheckBoxMenuItem itemSaber = new JCheckBoxMenuItem("Sabers");
    final JCheckBoxMenuItem itemSkull = new JCheckBoxMenuItem("Skull");
    final JCheckBoxMenuItem itemRing = new JCheckBoxMenuItem("One Ring");
    final JCheckBoxMenuItem itemSmiley = new JCheckBoxMenuItem("Red Smiley");
    final JCheckBoxMenuItem itemHydra = new JCheckBoxMenuItem("Hydra");
    final JCheckBoxMenuItem itemDragon = new JCheckBoxMenuItem("Dragon");
    final JCheckBoxMenuItem itemFinalFantasy = new JCheckBoxMenuItem("Final Fantasy 7");
    final JCheckBoxMenuItem itemNight = new JCheckBoxMenuItem("Nighttime");

    // Set the initial checkboxes to true (for play vs ai, as X, with graphics on)
    item2.setSelected(true);
    item3.setSelected(true);
    item5.setSelected(true);
    item11.setSelected(true);
    itemSaber.setSelected(true);
    itemRing.setSelected(true);
    itemDragon.setSelected(true);

    // Play against friend
    item.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            item.setSelected(true);
            item2.setSelected(false);
            multiPlayers = true;
            repaint();
          }
        });
    menu.add(item);

    // Checkbox for Selecting to play against AI
    item2.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            item2.setSelected(true);
            item.setSelected(false);
            if (currentPlayer == Symbol.X) ai = Symbol.O;
            else ai = Symbol.X;
            item3.setSelected(true);
            item4.setSelected(false);
            multiPlayers = false;
          }
        });
    menu.add(item2);

    // Play as X
    item3.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            // use temp variable to move after assigning symbols
            if (item4.getState() && !multiPlayers) temp = true;
            item3.setSelected(true);
            item4.setSelected(false);
            currentPlayer = Symbol.X;
            ai = Symbol.O;
            if (temp) aiMove();
            repaint();
            temp = false;
          }
        });
    menu2.add(item3);

    // Play as O
    item4.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (item3.getState() && !multiPlayers) temp = true;
            item4.setSelected(true);
            item3.setSelected(false);
            currentPlayer = Symbol.O;
            ai = Symbol.X;
            if (temp) aiMove();
            repaint();
            temp = false;
          }
        });
    menu2.add(item4);

    // Turn Graphics on
    item5.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            item5.setSelected(true);
            item6.setSelected(false);
            useImages = true;
            repaint();
          }
        });
    menu3.add(item5);

    // Turn Graphics off
    item6.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            item5.setSelected(false);
            item6.setSelected(true);
            useImages = false;
            repaint();
          }
        });
    menu3.add(item6);
    menu3.addSeparator();
    menu3.add(xImageMenu);
    menu3.add(oImageMenu);
    menu3.add(backgroundMenu);

    // Choose Saber for X
    itemSaber.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemSword.setSelected(false);
            itemSaber.setSelected(true);
            itemSkull.setSelected(false);
            imageX = saber;
            repaint();
          }
        });
    xImageMenu.add(itemSaber);

    // Choose Sword for X
    itemSword.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemSword.setSelected(true);
            itemSaber.setSelected(false);
            itemSkull.setSelected(false);
            imageX = sword;
            repaint();
          }
        });
    xImageMenu.add(itemSword);

    // Choose Skull for X
    itemSkull.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemSword.setSelected(false);
            itemSaber.setSelected(false);
            itemSkull.setSelected(true);
            imageX = skull;
            repaint();
          }
        });
    xImageMenu.add(itemSkull);

    // Choose ring for O
    itemRing.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemRing.setSelected(true);
            itemSmiley.setSelected(false);
            itemHydra.setSelected(false);
            imageO = ring;
            repaint();
          }
        });
    oImageMenu.add(itemRing);

    // Choose red smiley for O
    itemSmiley.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemRing.setSelected(false);
            itemSmiley.setSelected(true);
            itemHydra.setSelected(false);
            imageO = smiley;
            repaint();
          }
        });
    oImageMenu.add(itemSmiley);

    // Choose hydra for O
    itemHydra.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemRing.setSelected(false);
            itemSmiley.setSelected(false);
            itemHydra.setSelected(true);
            imageO = hydra;
            repaint();
          }
        });
    oImageMenu.add(itemHydra);

    // Set dragon as background
    itemDragon.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemDragon.setSelected(true);
            itemFinalFantasy.setSelected(false);
            itemNight.setSelected(false);
            background = dragon;
            repaint();
          }
        });
    backgroundMenu.add(itemDragon);

    // Set final fantasy 7 as background
    itemFinalFantasy.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemDragon.setSelected(false);
            itemFinalFantasy.setSelected(true);
            itemNight.setSelected(false);
            background = finalfantasy;
            repaint();
          }
        });
    backgroundMenu.add(itemFinalFantasy);

    // Set night as background
    itemNight.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemDragon.setSelected(false);
            itemFinalFantasy.setSelected(false);
            itemNight.setSelected(true);
            background = night;
            repaint();
          }
        });
    backgroundMenu.add(itemNight);

    // Reset game
    item7.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            initialize();
          }
        });
    menu4.add(item7);

    // Exit game
    item8.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });
    menu4.add(item8);

    // Difficulty easy
    item9.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            difficulty = Difficulty.EASY;
            item9.setSelected(true);
            item10.setSelected(false);
            item11.setSelected(false);
          }
        });
    menu5.add(item9);

    // Difficulty hard
    item10.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            difficulty = Difficulty.HARD;
            item10.setSelected(true);
            item9.setSelected(false);
            item11.setSelected(false);
          }
        });
    menu5.add(item10);

    // Difficulty impossible
    item11.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            difficulty = Difficulty.IMPOSSIBLE;
            item11.setSelected(true);
            item9.setSelected(false);
            item10.setSelected(false);
          }
        });
    menu5.add(item11);

    // Add Whole menu bar to frame
    frame.setJMenuBar(menuBar);

    // Create statusBar (updates will take place in paintComponent)
    statusBar = new JLabel("  ");
    statusBar.setFont(new Font(Font.DIALOG_INPUT, Font.BOLD, 15));
    statusBar.setBorder(BorderFactory.createEmptyBorder(2, 5, 4, 5));
    // Use container variable to set layout and pack everything nicely
    Container cp = frame.getContentPane();
    cp.setLayout(new BorderLayout());
    cp.add(this, BorderLayout.CENTER);
    cp.add(statusBar, BorderLayout.SOUTH);
    frame.pack();

    board = new Symbol[ROWS][COLS];
    initialize();

    // Add the mouse listener.  Use MouseAdapter rather than implement it
    this.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            int currentCol = e.getX() / cellSize;
            int currentRow = e.getY() / cellSize;

            if (gameStatus == GameStatus.CONTINUE) {
              // If valid click, and spot is empty, make the move.  Then check
              // to see if game is won. If not, and facing AI, ai moves.
              // Otherwise switch X and O
              if (currentRow >= 0
                  && currentRow < ROWS
                  && currentCol >= 0
                  && currentCol < COLS
                  && board[currentRow][currentCol] == Symbol.EMPTY) {
                board[currentRow][currentCol] = currentPlayer;
                checkState(currentPlayer);

                if (multiPlayers) currentPlayer = (currentPlayer == Symbol.X) ? Symbol.O : Symbol.X;

                if (gameStatus == GameStatus.CONTINUE && !multiPlayers) aiMove();
              }
            } else {
              // Game is over, so re-initialize everything
              initialize();
            }
            repaint();
          }
        });
  }
  void main() {

    CommonSwing.setDefaultColor();

    fMain = new JFrame("HSQL Database Manager");

    // (ulrivo): An actual icon.
    fMain.getContentPane().add(createToolBar(), "North");
    fMain.setIconImage(CommonSwing.getIcon());
    fMain.addWindowListener(this);

    JMenuBar bar = new JMenuBar();

    // used shortcuts: CERGTSIUDOLM
    String fitems[] = {
      "-Connect...", "--", "-Open Script...", "-Save Script...", "-Save Result...", "--", "-Exit"
    };

    addMenu(bar, "File", fitems);

    String vitems[] = {"RRefresh Tree", "--", "GResults in Grid", "TResults in Text"};

    addMenu(bar, "View", vitems);

    String sitems[] = {
      "SSELECT",
      "IINSERT",
      "UUPDATE",
      "DDELETE",
      "---",
      "-CREATE TABLE",
      "-DROP TABLE",
      "-CREATE INDEX",
      "-DROP INDEX",
      "--",
      "-CHECKPOINT",
      "-SCRIPT",
      "-SET",
      "-SHUTDOWN",
      "--",
      "-Test Script"
    };

    addMenu(bar, "Command", sitems);

    mRecent = new JMenu("Recent");

    bar.add(mRecent);

    String soptions[] = {
      "-AutoCommit on",
      "-AutoCommit off",
      "OCommit",
      "LRollback",
      "--",
      "-Disable MaxRows",
      "-Set MaxRows to 100",
      "--",
      "-Logging on",
      "-Logging off",
      "--",
      "-Insert test data"
    };

    addMenu(bar, "Options", soptions);

    String stools[] = {"-Dump", "-Restore", "-Transfer"};

    addMenu(bar, "Tools", stools);
    fMain.setJMenuBar(bar);
    initGUI();

    sRecent = new String[iMaxRecent];

    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension size = fMain.getSize();

    // (ulrivo): full size on screen with less than 640 width
    if (d.width >= 640) {
      fMain.setLocation((d.width - size.width) / 2, (d.height - size.height) / 2);
    } else {
      fMain.setLocation(0, 0);
      fMain.setSize(d);
    }

    fMain.show();

    // (ulrivo): load query from command line
    if (defScript != null) {
      if (defDirectory != null) {
        defScript = defDirectory + File.separator + defScript;
      }

      // if insert stmet is thousands of records...skip showing it
      // as text.  Too huge.
      StringBuffer buf = new StringBuffer();

      ifHuge = DatabaseManagerCommon.readFile(defScript);

      if (4096 <= ifHuge.length()) {
        buf.append("This huge file cannot be edited. Please execute\n");
        txtCommand.setText(buf.toString());
      } else {
        txtCommand.setText(ifHuge);
      }
    }

    txtCommand.requestFocus();
  }
  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);

  }