Ejemplo n.º 1
0
 /**
  * mouseEvent(java.awt.Point, java.lang.boolean, java.lang.boolean)
  *
  * @param java .awt.Point point a point clicked by mouse
  * @param java .lang.boolean ctrlDown true if ctrl key was hit
  * @param java .lang.boolean rightMouse true if the right mouse button was hit
  */
 private void mouseEvent(final Point point, final boolean rightMouse) {
   if (!rightMouse) {
     String name = findTerritoryName(point);
     name = JOptionPane.showInputDialog(this, "Enter the territory name:", name);
     if (name == null || name.trim().length() == 0) {
       return;
     }
     if (m_centers.containsKey(name)
         && JOptionPane.showConfirmDialog(
                 this,
                 "Another center exists with the same name. Are you sure you want to replace it with this one?")
             != 0) {
       return;
     }
     m_centers.put(name, point);
   } else {
     String centerClicked = null;
     for (final Entry<String, Point> cur : m_centers.entrySet()) {
       if (new Rectangle(cur.getValue(), new Dimension(15, 15))
           .intersects(new Rectangle(point, new Dimension(1, 1)))) {
         centerClicked = cur.getKey();
       }
     }
     if (centerClicked != null
         && JOptionPane.showConfirmDialog(this, "Are you sure you want to remove this center?")
             == 0) {
       m_centers.remove(centerClicked);
     }
   }
   repaint();
 }
 @Override
 public void actionPerformed(ActionEvent ae) {
   try {
     if (tableModel instanceof CashOpTableModel) {
       int dialogResponse =
           JOptionPane.showConfirmDialog(
               view.getApplication(),
               Messages.getString("Do you want delete selected cash operation?"),
               Messages.getString("Cancel"),
               JOptionPane.YES_NO_OPTION);
       if (dialogResponse == JOptionPane.YES_OPTION) {
         CashOpTableModel cashOpTableModel = (CashOpTableModel) tableModel;
         cashOpTableModel.removeAt(currentRow);
       }
     } else if (tableModel instanceof ReceiptsTableModel) {
       int dialogResponse =
           JOptionPane.showConfirmDialog(
               view.getApplication(),
               Messages.getString("Do you want to delete selected receipt?"),
               Messages.getString("Cancel"),
               JOptionPane.YES_NO_OPTION);
       if (dialogResponse == JOptionPane.YES_OPTION) {
         ReceiptsTableModel receiptsTableModel = (ReceiptsTableModel) tableModel;
         receiptsTableModel.removeAt(currentRow);
         view.getReceiptItemsTableModel().clean();
         view.getSoldsTableModel().refresh();
       }
     }
   } catch (AppException e) {
     throw new RuntimeException(e);
   }
 }
 @Override
 public void close() {
   if (attributeEditor.hasDataChanged()) {
     int selectedOption =
         JOptionPane.showConfirmDialog(
             this,
             "It seems that you have changed the data without saving it afterwards."
                 + Tools.getLineSeparator()
                 + "Do you still want to proceed and close the editor (changes will be lost)?",
             "Save data file?",
             JOptionPane.YES_NO_OPTION,
             JOptionPane.QUESTION_MESSAGE);
     if (selectedOption == JOptionPane.YES_OPTION) dispose();
   } else if (attributeEditor.hasMetaDataChanged()) {
     int selectedOption =
         JOptionPane.showConfirmDialog(
             this,
             "It seems that you have changed the attribute descriptions without saving an attribute description file (.aml) afterwards."
                 + Tools.getLineSeparator()
                 + "Do you still want to proceed and close the editor (changes will be lost)?",
             "Save attribute description file?",
             JOptionPane.YES_NO_OPTION,
             JOptionPane.QUESTION_MESSAGE);
     if (selectedOption == JOptionPane.YES_OPTION) dispose();
   } else {
     dispose();
   }
 }
Ejemplo n.º 4
0
 @AfterTest
 public void stop() throws Exception {
   JOptionPane.showConfirmDialog(null, "Stop");
   server.stop();
   server = null;
   JOptionPane.showConfirmDialog(null, "Stoped");
 }
Ejemplo n.º 5
0
  /**
   * Shows the file proposal sent from an another user
   *
   * @param fileName The file name
   * @param from Sender Username
   */
  public void showProposal(String fileName, String from) {

    int n = 0; // MAYBE PROBLEM!!!
    if (this.gui.controller.Language == "English") {
      n =
          JOptionPane.showConfirmDialog(
              this,
              "Would you like to get this file : " + fileName + " From" + from + " ?",
              "File Proposal",
              JOptionPane.YES_NO_OPTION);
    } else if (this.gui.controller.Language == "Francais") {
      n =
          JOptionPane.showConfirmDialog(
              this,
              "Voudrez vous telecharger le fichier : " + fileName + " envoyé par " + from + " ?",
              "Proposition De Telechargement",
              JOptionPane.YES_NO_OPTION);
    }

    // System.out.println("n = "+n);
    if (n == 0) {
      try {
        gui.acceptFileTransfer(fileName, from);
      } catch (IOException ex) {
        Logger.getLogger(ChatGUI.class.getName()).log(Level.SEVERE, null, ex);
      }
    } else {
      gui.notAcceptFileTransfer(fileName, from);
    }
  }
Ejemplo n.º 6
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == mApplyBtn) {
     System.out.println("apply");
     return;
   }
   if (e.getSource() == mBgmBtn) {
     GameConfig.isBGM = !GameConfig.isBGM;
     freshBgmBtnText();
     return;
   }
   if (e.getSource() == mSoundBtn) {
     GameConfig.isSound = !GameConfig.isSound;
     freshSoundBtnText();
     return;
   }
   if (e.getSource() == mExitBtn) {
     int result = JOptionPane.showConfirmDialog(this, "确定要退出游戏?", "提示", JOptionPane.YES_NO_OPTION);
     if (result == 0) {
       System.exit(1);
     }
     return;
   }
   if (e.getSource() == mStartBtn) {
     int result = JOptionPane.showConfirmDialog(this, "确定要开始游戏?", "提示", JOptionPane.YES_NO_OPTION);
     if (result == 0) {
       if (!GameConfig.isGameStart) startGame();
       else {
         restartGame();
       }
     }
     return;
   }
 }
Ejemplo n.º 7
0
 private void removeSelectedRecords() {
   if (arbre.getSelectionCount() >= 1 && onlySelectFeuille()) {
     int option = -1;
     if (arbre.getSelectionCount() == 1) {
       option =
           JOptionPane.showConfirmDialog(
               null,
               "Voulez-vous supprimer cet enregistrement ?\n(Notez que la catégorie sera conservée)",
               "Suppression",
               JOptionPane.YES_NO_CANCEL_OPTION,
               JOptionPane.QUESTION_MESSAGE);
     } else {
       option =
           JOptionPane.showConfirmDialog(
               null,
               "Êtes-vous sûr de vouloir ces enregistrements ?\n(Notez que les catégories seront conservées)",
               "Suppression",
               JOptionPane.YES_NO_CANCEL_OPTION,
               JOptionPane.QUESTION_MESSAGE);
     }
     if (option == JOptionPane.OK_OPTION) {
       for (int i = 0; i < arbre.getSelectionPaths().length; i++) {
         if (arbre.getSelectionPaths()[i].getLastPathComponent() instanceof Feuille) {
           try {
             bdd.supprimerEnregistrement(
                 ((Feuille) arbre.getSelectionPaths()[i].getLastPathComponent()).getId());
           } catch (DBException exception) {
             GraphicalUserInterface.popupErreur(
                 "Impossible de supprimer l'enregistrement : " + exception.getMessage());
           }
         }
       }
     }
   }
 }
  public static void main(String[] args) {
    JOptionPane.showMessageDialog(
        null,
        "The object of this game is to get the number 21. Anything over 21, is a bust. Anything below is acceptable, but the goal is 21.");
    int card = new Random().nextInt(20) + 1;
    int hit = new Random().nextInt(10);
    JOptionPane.showMessageDialog(null, "YOU got " + card);
    int hat =
        JOptionPane.showConfirmDialog(null, "Do you want a HIT?", "", JOptionPane.YES_NO_OPTION);
    if (JOptionPane.YES_OPTION == hat) {
      while (JOptionPane.YES_OPTION == hat) {
        hit = new Random().nextInt(10);
        card += hit;
        JOptionPane.showMessageDialog(null, "YOU got " + card);
        JOptionPane.showConfirmDialog(
            null, "Do you want a HIT AGAIN?", "", JOptionPane.YES_NO_OPTION);
        int lat =
            JOptionPane.showConfirmDialog(
                null, "Do you want a HIT?", "", JOptionPane.YES_NO_OPTION);
        if (card > 21) {
          JOptionPane.showMessageDialog(null, "BUST!!!");
        } else if (JOptionPane.NO_OPTION == hat) {

          String stand = JOptionPane.showInputDialog(null, "In the end, YOU got " + card);
        }
      }
    } else if (card > 21) {
      JOptionPane.showMessageDialog(null, "BUST!!!");
    } else if (card <= 21) {
      String stand = JOptionPane.showInputDialog(null, "In the end, YOU got " + card);
      JOptionPane.showMessageDialog(null, "OK!!!");
    }
  }
Ejemplo n.º 9
0
  // Close the window when the close box is clicked
  public void windowClosing(java.awt.event.WindowEvent e) {
    // check for various types of dirty - first table data not written back
    if (cvModel.decoderDirty() || variableModel.decoderDirty()) {
      if (JOptionPane.showConfirmDialog(
              null,
              "Some changes have not been written to the decoder. They will be lost. Close window?",
              "choose one",
              JOptionPane.OK_CANCEL_OPTION)
          == JOptionPane.CANCEL_OPTION) {
        return;
      }
    }
    if (variableModel.fileDirty()) {
      if (JOptionPane.showConfirmDialog(
              null,
              "Some changes have not been written to a configuration file. Close window?",
              "choose one",
              JOptionPane.OK_CANCEL_OPTION)
          == JOptionPane.CANCEL_OPTION) {
        return;
      }
    }

    modePane.dispose();
    // OK, close
    super.windowClosing(e);
  }
Ejemplo n.º 10
0
  // ****************************************
  public void cleanup(List<File> target, String text)
        // ****************************************
      {
    if (target.isEmpty() == true) return;
    int s = target.size();
    int option =
        JOptionPane.showConfirmDialog(
            null,
            s + " " + text + " files will be deleted",
            "Please confirm, file deletion?",
            JOptionPane.OK_CANCEL_OPTION);
    if (option != JOptionPane.OK_OPTION) {
      return;
    }
    List<File> not_deleted = new ArrayList<File>();
    for (File f : target) {
      boolean b = Garbagor.sure_delete(f);
      if (b == false) not_deleted.add(f);
    }
    target.clear();
    target.addAll(not_deleted);
    if (not_deleted.isEmpty() == false) {
      int s2 = not_deleted.size();
      JOptionPane.showConfirmDialog(
          null,
          s2 + " " + text + " files COULD NOT be deleted",
          "This is weird!?",
          JOptionPane.OK_CANCEL_OPTION);
    }

    show_files(target);
  }
Ejemplo n.º 11
0
    /**
     * The drag operation has terminated with a drop on this <code>DropTarget</code>. This method is
     * responsible for undertaking the transfer of the data associated with the gesture. The <code>
     * DropTargetDropEvent</code> provides a means to obtain a <code>Transferable</code> object that
     * represents the data object(s) to be transfered.
     *
     * <p>From this method, the <code>DropTargetListener</code> shall accept or reject the drop via
     * the acceptDrop(int dropAction) or rejectDrop() methods of the <code>DropTargetDropEvent
     * </code> parameter.
     *
     * <p>Subsequent to acceptDrop(), but not before, <code>DropTargetDropEvent</code>'s
     * getTransferable() method may be invoked, and data transfer may be performed via the returned
     * <code>Transferable</code>'s getTransferData() method.
     *
     * <p>At the completion of a drop, an implementation of this method is required to signal the
     * success/failure of the drop by passing an appropriate <code>boolean</code> to the <code>
     * DropTargetDropEvent</code>'s dropComplete(boolean success) method.
     *
     * <p>Note: The actual processing of the data transfer is not required to finish before this
     * method returns. It may be deferred until later.
     *
     * <p>
     *
     * @param dtde the <code>DropTargetDropEvent</code>
     */
    @Override
    @SuppressWarnings("unchecked")
    public void drop(DropTargetDropEvent event) {
      if (event.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        event.acceptDrop(DnDConstants.ACTION_COPY);

        try {
          List<File> files =
              (List<File>) event.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);

          splitMPOFiles(files);

        } catch (IOException e) {
          JOptionPane.showConfirmDialog(
              MPOImageSplitter.this,
              "Could not access the dropped data.",
              "MPOImageSplitter: Drop Failed",
              JOptionPane.DEFAULT_OPTION,
              JOptionPane.INFORMATION_MESSAGE);
        } catch (UnsupportedFlavorException e) {
          JOptionPane.showConfirmDialog(
              MPOImageSplitter.this,
              "Unsupported data flavor.",
              "MPOImageSplitter: Drop Failed",
              JOptionPane.DEFAULT_OPTION,
              JOptionPane.INFORMATION_MESSAGE);
        }
      } else {
        event.rejectDrop();
      }
    }
Ejemplo n.º 12
0
 // ****************************************
 protected boolean double_confirm_delete_file(File f)
       // ****************************************
     {
   int dialogButton =
       JOptionPane.showConfirmDialog(
           null,
           "Please confirm you want to sure-delete file "
               + f.getAbsolutePath()
               + " (WARNING: cannot be undone)",
           "Are you sure?",
           JOptionPane.OK_CANCEL_OPTION,
           JOptionPane.PLAIN_MESSAGE);
   if (dialogButton == JOptionPane.YES_OPTION) {
     if (f.isDirectory() == true) {
       int dialogButton2 =
           JOptionPane.showConfirmDialog(
               null,
               "DANGER: The target is a Folder ! Please confirm you want to sure-delete *recursively* ALL FILES IN THIS FOLDER (cannot be undone)\nIf you dont know what \"recursively\" means DONT click OK!",
               "Are you REALLY REALLY sure?",
               JOptionPane.OK_CANCEL_OPTION,
               JOptionPane.PLAIN_MESSAGE);
       if (dialogButton2 == JOptionPane.YES_OPTION) {
         Show_dialog_box.display("going to sure-delete:" + f.getAbsolutePath());
         return Garbagor.sure_delete(f);
       }
     } else {
       Show_dialog_box.display("going to sure-delete:" + f.getAbsolutePath());
       return Garbagor.sure_delete(f);
     }
   }
   return false;
 }
  public static void main(String[] args) {
    ArrayList<Funcionario> funcionarios = new ArrayList<Funcionario>();

    ControleBonus controle = new ControleBonus();

    int continua = JOptionPane.NO_OPTION;

    do {
      Funcionario f = null;
      int eGerente =
          JOptionPane.showConfirmDialog(
              null, "O Funcionário é " + "Gerente?", "Confirmar", JOptionPane.YES_NO_OPTION);

      double salario =
          Double.parseDouble(JOptionPane.showInputDialog("Informe o salário do Funcionario"));

      if (eGerente == JOptionPane.YES_OPTION) f = new Gerente(salario);
      else f = new Funcionario(salario);

      funcionarios.add(f);

      continua =
          JOptionPane.showConfirmDialog(null, "Continua?", "Confirmar", JOptionPane.YES_NO_OPTION);
    } while (continua == JOptionPane.YES_OPTION);

    for (Funcionario f : funcionarios) {
      controle.soma(f);
    }

    System.out.println("Total de Bonificação dos funcionários: " + controle.getTotal());
  }
Ejemplo n.º 14
0
  @Override
  public void actionPerformed(ActionEvent e) {

    facade.marcheBateau(false);
    int option =
        JOptionPane.showConfirmDialog(
            null,
            "Voulez vous enregistrer le fichier?",
            "Arrêt de la Course",
            JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE);

    if (option == 0) {
      // Reponse oui
      String nom =
          JOptionPane.showInputDialog(
              null,
              "veuillez indiquer un nom ou un pseudo : ",
              " Nom d'utilisateur",
              JOptionPane.QUESTION_MESSAGE);

      if (facade.isFichierCharger()) {

        int optionchargement =
            JOptionPane.showConfirmDialog(
                null,
                "Voulez vous enregistrer le fichier sur le dernier fichier charge?",
                "Arrêt de la Course",
                JOptionPane.YES_NO_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE);

        if (optionchargement == 0) {
          facade.setEnregistrement(nom, facade.getLastchargement());
          facade.setFinCourse();
        } else {
          String fichier =
              JOptionPane.showInputDialog(
                  null, "nom du fichier", "Enregistrer", JOptionPane.QUESTION_MESSAGE);
          facade.setEnregistrement(nom, fichier);
          facade.setFinCourse();
        }
      } else {
        String fichier =
            JOptionPane.showInputDialog(
                null, "nom du fichier", "Enregistrer", JOptionPane.QUESTION_MESSAGE);
        facade.setEnregistrement(nom, fichier);
        facade.setFinCourse();
      }

    } else {
      // Reponse non
      if (option == 1) {
        facade.setFinCourse();
      }
    }
  }
Ejemplo n.º 15
0
 public static boolean showComfirmation(String message, Component parent, int timeout) {
   if (timeout > 0) {
     JLabel msg = new JLabel(String.format(message, timeout));
     new Timer(1000, new TimerListener(msg, message, timeout - 1)).start();
     return JOptionPane.showConfirmDialog(parent, msg, "弹窗", JOptionPane.YES_NO_OPTION)
         == JOptionPane.YES_OPTION;
   } else {
     return JOptionPane.showConfirmDialog(parent, message, "弹窗", JOptionPane.YES_NO_OPTION)
         == JOptionPane.YES_OPTION;
   }
 }
  @Override
  public void actionPerformed(ActionEvent event) {
    String source = event.getActionCommand();
    if (source.equals("open")) {
      if (trap == true) {
        int springTrap = rand.nextInt(100);
        if (springTrap < 70) {
          JOptionPane.showConfirmDialog(null, "You sprung a trap!");
          damge = damge * level;
          currentGame.getPlayer().setHp(currentGame.getPlayer().getHp() - damge);
          frame.dispose();
          currentGame.createCompass();
          currentGame.createPlayerWindow();
          currentGame.createGameWindow();
        } else {
          treasure = treasure * level;
          JOptionPane.showConfirmDialog(null, "You got " + treasure + " gold.");
          currentGame.createCompass();
          currentGame.createPlayerWindow();
          currentGame.createGameWindow();
        } // End if-else
      } else {
        treasure = treasure * level;
        currentGame.getPlayer().setMoney(currentGame.getPlayer().getMoney() + treasure);
        JOptionPane.showConfirmDialog(null, "You got " + treasure + " gold.");
        frame.dispose();
        currentGame.createCompass();
        currentGame.createPlayerWindow();
        currentGame.createGameWindow();
      } // End if-else

    } else if (source.equals("disarm")) {
      int disarmTrap = rand.nextInt(100);
      if (disarmTrap < 50) {
        JOptionPane.showConfirmDialog(null, "You disarmed the trap!");
        xpGained = xpGained * level;
        currentGame.getPlayer().setXp(currentGame.getPlayer().getXp() + xpGained);
        trap = false;
      } else {
        JOptionPane.showConfirmDialog(null, "You sprung a trap!");
        damge = damge * level;
        currentGame.getPlayer().setHp(currentGame.getPlayer().getHp() - damge);
        frame.dispose();
        currentGame.createCompass();
        currentGame.createPlayerWindow();
        currentGame.createGameWindow();
      } // End if-else
    } else if (source.equals("leave")) {
      frame.dispose();
      currentGame.createCompass();
      currentGame.createPlayerWindow();
      currentGame.createGameWindow();
    } // End if-else
  } // End ActionListener
  public void actionPerformed(ActionEvent e) {
    /*
     * The menu is assigned to several menu bars. The listener is kept as
     * a separate class than the listeners already assigned to the actions
     * for the menu when created.
     */
    JMenu menuOfEventTrigger = Application.frame.getJMenuBar().getMenu(1);

    if (e.getSource() == menuOfEventTrigger.getItem(0)) LectureManager.goToFirstPage();
    else if (e.getSource() == menuOfEventTrigger.getItem(1)) LectureManager.goToLastPage();
    else if (e.getSource() == menuOfEventTrigger.getItem(2)) {
      Application.dialogLabel.setText(DialogLabelText.changeLectureMessage);

      byte selectedButton =
          (byte)
              (JOptionPane.showConfirmDialog(
                  null,
                  Application.dialogLabel,
                  "Change Lecture",
                  JOptionPane.YES_NO_OPTION,
                  JOptionPane.QUESTION_MESSAGE));

      if (selectedButton == JOptionPane.YES_OPTION) {
        Application.frame.setJMenuBar(Application.centralProgramMenuBar);

        CardLayout mainPanelLayout = (CardLayout) (Application.mainPanel.getLayout());
        Application.currentPanelName = Application.LECTURE_SELECT_NAME;
        mainPanelLayout.show(Application.mainPanel, Application.currentPanelName);
      }
    }
    // When the user clicks on the button to quit Lecture Mode.
    else if (e.getSource() == menuOfEventTrigger.getItem(3)) {
      Application.dialogLabel.setText(DialogLabelText.quitLectureModeMessage);

      byte selectedButton =
          (byte)
              (JOptionPane.showConfirmDialog(
                  null,
                  Application.dialogLabel,
                  "Quit Lecture Mode",
                  JOptionPane.YES_NO_OPTION,
                  JOptionPane.QUESTION_MESSAGE));

      if (selectedButton == JOptionPane.YES_OPTION) {
        Application.frame.setJMenuBar(Application.centralProgramMenuBar);

        Application.restartMainMenuThread();

        CardLayout mainPanelLayout = (CardLayout) (Application.mainPanel.getLayout());
        Application.currentPanelName = Application.MAIN_MENU_NAME;
        mainPanelLayout.show(Application.mainPanel, Application.currentPanelName);
      }
    }
  }
Ejemplo n.º 18
0
 public void secureAnalysis() {
   int rw = tblItems.getSelectedRow();
   if (rw != -1) {
     int idx = tblItems.convertRowIndexToModel(rw);
     String desc = store.describe(idx);
     if (JOptionPane.showConfirmDialog(frm, desc, "Details", JOptionPane.OK_CANCEL_OPTION)
         == JOptionPane.CANCEL_OPTION) return;
   }
   if (JOptionPane.showConfirmDialog(frm, store.tagDesc(), "Tags", JOptionPane.OK_CANCEL_OPTION)
       == JOptionPane.CANCEL_OPTION) return;
   if (JOptionPane.showConfirmDialog(
           frm, store.storeDesc(), "Storage", JOptionPane.OK_CANCEL_OPTION)
       == JOptionPane.CANCEL_OPTION) return;
 }
Ejemplo n.º 19
0
  private void addCourse() {

    JTextField pf = new JTextField();
    int okCxl =
        JOptionPane.showConfirmDialog(
            null, pf, "Enter Course Name", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    String courseName = null;
    if (okCxl == JOptionPane.OK_OPTION) {
      courseName = new String(pf.getText());
    } else {
      return;
    }
    JComboBox<Person> profList = new JComboBox<Person>();
    profList.addItem(null);
    for (Person p : LoginManager.getPersons()) {
      profList.addItem(p);
    }
    okCxl =
        JOptionPane.showConfirmDialog(
            null,
            profList,
            "Select Professor",
            JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE);
    Person prof = null;
    if (okCxl == JOptionPane.OK_OPTION) {
      prof = (Person) profList.getSelectedItem();
    } else {
      return;
    }
    Course c = new Course(courseName, prof);
    char[] password = null;
    try {
      password =
          PrivateKeyHandler.checkPassword(
              GenerateKeys.getPasswordInput()); // This window shows garbage
      if (password == null) {
        System.err.println("Please enter admin password to apply changes");
        return;
      }
      LoginManager.putCourse(c.getCID(), c);
      enc = LoginManager.save(password);
    } finally {
      if (password != null) {
        for (int i = 0; i < password.length; i++) {
          password[i] = '\0';
        }
      }
    }
  }
Ejemplo n.º 20
0
  /**
   * Queries the user as to whether they would like to save their sessions.
   *
   * @return true if the transaction was ended successfully, false if not (that is, canceled).
   */
  public boolean closeAllSessions() {
    while (existsSession()) {
      SessionEditor sessionEditor = getFrontmostSessionEditor();
      SessionEditorWorkbench workbench = sessionEditor.getSessionWorkbench();
      SessionWrapper wrapper = workbench.getSessionWrapper();

      if (!wrapper.isSessionChanged()) {
        closeFrontmostSession();
        continue;
      }

      String name = sessionEditor.getName();

      int ret =
          JOptionPane.showConfirmDialog(
              JOptionUtils.centeringComp(),
              "Would you like to save the changes you made to " + name + "?",
              "Advise needed...",
              JOptionPane.YES_NO_CANCEL_OPTION);

      if (ret == JOptionPane.NO_OPTION) {
        closeFrontmostSession();
        continue;
      } else if (ret == JOptionPane.CANCEL_OPTION) {
        return false;
      }

      SaveSessionAsAction action = new SaveSessionAsAction();
      action.actionPerformed(
          new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Dummy close action"));

      if (!action.isSaved()) {
        int ret2 =
            JOptionPane.showConfirmDialog(
                JOptionUtils.centeringComp(),
                "This session was not saved. Close session and continue anyway?",
                "Advise needed...",
                JOptionPane.OK_CANCEL_OPTION);

        if (ret2 == JOptionPane.CANCEL_OPTION) {
          return false;
        }
      }

      closeFrontmostSession();
    }

    return true;
  }
Ejemplo n.º 21
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);
        }
      }
    }
  }
Ejemplo n.º 22
0
    @Override
    public void actionPerformed(ActionEvent e) {
      Preferences pref = Preferences.userNodeForPackage(FSFrame.class);
      String saveDirName = pref.get(SAVE_IMAGE_DIR, System.getProperty("user.dir"));

      JFileChooser fileChooser = new JFileChooser(saveDirName);
      int result = fileChooser.showSaveDialog(FSFrame.this);
      if (result != JFileChooser.APPROVE_OPTION) {
        return;
      }
      File file = fileChooser.getSelectedFile();
      if (!file.getName().toLowerCase().endsWith(".png")) {
        file = new File(file.getAbsolutePath() + ".png");
      }
      if (file.exists()) {
        result =
            JOptionPane.showConfirmDialog(
                FSFrame.this, FSResource.getString("file_exists"), "", JOptionPane.YES_NO_OPTION);
        if (result != JOptionPane.YES_OPTION) {
          return;
        }
      }
      pref.put(SAVE_IMAGE_DIR, file.getAbsolutePath());

      BufferedImage image = panel.toImage(drawPmCode);

      try {
        if (drawPmCode) {
          BufferedImage pmCode = createPMCode();
          Graphics g = image.getGraphics();
          Point p =
              panel
                  .getModel()
                  .getPmCodePosition()
                  .getPoint(panel.getSize(), new Dimension(pmCode.getWidth(), pmCode.getHeight()));
          g.drawImage(pmCode, p.x, p.y, image.getHeight() / 2, image.getHeight() / 2, FSFrame.this);
          pmCode.flush();
        }

        ImageIO.write(image, "png", file);
      } catch (IOException ex) {
        JOptionPane.showConfirmDialog(
            FSFrame.this, FSResource.resourceBundle.getString("failed_to_output_file"));
        ex.printStackTrace();
      } finally {
        image.flush();
      }
    }
  private void jButton3ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton3ActionPerformed
    // libera a exclusao apenas se o ArrayList não estiver vazio
    if (RepositorioProdutos.listaProdutos.size() > 0) {

      Produto p = produtosTableModel.getProduto(jTableProduto.getSelectedRow());
      if (p != null) {
        // teste
        System.out.print(p);
        int opcao =
            JOptionPane.showConfirmDialog(
                this, p.getNome(), "Excluir produto?", JOptionPane.YES_NO_OPTION);

        if (opcao == JOptionPane.YES_OPTION) {
          RepositorioProdutos.removerProdutos(p);
          produtosTableModel.atualizarTabela();

        } else if (opcao == JOptionPane.NO_OPTION) {
          System.out.print("exclusão abortada");
        }
      } else if (p == null) {
        // getSelectedRow retorna -1 quando não esta selecionado
        System.out.print(jTableProduto.getSelectedRow());
        JOptionPane.showMessageDialog(this, "Selecione ou pesquise um produto para excluir");
      }
    } else {
      JOptionPane.showMessageDialog(this, "O sistema não possui produtos cadastrados!");
    }
  } // GEN-LAST:event_jButton3ActionPerformed
Ejemplo n.º 24
0
  /** <b> Method that permit to listen a button. </b> */
  @Override
  public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    if (source == btnPlay) {
      dispose();
      TicTacToeChoiceMenu frame = new TicTacToeChoiceMenu(lab5, lab6);
      frame.setVisible(true);
    } else if (source == btnOptions) {
      dispose();
      TicTacToeOptions frame = new TicTacToeOptions();
      frame.setVisible(true);
    } else if (source == btnQuit) {

      int answer =
          JOptionPane.showConfirmDialog(
              null,
              "Do you want back to the main menu ?",
              "Exit Application",
              JOptionPane.YES_NO_OPTION);

      if (answer == JOptionPane.YES_OPTION) {
        GamesMenu frame = new GamesMenu();
        frame.setVisible(true);
      }
      dispose();
    }
  }
Ejemplo n.º 25
0
  // --------------------------------actionQuit---------------------------------
  private void actionQuit() {
    int nResult =
        JOptionPane.showConfirmDialog(
            frame, "Are you sure you wish to quit?", "Are you sure?", JOptionPane.YES_NO_OPTION);

    if (nResult == JOptionPane.YES_OPTION) frame.dispose();
  }
Ejemplo n.º 26
0
  /**
   * Create/Replace a File
   *
   * @param Direct the Directory in which the File is made
   * @param Txt the Text to be written in the file
   */
  public void createFile(String Direct, String Txt) {
    File f = new File(Direct + File_Name);

    if (f.isFile()) { // Check if this file already exists
      if (JOptionPane.showConfirmDialog(
              null, "This file already exists, do you wish to replace it?", "Replace", 0)
          != 0) {
        return;
      }
      // Delete file
      f.delete();
    }

    try {
      // Replace/Create file
      f.createNewFile();
      // If file preference set to "File with displayed text", write text to file
      if (Txt != null) {
        WriteFile(f, Txt);
      }
      Msgs.Type("File created", Display);
    } catch (Exception e) {
      Msgs.Type("Unable to create this file", Display);
    }
  }
Ejemplo n.º 27
0
 public void keyPressed(KeyEvent e) {
   if (e.getKeyCode() == KeyEvent.VK_1) {
     Charge(0);
   } else if (e.getKeyCode() == KeyEvent.VK_2) {
     Charge(1);
   } else if (e.getKeyCode() == KeyEvent.VK_3) {
     Charge(2);
   } else if (e.getKeyCode() == KeyEvent.VK_4) {
     Charge(3);
   } else if (e.getKeyCode() == KeyEvent.VK_D) {
     if (x == 1) {
       int yesorno = 0;
       yesorno = JOptionPane.showConfirmDialog(PracticeFrame.this, "是否要删除本词");
       if (yesorno == JOptionPane.YES_OPTION) DeleteWord(1);
     }
   } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
     if (x == 1) {
       NewPractice();
     } else if (x == 2) {
       NextSpellQuestion();
     }
   } else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
     ChargeSpell();
   }
 }
Ejemplo n.º 28
0
 // Copied from app.ui.controlpanel.ExtruderPanel
 private double confirmTemperature(double target, String limitPrefName, double defaultLimit) {
   double limit = Base.preferences.getDouble("temperature.acceptedLimit", defaultLimit);
   if (target > limit) {
     // Temperature warning dialog!
     int n =
         JOptionPane.showConfirmDialog(
             this,
             "<html>Setting the temperature to <b>"
                 + Double.toString(target)
                 + "\u00b0C</b> may<br>"
                 + "involve health and/or safety risks or cause damage to your machine!<br>"
                 + "The maximum recommended temperature is <b>"
                 + Double.toString(limit)
                 + "</b>.<br>"
                 + "Do you accept the risk and still want to set this temperature?",
             "Danger",
             JOptionPane.YES_NO_OPTION,
             JOptionPane.WARNING_MESSAGE);
     if (n == JOptionPane.YES_OPTION) {
       return target;
     } else if (n == JOptionPane.NO_OPTION) {
       return Double.MIN_VALUE;
     } else { // Cancel or whatnot
       return Double.MIN_VALUE;
     }
   } else {
     return target;
   }
 }
  boolean checkSave() {
    final String currentFileName = EncogWorkBench.getInstance().getCurrentFileName();

    if (EncogWorkBench.getInstance().getCurrentFile() == null) return true;

    if (currentFileName != null
        || EncogWorkBench.getInstance().getCurrentFile().getDirectory().size() > 0) {
      final String f = currentFileName != null ? currentFileName : "Untitled";
      final int response =
          JOptionPane.showConfirmDialog(
              null,
              "Save " + f + ", first?",
              "Save",
              JOptionPane.YES_NO_CANCEL_OPTION,
              JOptionPane.QUESTION_MESSAGE);
      if (response == JOptionPane.YES_OPTION) {
        performFileSave();
        return true;
      } else if (response == JOptionPane.NO_OPTION) {
        return true;
      } else {
        return false;
      }
    }

    return true;
  }
 /** Delete an employee */
 private void deleteEmp() {
   parent.doBlur();
   int sure =
       JOptionPane.showConfirmDialog(
           parent.getView(),
           Messages.getString("EmployeeController.7"),
           Messages.getString("EmployeeController.8"), // $NON-NLS-1$
           JOptionPane.YES_NO_OPTION,
           JOptionPane.INFORMATION_MESSAGE);
   if (sure == JOptionPane.OK_OPTION) {
     // Get Id employee selected
     String empID = view.getTblEmp().getValueAt(view.getTblEmp().getSelectedRow(), 0).toString();
     if (!AccessEmp.getInstance().deleteEmp(Integer.parseInt(empID))) {
       JOptionPane.showMessageDialog(
           parent.getView(),
           Messages.getString("EmployeeController.9") // $NON-NLS-1$
               + Messages.getString("EmployeeController.10"), // $NON-NLS-1$
           Messages.getString("EmployeeController.11"),
           JOptionPane.ERROR_MESSAGE);
     } else {
       JOptionPane.showMessageDialog(
           parent.getView(),
           Messages.getString("EmployeeController.12"),
           Messages.getString("EmployeeController.13"), // $NON-NLS-1$
           JOptionPane.INFORMATION_MESSAGE);
       empModel.removeRow(view.getTblEmp().getSelectedRow());
     }
   }
   tableFocus();
   parent.doBlur();
 }