/** 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);
  }
Example #2
0
  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);
  }
Example #3
0
  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.");
  }
Example #4
0
  /* 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);
  }
Example #5
0
  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());
  }
 /** 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);
  }
Example #8
0
  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());
  }
Example #9
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);
  }
  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();
  }
Example #11
0
  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);
  }
Example #13
0
  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 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();
  }
Example #16
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 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);
          }
        });
  }
Example #18
0
  // 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 antialiasing
    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);
  }
  /**
   * 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);
  }
Example #20
0
  /** 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);
  }
Example #21
0
  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());
  }
Example #22
0
 /**
  * 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);
 }
  // ------------------------------------------------------------------------------------------------------
  protected void createGui() {
    mainFrame = new JFrame(myGaggleName);
    MiscUtil.setApplicationIcon(mainFrame);

    mainFrame.setJMenuBar(createMenuBar());
    mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    JPanel outerPanel = new JPanel();
    mainFrame.getContentPane().add(outerPanel);
    outerPanel.setLayout(new BorderLayout());

    JToolBar toolbar = new JToolBar();
    toolbar.setFloatable(false);
    JButton bossButton = new JButton("Boss");
    bossButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              gaggleBoss.show("boss");
            } catch (RemoteException rex) {
              rex.printStackTrace();
            }
          }
        });

    toolbar.add(bossButton);
    outerPanel.add(toolbar, BorderLayout.NORTH);

    tabbedPane = new JTabbedPane();
    tabbedPane.setUI(new MyTabbedPaneUI());

    outerPanel.add(tabbedPane, BorderLayout.CENTER);

    mainFrame.pack();
    mainFrame.setSize(800, 800);
    mainFrame.setVisible(true);
    MiscUtil.placeInCenter(mainFrame);
  } // createGui
  /** Create the Swing frame and its content. */
  private void makeFrame() {
    frame = new JFrame("Text Display");
    Container contentPane = frame.getContentPane();
    JMenuBar menubar = new JMenuBar();
    frame.setJMenuBar(menubar);
    JMenu fileMenu = new JMenu("File");
    menubar.add(fileMenu);

    JMenuItem openItem = new JMenuItem("Open");
    fileMenu.add(openItem);
    JMenuItem quitItem = new JMenuItem("Quit");
    fileMenu.add(quitItem);
    JMenuItem help = new JMenuItem("AboutImageViewer");
    fileMenu.add(help);

    JLabel label = new JLabel("I am a label. I can display some text.");
    JButton button = new JButton("Nuclear Launch Codes");
    contentPane.add(label);
    contentPane.add(button);

    frame.pack();
    frame.setVisible(true);
    frame.resize(240, 240);
  }
Example #25
0
  // --------------------------------initGUI------------------------------------
  public void initGUI() {
    bDeployed = bOpponentDeployed = false;
    listAT = new LinkedList();

    frame.setJMenuBar(new GameMenuBar(this));
    panParty = new PartyPanel(200, 480);
    panStatus = new JPanel(null);
    oMap = new Map(600, 350);
    panChat = new ChatPanel(600, 200);

    Container contentPane = frame.getContentPane();

    panParty.setOpaque(true);
    panStatus.setOpaque(true);
    panChat.setOpaque(true);

    panStatus.setPreferredSize(new Dimension(200, 70));

    contentPane.add(panStatus);
    contentPane.add(panParty);
    contentPane.add(oMap);
    contentPane.add(panChat);

    SpringLayout oLayout = new SpringLayout();
    contentPane.setLayout(oLayout);

    oLayout.putConstraint(SpringLayout.WEST, panParty, 0, SpringLayout.WEST, contentPane);
    oLayout.putConstraint(SpringLayout.NORTH, panParty, 0, SpringLayout.NORTH, contentPane);
    oLayout.putConstraint(SpringLayout.WEST, panStatus, 0, SpringLayout.WEST, contentPane);
    oLayout.putConstraint(SpringLayout.SOUTH, panStatus, 0, SpringLayout.SOUTH, contentPane);
    oLayout.putConstraint(SpringLayout.EAST, oMap, 0, SpringLayout.EAST, contentPane);
    oLayout.putConstraint(SpringLayout.NORTH, oMap, 0, SpringLayout.NORTH, contentPane);
    oLayout.putConstraint(SpringLayout.WEST, panChat, 0, SpringLayout.EAST, panStatus);
    oLayout.putConstraint(SpringLayout.NORTH, panChat, 0, SpringLayout.SOUTH, oMap);
    oLayout.putConstraint(SpringLayout.EAST, contentPane, 0, SpringLayout.EAST, panChat);
    oLayout.putConstraint(SpringLayout.SOUTH, contentPane, 0, SpringLayout.SOUTH, panChat);

    panChat.validate();
    panChat.setVisible(true);

    Insets oInsets = panStatus.getInsets();
    int nX = oInsets.left + 5;
    int nY = oInsets.top + 5;

    lblStatus1 = new JLabel("Not Connected...");
    lblStatus2 = new JLabel("No Party Formed...");
    lblStatus3 = new JLabel();

    Dimension oSize = lblStatus1.getPreferredSize();

    lblStatus1.setBounds(nX, nY, 180, oSize.height);
    nY += oSize.height + 7;
    lblStatus2.setBounds(nX, nY, 180, oSize.height);
    nY += oSize.height + 7;
    lblStatus3.setBounds(nX, nY, 180, oSize.height);

    panStatus.add(lblStatus1);
    panStatus.add(lblStatus2);
    panStatus.add(lblStatus3);

    frame.pack();
    frame.setResizable(false);
    frame.setLocation(
        ((scrBounds.x + scrBounds.width - frame.getWidth()) / 2),
        ((scrBounds.y + scrBounds.height - frame.getHeight()) / 2));

    oMap.addKeyListener(oMap);
    oMap.setButtonEvents(this);
  }
Example #26
0
  /** Initialize the contents of the frame. */
  private void initialize() {
    frame = new JFrame();
    frame.setBounds(100, 100, 616, 451);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);

    JMenu MenuScegli = new JMenu("Scegli");
    menuBar.add(MenuScegli);

    MenuScegliCampionato = new JMenu("Campionato");
    MenuScegli.add(MenuScegliCampionato);

    MenuScegliSquadra = new JMenu("Squadra");
    MenuScegli.add(MenuScegliSquadra);

    JMenu MenuCrea = new JMenu("Crea");
    menuBar.add(MenuCrea);

    JMenuItem MenuCreaCampionato = new JMenuItem("Campionato");
    MenuCreaCampionato.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseReleased(MouseEvent e) {
            CreaCampionato creaCampionato = new CreaCampionato();
            creaCampionato.setVisible(true);
          }
        });
    MenuCrea.add(MenuCreaCampionato);

    JMenuItem MenuCreaSquadra = new JMenuItem("Squadra");
    MenuCreaSquadra.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseReleased(MouseEvent e) {
            CreaSquadra creaSquadra = new CreaSquadra();
            creaSquadra.setVisible(true);
          }
        });
    MenuCrea.add(MenuCreaSquadra);

    JMenu MenuAltro = new JMenu("Altro");
    menuBar.add(MenuAltro);

    JMenuItem MenuAltroInfo = new JMenuItem("Info");
    MenuAltroInfo.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseReleased(MouseEvent e) {
            JOptionPane.showMessageDialog(frame, "Per ora niente");
          }
        });
    MenuAltro.add(MenuAltroInfo);

    JMenuItem MenuAltroEsci = new JMenuItem("Esci");
    MenuAltroEsci.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseReleased(MouseEvent arg0) {
            if (JOptionPane.showConfirmDialog(
                    frame,
                    "Vuoi veramente uscire?",
                    "Uscire",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE)
                == JOptionPane.YES_OPTION) {
              System.exit(0);
            }
          }
        });
    MenuAltro.add(MenuAltroEsci);
  }
Example #27
0
  // Constructor receives the filename
  Rolodex(String filename) throws FileNotFoundException {
    File file = new File(filename);
    Scanner scanner = new Scanner(file);

    // Split the line with ~
    while (scanner.hasNext()) {
      tokens = scanner.nextLine().split("~");
      name = tokens[0];
      email = tokens[1];
      pictures = tokens[tokens.length - 1];

      User user = new User();
      user.setUserName(name);
      user.setUserEmail(email);
      user.setPicture(pictures);
      userList.add(user);
    }

    frame = new JFrame("Rolodex");
    frame.setSize(700, 200);

    // Menu
    JMenuBar jmb = new JMenuBar();
    JMenu jmFile = new JMenu("File");
    JMenuItem jmiOpen = new JMenuItem("Open");
    jmiOpen.setEnabled(false);
    JMenuItem jmiExit = new JMenuItem("Exit");
    jmiExit.setMnemonic(KeyEvent.VK_X);
    jmFile.add(jmiOpen);
    jmFile.addSeparator();
    jmFile.add(jmiExit);
    jmb.add(jmFile);

    jmiOpen.addActionListener(this);
    jmiExit.addActionListener(this);

    JMenu jmTabs = new JMenu("Tabs");
    jmTabs.setMnemonic(KeyEvent.VK_T);

    JMenu jmiplacement = new JMenu("Placement");
    JMenuItem jmitop = new JMenuItem("Top");
    JMenuItem jmiright = new JMenuItem("Right");
    JMenuItem jmibottom = new JMenuItem("Bottom");
    JMenuItem jmileft = new JMenuItem("Left");
    jmiplacement.add(jmitop);
    jmiplacement.add(jmiright);
    jmiplacement.add(jmibottom);
    jmiplacement.add(jmileft);

    jmitop.addActionListener(this);
    jmiright.addActionListener(this);
    jmibottom.addActionListener(this);
    jmileft.addActionListener(this);

    JMenu jmilayoutpolicy = new JMenu("Layout policy");
    JMenuItem jmiscroll = new JMenuItem("Scroll");
    JMenuItem jmiwrap = new JMenuItem("Wrap");
    jmilayoutpolicy.add(jmiscroll);
    jmilayoutpolicy.add(jmiwrap);

    jmiscroll.addActionListener(this);
    jmiwrap.addActionListener(this);

    JMenuItem jmidefaults = new JMenuItem("Defaults");
    jmidefaults.setMnemonic(KeyEvent.VK_D);
    jmidefaults.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_MASK));
    jmidefaults.addActionListener(this);
    jmTabs.add(jmiplacement);
    jmTabs.add(jmilayoutpolicy);
    jmTabs.addSeparator();
    jmTabs.add(jmidefaults);
    jmb.add(jmTabs);

    JMenu jmHelp = new JMenu("Help");
    JMenuItem jmiabout = new JMenuItem("About");
    jmiabout.addActionListener(this);
    jmHelp.add(jmiabout);
    jmb.add(jmHelp);

    frame.setJMenuBar(jmb);

    jtp = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());

    for (User user : userList) {
      image = new ImageIcon(user.getPicture());
      panel = new JPanel();
      labname = new JLabel("Name: ");
      txtname = new JTextField(20);
      txtname.setText(user.getUserName());
      labemail = new JLabel("Email: ");
      txtemail = new JTextField(20);
      txtemail.setText(user.getUserEmail());
      l = new JLabel(image);
      l.setHorizontalAlignment(SwingConstants.LEFT);
      panel.add(l);
      panel.add(labname);
      panel.add(txtname);
      panel.add(labemail);
      panel.add(txtemail);
      jtp.addTab(user.getUserName(), panel);
      topPanel.add(jtp);
    }

    frame.add(jtp);
    center(frame);
    frame.setVisible(true);
  }
Example #28
0
  public static void main(String... args) {
    JFrame frame = new JFrame();
    frame.setTitle("Game Of Life");
    JMenuBar toolBar = new JMenuBar();
    JButton start = new JButton(getImageIcon("/icons/play_icon.png"));
    start.setToolTipText("Run");
    start.setBorderPainted(false);
    JButton reset = new JButton(getImageIcon("/icons/reset_icon.png"));
    reset.setToolTipText("Clear field");
    reset.setBorderPainted(false);
    JButton next = new JButton(getImageIcon("/icons/next_icon.png"));
    next.setToolTipText("Next step");
    next.setBorderPainted(false);
    JButton pause = new JButton(getImageIcon("/icons/pause_icon.png"));
    pause.setToolTipText("Pause");
    pause.setBorderPainted(false);
    JButton size = new JButton(getImageIcon("/icons/size_icon.png"));
    size.setToolTipText("Set grid size");
    size.setBorderPainted(false);
    JButton showGrid = new JButton(getImageIcon("/icons/grid_icon.png"));
    showGrid.setToolTipText("Enable/disable grid lines");
    showGrid.setBorderPainted(false);
    JButton btRandom = new JButton(getImageIcon("/icons/dice_icon.png"));
    btRandom.setToolTipText("Fill randomly");
    btRandom.setBorderPainted(false);

    JButton btAbout = new JButton(getImageIcon("/icons/about_icon.png"));
    btAbout.setToolTipText("About");
    btAbout.setBorderPainted(false);

    toolBar.add(start);
    toolBar.add(next);
    toolBar.add(pause);
    toolBar.add(reset);
    toolBar.add(btRandom);
    toolBar.add(size);
    toolBar.add(showGrid);
    toolBar.add(new JSeparator(SwingConstants.VERTICAL));
    toolBar.add(btAbout);

    frame.setJMenuBar(toolBar);
    Toolkit.getDefaultToolkit().getScreenSize();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setSize(screenSize);
    Grid grid = new Grid(80, 80);
    Envolver envolver = new Envolver(grid, new SimpleTransition());

    /*grid.setValueAt(150, 150, State.Full);

    grid.setValueAt(152, 150, State.Full);
    grid.setValueAt(152, 151, State.Full);

    grid.setValueAt(154, 152, State.Full);
    grid.setValueAt(154, 153, State.Full);
    grid.setValueAt(154, 154, State.Full);

    grid.setValueAt(156, 153, State.Full);
    grid.setValueAt(156, 154, State.Full);
    grid.setValueAt(156, 155, State.Full);

    grid.setValueAt(157, 154, State.Full);*/

    Random random = new Random();

    for (int x = 0; x < grid.getWidth(); x++) {
      for (int y = 0; y < grid.getHeight(); y++) {
        if (random.nextDouble() <= 0.3125) {
          grid.setValueAt(x, y, State.Full);
        }
      }
    }

    GridPanel panel = new GridPanel(grid);
    JScrollPane scrollPane = new JScrollPane(panel);
    scrollPane.setPreferredSize(screenSize);
    // panel.setPreferredSize(screenSize);
    frame.setLayout(new FormLayout("2dlu, default:grow, 2dlu", "2dlu, default:grow, 2dlu"));
    frame.getContentPane().add(scrollPane, CC.xy(2, 2));

    frame.setVisible(true);
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    Runner runner = new Runner(envolver, frame);

    start.addActionListener(e -> runner.start());
    pause.addActionListener(e -> runner.pause());
    size.addActionListener(e -> new SizeDialog(grid, frame));
    reset.addActionListener(
        e -> {
          runner.pause();
          grid.init(grid.getWidth(), grid.getHeight());
          frame.repaint();
        });

    btRandom.addActionListener(
        e -> {
          String result =
              JOptionPane.showInputDialog(
                  null,
                  "Choose the probability for an filled cell:",
                  "Input",
                  JOptionPane.PLAIN_MESSAGE);
          try {
            if (Double.parseDouble(result) <= 1.0 && Double.parseDouble(result) >= 0) {
              runner.pause();
              grid.init(grid.getWidth(), grid.getHeight(), Double.parseDouble(result));
              frame.repaint();
            }
          } catch (NumberFormatException ex) {
            // ignore
          }
        });

    showGrid.addActionListener(
        e -> {
          panel.setShowGrid(!panel.isShowGrid());
          frame.repaint();
        });

    next.addActionListener(
        e -> {
          envolver.evolve();
          frame.repaint();
        });

    btAbout.addActionListener(
        e -> {
          JOptionPane.showMessageDialog(
              null,
              "For more information about the rules\nlook to the corresponding wikipedia article.\nNote that we do not look at an infinite grid!\nA cell at the border of the grid has less neighbours than cells in the center.",
              "About",
              JOptionPane.INFORMATION_MESSAGE);
        });
  }
  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);

  }