Esempio n. 1
0
 public void notifyGenomeServerReachable(boolean reachable) {
   if (loadFromServerMenuItem != null) {
     loadFromServerMenuItem.setEnabled(reachable);
     String tooltip = reachable ? LOAD_GENOME_SERVER_TOOLTIP : CANNOT_LOAD_GENOME_SERVER_TOOLTIP;
     loadFromServerMenuItem.setToolTipText(tooltip);
   }
 }
  /**
   * Constructor creates graphic components and adds them to the JPanel this class inherits from.
   */
  public SlidePuzzleGUI(String solver) {
    // default settings for internal attributes: unsolved 15 puzzle
    nPuzzle = 15;
    solved = false;
    this.solver = solver;
    // create graphics
    // create menu bar with pull down menu for puzzle configuration
    // this needs a menu and a menu item in it
    menuBar = new JMenuBar();
    menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
    // create a menu and add it to the menu bar.
    JMenu menu = new JMenu("Menu");
    menu.setMnemonic(KeyEvent.VK_M);
    // create menu item
    JMenuItem eMenuItem = new JMenuItem("Configuration");
    eMenuItem.setMnemonic(KeyEvent.VK_C);
    eMenuItem.setToolTipText("Set Puzzle Configuration");
    eMenuItem.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent event) {
            createFrame(); // create configuration frame
          }
        });
    menu.add(eMenuItem);
    menuBar.add(menu);

    // create button to solve puzzle in a step by step manner
    // The listener is too lengthy for an anonymous class,
    // code for the listener resides in internal NewGameAction class.
    JButton newGameButton = new JButton("Solve");
    ActionListener gameAction = new NewGameAction();
    newGameButton.addActionListener(gameAction);

    // create control panel that holds the solve button
    JPanel controlPanel = new JPanel();
    controlPanel.setLayout(new FlowLayout());
    controlPanel.add(newGameButton);

    // create graphics panel
    initalPuzzleGraphics = new GraphicsPanel(nPuzzle, PanelType.INITIALPANEL);
    intermediatePuzzleGraphics = new GraphicsPanel(nPuzzle, PanelType.INTERMEDIATEPANEL);
    finalPuzzleGraphics = new GraphicsPanel(nPuzzle, PanelType.GOALPANEL);
    // create and configure a solver
    constructPuzzleSolver();
    // the panel uses a borderlayout
    // the menubar goes on top
    setLayout(new BorderLayout());
    add(menuBar, BorderLayout.NORTH);
    add(controlPanel, BorderLayout.SOUTH);
    add(initalPuzzleGraphics, BorderLayout.WEST);
    add(intermediatePuzzleGraphics, BorderLayout.CENTER);
    add(finalPuzzleGraphics, BorderLayout.EAST);
  }
  private void addMenuToTray() {
    HashMap categories = new HashMap();

    // create menu list
    Iterator plugins = PluginManager.getInstance().getAvailablePlugins();
    plugins = PluginComparator.sortPlugins(plugins);

    while (plugins.hasNext()) {
      Plugin p = (Plugin) plugins.next();

      JMenu category = (JMenu) categories.get(p.getCategory());
      if (category == null) {
        category = new JMenu(p.getCategory());
        categories.put(p.getCategory(), category);

        // copy menu to real one
        if (!p.getCategory().equals("Invisible")) this.trayIcon.add(category);
      }

      ImageIcon icon = new ImageIcon();
      try {
        icon = new ImageIcon(new URL(p.getDirectory() + p.getIcon()));
        icon = new ImageIcon(icon.getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH));
      } catch (Exception e) {
        // error at icon loading
      }

      JMenuItem menu = new JMenuItem(p.getTitle(), icon);
      menu.setName(p.getName());
      menu.setToolTipText(p.getToolTip());
      menu.addActionListener(this);
      category.add(menu);
    }

    this.trayIcon.addSeparator();

    // windows
    this.trayIcon.add(new WindowMenu(this));

    // open main interface
    JMenuItem menu = new JMenuItem(tr("open"));
    menu.setName("org.lucane.applications.maininterface");
    menu.addActionListener(this);
    this.trayIcon.add(menu);

    // exit
    menu = new JMenuItem(tr("exit"));
    menu.setName("exit");
    menu.addActionListener(this);
    this.trayIcon.add(menu);
  }
Esempio n. 4
0
  public storeGUI() {

    // Create Form Frame
    super("Video Store");
    setLayout(new FlowLayout());
    setSize(679, 385);
    setLocation(500, 280);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Menu Bar
    JMenuBar menuBar = new JMenuBar();
    JMenu file = new JMenu("File");
    JMenuItem exit = new JMenuItem("Exit");
    exit.setToolTipText("close");
    exit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            JOptionPane.showMessageDialog(null, "See You!");
            System.exit(0);
          }
        });
    JMenuItem logout = new JMenuItem("Logout");
    logout.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            getContentPane().removeAll();
            JOptionPane.showMessageDialog(null, "logged out!");
            LoginDialog();
          }
        });
    file.add(logout);
    file.add(exit);
    menuBar.add(file);
    setJMenuBar(menuBar);

    lblWelcome = new JLabel("Message", JLabel.LEFT);
    lblWelcome.setFont(new Font("Tahoma", Font.PLAIN, 20));
    lblWelcome.setBounds(0, 0, 336, 25);
    getContentPane().add(lblWelcome);

    // When Frame Loaded
    addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowOpened(WindowEvent e) {
            LoginDialog();
          }
        });
  }
Esempio n. 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);
  }