public String[] cannotUseRequestedNicknames(Server s) {
   synchronized (_nickLock) {
     if (_interface.getComponent() != null) _interface.getComponent().setEnabled(false);
     if (_frame != null) _frame.setEnabled(false);
     JFrame f = new JFrame();
     f.setLayout(new FlowLayout());
     f.setSize(200, 65);
     f.setTitle("Change nickname to");
     // f.setTitle(getText(IRCTextProvider.GUI_CHANGE_NICK));
     JTextField field = new JTextField(_start.getNick());
     JButton b = new JButton("Ok");
     b.addActionListener(this);
     f.add(field);
     f.add(b);
     f.setVisible(true);
     try {
       _nickLock.wait();
     } catch (InterruptedException ex) {
       // ignore...
     }
     f.setVisible(false);
     f.remove(b);
     f.remove(field);
     f.dispose();
     String[] ans = new String[1];
     ans[0] = field.getText();
     if (_frame != null) _frame.setEnabled(true);
     if (_interface.getComponent() != null) _interface.getComponent().setEnabled(true);
     return ans;
   }
 }
Exemple #2
0
  public void play(int lv) {
    jl.setText("Level " + level);
    Game game = new Game(lv); // An object representing the game
    View view = new View(game); // An object representing the view of the game
    game.newGame();
    view.print();
    gameBoardPanel = view.mainPanel;
    ButtonPanel buttonPanel = new ButtonPanel(game);
    container.add(buttonPanel, BorderLayout.EAST);
    container.add(gameBoardPanel, BorderLayout.WEST);
    mainFrame.pack();

    // Main game loop
    while (true) {

      view.print();
      gameBoardPanel = view.mainPanel;

      // Win/lose conditions
      if (game.isWin()) {
        view.print();
        gameBoardPanel = view.mainPanel;
        int choice;
        choice = JOptionPane.showConfirmDialog(null, "You win!", "", JOptionPane.OK_OPTION);
        if (choice == JOptionPane.OK_OPTION) {
          level++;
          mainFrame.remove(buttonPanel);
          mainFrame.remove(gameBoardPanel);
          play(level);
        }
      }
      if (game.isLose()) {
        view.print();
        gameBoardPanel = view.mainPanel;
        int choice;
        choice =
            JOptionPane.showConfirmDialog(
                null, "You lose!", "Would you like to play again?", JOptionPane.YES_NO_OPTION);
        if (choice == JOptionPane.YES_OPTION) {
          level = 1;
          mainFrame.remove(buttonPanel);
          mainFrame.remove(gameBoardPanel);
          play(level);
        } else {
          System.exit(0);
        }
      }
    }
  }
Exemple #3
0
 public void openInAFrame(boolean on) {
   if (on) {
     if (frame == null) {
       frame = new JFrame("GraphStream");
       frame.setLayout(new BorderLayout());
       frame.add(this, BorderLayout.CENTER);
       frame.setSize(800, 600);
       frame.setLocationRelativeTo(null);
       frame.setVisible(true);
       frame.addWindowListener(this);
       frame.addComponentListener(this);
       frame.addKeyListener(shortcuts);
     } else {
       frame.setVisible(true);
     }
   } else {
     if (frame != null) {
       frame.removeComponentListener(this);
       frame.removeWindowListener(this);
       frame.removeKeyListener(shortcuts);
       frame.remove(this);
       frame.setVisible(false);
       frame.dispose();
     }
   }
 }
Exemple #4
0
 public static void prevPanel() {
   if (currentStack.hasPrev()) {
     myFrame.remove(currentStack.getCurrentPanel());
     myFrame.add(currentStack.getPrev());
     currentStack.getCurrentPanel().setVisible(true);
     myFrame.validate();
     myFrame.repaint();
   }
 }
Exemple #5
0
 public void actionPerformed(ActionEvent ae) {
   JButton button = (JButton) ae.getSource();
   if (button == high) {
     frame.remove(main);
     frame.setContentPane(scores);
   }
   if (button == cred) {
     frame.remove(main);
     frame.setContentPane(credits);
   }
   if (button == start) {
     frame.remove(main);
     frame.setContentPane(story);
   }
   if (button == stor) {
     frame.remove(story);
     frame.setContentPane(tutorial);
   }
   if (button == tutor) {
     frame.remove(main);
     DesktopLauncher a = new DesktopLauncher();
     a.run();
   }
   if (button == returns1) {
     frame.remove(scores);
     frame.setContentPane(main);
   }
   if (button == returns2) {
     frame.remove(credits);
     frame.setContentPane(main);
   }
   if (button == returns3) {
     frame.remove(story);
     frame.setContentPane(main);
   }
   if (button == returns4) {
     frame.remove(tutorial);
     frame.setContentPane(story);
   }
   frame.validate();
   frame.repaint();
 }
Exemple #6
0
 public static void main(String[] args) throws Exception {
   JFrame quizWindow = new JFrame();
   quizWindow.setVisible(true);
   // 1. find an image on the internet, and put its URL in a String variable (from your browser,
   // right click on the image, and select “Copy Image URL”)
   String url1 = "http://cdn.v-harness.com/wp-content/uploads/2015/03/tree.png";
   // 2. create a variable of type "Component" that will hold your image
   JLabel image1;
   // 3. use the "createImage()" method below to initialize your Component
   image1 = new JLabel(createImage(url1));
   image1.setSize(new Dimension(500, 500));
   // 4. add the image to the quiz window
   quizWindow.add(image1);
   // 5. call the pack() method on the quiz window
   quizWindow.pack();
   // 6. ask a question that relates to the image
   String question1 =
       JOptionPane.showInputDialog(
           "How many trees are in the image? Use lowercase letters to spell out the number.");
   // 7. print "CORRECT" if the user gave the right answer
   if (question1.equals("one")) {
     System.out.println("CORRECT");
   }
   // 8. print "INCORRECT" if the answer is wrong
   else {
     System.out.println("INCORRECT");
   }
   // 9. remove the component from the quiz window (you may not see the effect of this until step
   // 12)
   quizWindow.remove(image1);
   // 10. find another image and create it (might take more than one line of code)
   String url2 =
       "https://upload.wikimedia.org/wikipedia/commons/6/67/Inside_the_Batad_rice_terraces.jpg";
   JLabel image2 = new JLabel(createImage(url2));
   // 11. add the second image to the quiz window
   quizWindow.add(image2);
   // 12. pack the quiz window
   quizWindow.pack();
   // 13. ask another question
   String question2 =
       JOptionPane.showInputDialog(
           "What color is the image? Use lowercase letters to spell out the color.");
   // 14+ check answer, say if correct or incorrect, etc.
   if (question2.equals("green")) {
     System.out.println("CORRECT");
   } else {
     System.out.println("INCORRECT");
   }
 }
 @Override
 protected void actionPerformedOverride(final ActionEvent e) throws Exception {
   super.actionPerformedOverride(e);
   final WrapNote wn = new WrapNote(nota);
   try {
     Controllore.invocaComando(new CommandDeleteNota(wn));
   } catch (final Exception e1) {
     Alert.segnalazioneErroreGrave(
         "Nota " + nota.getnome() + " non eliminata: " + e1.getMessage());
   }
   final JFrame f = pNota.getPadre();
   pNota.setVisible(false);
   f.remove(pNota);
   ((MostraNoteView) f).aggiornaVista();
 }
Exemple #8
0
  private void createAndShowGUI(String sendToRight) {
    if (screen == null) {
      screen = new JFrame();
      screen.setLayout(new GridLayout(0, 2));
      screen.setTitle("Spiral Numbers");
      screen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      screen.add(this.makeLeftSide());
    } else {
      screen.remove(right);
    }
    this.setRightSide(sendToRight);
    screen.add(right);

    // Display the window.
    screen.pack();
    screen.setVisible(true);
    screen.repaint();
  }
  private void refreshTable() {

    try {
      if (scrollPane.isAncestorOf(table)) {
        frame.remove(scrollPane);
        scrollPane.remove(table);
        frame.validate();
        frame.repaint();
      }
    } catch (NullPointerException e) {

    }

    DefaultTableModel dm = new DefaultTableModel();
    dm.setDataVector(getValuesArray(), new Object[] {"Name", ""});

    table = new JTable(dm);
    table.getColumn("").setMaxWidth(120);
    table.getColumn("").setCellRenderer(new ButtonRenderer());
    table.getColumn("").setCellEditor(new ButtonEditor(new JCheckBox()));

    table
        .getModel()
        .addTableModelListener(
            new TableModelListener() {

              @Override
              public void tableChanged(TableModelEvent e) {

                int row = e.getFirstRow();
                int column = e.getColumn();
                TableModel model = (TableModel) e.getSource();
                String columnName = model.getColumnName(column);
                String newValue = model.getValueAt(row, column).toString();

                eaArrayList_RenamededFolders.add(
                    new EA_Rename(EA_Utils.getColumnsArrayList().get(row), newValue, row));
              }
            });

    scrollPane = new JScrollPane(table);
    scrollPane.setBounds(10, 11, 371, 206);
    frame.getContentPane().add(scrollPane);
  }
 protected void destroy(final JFrame frame, final GLJPanel glJPanel) {
   try {
     if (SwingUtilities.isEventDispatchThread()) {
       if (null != frame) {
         frame.setVisible(false);
         if (null != glJPanel) {
           frame.getContentPane().remove(glJPanel);
         }
         frame.remove(glJPanel);
       }
       if (null != glJPanel) {
         glJPanel.destroy();
       }
       if (null != frame) {
         frame.dispose();
       }
     } else {
       SwingUtilities.invokeAndWait(
           new Runnable() {
             public void run() {
               if (null != frame) {
                 frame.setVisible(false);
                 if (null != glJPanel) {
                   frame.getContentPane().remove(glJPanel);
                 }
                 frame.remove(glJPanel);
               }
               if (null != glJPanel) {
                 glJPanel.destroy();
               }
               if (null != frame) {
                 frame.dispose();
               }
             }
           });
     }
   } catch (final Exception e) {
     e.printStackTrace();
   }
 }
  /** Dock cytoPanel */
  private void DockCytoPanel() {
    // show ourselves
    showCytoPanel(CytoPanelState.DOCK);

    if (isFloating()) {
      // remove cytopanel from external view
      externalWindow.remove(this);

      // add this cytopanel back to cytopanel container
      if (cytoPanelContainer == null) {
        logger.warn("cytoPanelContainer reference has not been set.");
      }

      cytoPanelContainer.insertCytoPanel(this, compassDirection);

      // dispose of the external window
      externalWindow.dispose();

      // set proper button icon/text
      floatButton.setText("\uF096");
      floatButton.setToolTipText(TOOL_TIP_FLOAT);

      // set float label text
      floatLabel.setText(getTitle());

      // set our new state
      this.cytoPanelState = CytoPanelState.DOCK;

      // re-layout
      this.validate();

      // SOUTH_WEST is used for manualLayout, it is nested in WEST
      if (compassDirection == CytoPanelName.SOUTH_WEST) {
        try {
          this.getParent().getParent().validate();
        } catch (Exception e) {
        }
      }
    }
  }
Exemple #12
0
 public void actionPerformed(ActionEvent e) {
   level = 1;
   mainFrame.remove(gameBoardPanel);
   play(level);
 }
Exemple #13
0
  // menuActionPerformance
  @Override
  public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if (command == "Score") {
      JOptionPane.showMessageDialog(
          null,
          game.player1.name
              + ": "
              + game.player1.score
              + "\n"
              + game.player2.name
              + ": "
              + game.player2.score);
    } else if (command == "Forfeit") {
      int selection = JOptionPane.showConfirmDialog(null, "Are you sure?");
      if (selection == JOptionPane.YES_OPTION) {
        JOptionPane.showMessageDialog(null, currPlayer.name + " forfeit, game restart.");
        game.nextPlayer(currPlayer).score++;
        game.restart(currPlayer);
        window.remove(myPanel);
        myPanel = new BoardWindow();
        window.add(myPanel);
        window.setVisible(true);
        if (game.player1.moveFirst) currPlayer = game.player1;
        else currPlayer = game.player2;
      }
      JOptionPane.showMessageDialog(null, currPlayer.name + " goes first!");

    } else if (command == "Restart") {
      int selection =
          JOptionPane.showConfirmDialog(
              null, currPlayer.name + " wants to restart to game, do you agree?");
      if (selection == JOptionPane.YES_OPTION) {
        JOptionPane.showMessageDialog(null, "Game restart.");
        game.nextPlayer(currPlayer).score++;
        currPlayer.score++;
        game.restart(currPlayer);
        window.remove(myPanel);
        myPanel = new BoardWindow();
        window.add(myPanel);
        window.setVisible(true);
        if (game.player1.moveFirst) currPlayer = game.player1;
        else currPlayer = game.player2;
      } else if (selection == JOptionPane.NO_OPTION) {
        JOptionPane.showMessageDialog(
            null, game.nextPlayer(currPlayer).name + " does not agree to restart.");
      }
      JOptionPane.showMessageDialog(null, currPlayer.name + " goes first!");
    } else if (command == "Undo") {
      int selection =
          JOptionPane.showConfirmDialog(
              null, game.nextPlayer(currPlayer).name + " wants to restart to game, do you agree?");
      if (selection == JOptionPane.YES_OPTION) {
        if (game.move.isEmpty()) return;
        Step step = game.move.pop();
        // First part
        game.gameBoard.spaces[step.rank_i][step.file_i] =
            game.gameBoard.spaces[step.rank_f][step.file_f];
        game.gameBoard.spaces[step.rank_i][step.file_i].setRank(step.rank_i);
        game.gameBoard.spaces[step.rank_i][step.file_i].setFile(step.file_i);
        Icon img = jButtonList[step.rank_f][step.file_f].getIcon();
        jButtonList[step.rank_i][step.file_i].setIcon(img);

        // Second part
        if (step.eatenPiece == null) {
          game.gameBoard.spaces[step.rank_f][step.file_f] = null;
          jButtonList[step.rank_f][step.file_f].setIcon(null);
        } else {
          game.gameBoard.spaces[step.rank_f][step.file_f] = (Piece) step.eatenPiece;
          Image temp = game.gameBoard.spaces[step.rank_f][step.file_f].getBufferedImage();
          jButtonList[step.rank_f][step.file_f].setIcon(new ImageIcon(temp));
        }
        BoardLogic.updatePieces(game.gameBoard);
        currPlayer = game.nextPlayer(currPlayer);
      } else if (selection == JOptionPane.NO_OPTION) {
        JOptionPane.showMessageDialog(null, currPlayer.name + " does not agree to restart.");
      }
    } else if (command == "NewGame") {
      game.restart(currPlayer);
      window.remove(myPanel);
      myPanel = new BoardWindow();
      window.add(myPanel);
      window.setVisible(true);
      if (game.player1.moveFirst) currPlayer = game.player1;
      else currPlayer = game.player2;
      JOptionPane.showMessageDialog(null, currPlayer.name + " goes first!");
    } else if (command == "CustomerPiece") {
      String[] options = {"Rock", "Sentry"};
      int piece =
          JOptionPane.showOptionDialog(
              window,
              "Select customer piece you want to add on the board",
              "Option Dialog Box",
              0,
              JOptionPane.QUESTION_MESSAGE,
              null,
              options,
              null);
      int add_rank = Integer.parseInt(JOptionPane.showInputDialog(null, "Rank (start from 0)"));
      int add_file = Integer.parseInt(JOptionPane.showInputDialog(null, "File (start from 0)"));

      if (!BoardLogic.outOfBounds(game.gameBoard, add_rank, add_file)
          && (game.gameBoard.spaces[add_rank][add_file] == null
              || game.gameBoard.spaces[add_rank][add_file].getColor()
                  != game.nextPlayer(currPlayer).pieceColor)) {
        game.gameBoard.spaces[add_rank][add_file] = null;
        if (piece == 0) {
          BoardLogic.setPiece(
              game.gameBoard, new Rock(), add_rank, add_file, currPlayer.pieceColor);
          jButtonList[add_rank][add_file].setIcon(
              new ImageIcon(game.gameBoard.spaces[add_rank][add_file].getBufferedImage()));
        } else if (piece == 1) {
          BoardLogic.setPiece(
              game.gameBoard, new Sentry(), add_rank, add_file, currPlayer.pieceColor);
          jButtonList[add_rank][add_file].setIcon(
              new ImageIcon(game.gameBoard.spaces[add_rank][add_file].getBufferedImage()));
        }
      } else {
        JOptionPane.showMessageDialog(null, "Can't replace the other player's pieces");
      }

    } else {
      JOptionPane.showMessageDialog(null, "no such option");
    }
  }