Exemplo n.º 1
0
 public void actionPerformed(ActionEvent e) {
   JFileChooser chooser = new JFileChooser();
   chooser.setDialogTitle("Load");
   int choice = 0;
   do {
     int result = chooser.showOpenDialog(null);
     if (result == JFileChooser.APPROVE_OPTION) {
       file = chooser.getSelectedFile();
       try {
         if (file != null) {
           fileName = file.getCanonicalPath();
           reader = new BufferedReader(new FileReader(fileName));
           String line;
           while ((line = reader.readLine()) != null) {
             myPatternList.add(line);
           }
           //							for(int i=0;i<myPatternList.size();i++) {
           //								responseArea.append(myPatternList.get(i)+"\n");
           //							}
         }
         choice = 2;
         reader.close();
       } catch (IOException c) {
         c.printStackTrace();
         Object[] options = new String[] {"Load New File", "Exit"};
         choice =
             JOptionPane.showOptionDialog(
                 null,
                 "Invalid FileChoosen." + "Would you like to load a new file " + "or exit?",
                 "Options",
                 JOptionPane.YES_NO_OPTION,
                 JOptionPane.ERROR_MESSAGE,
                 null,
                 options,
                 options[0]);
         if (choice == 1) System.exit(0);
       }
     } else if (result == JFileChooser.CANCEL_OPTION) {
       Object[] options = new String[] {"Load Different File", "Exit"};
       choice =
           JOptionPane.showOptionDialog(
               null,
               "Would you like to load a new file " + " or exit?",
               "Options",
               JOptionPane.YES_NO_OPTION,
               JOptionPane.ERROR_MESSAGE,
               null,
               options,
               options[0]);
       if (choice == 1) System.exit(0);
     }
   } while (choice == 0);
 }
Exemplo n.º 2
0
 public void actionPerformed(ActionEvent evt) {
   Object source = evt.getSource();
   if (source == cancelButton) System.exit(0);
   else if (source == prevButton) {
     currentPage--;
     pageChanged();
   } else if (source == nextButton) {
     if (currentPage == pages.length - 1) System.exit(0);
     else {
       currentPage++;
       pageChanged();
     }
   }
 }
Exemplo n.º 3
0
    public void actionPerformed(ActionEvent e) {
      JFileChooser chooser = new JFileChooser();
      chooser.setDialogTitle("SaveAs");
      int choice = 0;
      do {
        int result = chooser.showOpenDialog(null);
        if (result == JFileChooser.APPROVE_OPTION) {
          file = chooser.getSelectedFile();
          try {
            if (file != null) {
              fileName = file.getCanonicalPath();
              printWriter = new PrintWriter(new FileOutputStream(fileName), true);
            }
            printWriter.append(responseArea.getText());
            choice = 2;

          } catch (IOException c) {
            c.printStackTrace();
            Object[] options = new String[] {"Choose New File", "Exit"};
            choice =
                JOptionPane.showOptionDialog(
                    null,
                    "Invalid FileChoosen." + "Would you like to choose a new file " + "or exit?",
                    "Options",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.ERROR_MESSAGE,
                    null,
                    options,
                    options[0]);
            if (choice == 1) System.exit(0);
          }
        } else if (result == JFileChooser.CANCEL_OPTION) {
          Object[] options = new String[] {"Choose Different File", "Exit"};
          choice =
              JOptionPane.showOptionDialog(
                  null,
                  "Would you like to choose a new file " + " or exit?",
                  "Options",
                  JOptionPane.YES_NO_OPTION,
                  JOptionPane.ERROR_MESSAGE,
                  null,
                  options,
                  options[0]);
          if (choice == 1) System.exit(0);
        }
      } while (choice == 0);
      printWriter.flush();
      printWriter.close();
    }
Exemplo n.º 4
0
 /**
  * The ActionListener implementation
  *
  * @param event the event.
  */
 public void actionPerformed(ActionEvent event) {
   String searchText = textField.getText().trim();
   if (searchText.equals("") && !saveAs.isSelected() && (fileLength > 10000000)) {
     textPane.setText("Blank search text is not allowed for large IdTables.");
   } else {
     File outputFile = null;
     if (saveAs.isSelected()) {
       outputFile = chooser.getSelectedFile();
       if (outputFile != null) {
         String name = outputFile.getName();
         int k = name.lastIndexOf(".");
         if (k != -1) name = name.substring(0, k);
         name += ".txt";
         File parent = outputFile.getAbsoluteFile().getParentFile();
         outputFile = new File(parent, name);
         chooser.setSelectedFile(outputFile);
       }
       if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) System.exit(0);
       outputFile = chooser.getSelectedFile();
     }
     textPane.setText("");
     Searcher searcher = new Searcher(searchText, event.getSource().equals(searchPHI), outputFile);
     searcher.start();
   }
 }
Exemplo n.º 5
0
 // Action - vad som händer om man klickar på knappen
 public void actionPerformed(ActionEvent e) {
   // Om man trycker på Avslutaknappen
   if (e.getSource() == exit) {
     // Stänger ner scorelistan och avslutar spelet
     System.exit(0);
   }
 }
Exemplo n.º 6
0
  /** Displayed when the template file is not found in the classpath or the working directory. */
  private void showNoTemplateDialog() {
    final String caption = ResourceHandler.getMessage("notemplate_dialog.caption");
    MessageFormat formatter =
        new MessageFormat(ResourceHandler.getMessage("notemplate_dialog.info"));
    final String info =
        formatter.format(new Object[] {PluginConverter.getDefaultTemplateFileName()});

    JOptionPane.showMessageDialog(this, info, caption, JOptionPane.ERROR_MESSAGE);

    System.exit(0);
  }
Exemplo n.º 7
0
 void getTable() {
   if (chooser == null) {
     File userdir = new File(System.getProperty("user.dir"));
     chooser = new JFileChooser(userdir);
   }
   if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
     file = chooser.getSelectedFile();
     fileLength = file.length();
     setTitle(windowTitle + ": " + file.getAbsolutePath());
     int size = Key.getEncryptionKeySize(this, true);
     key = Key.getEncryptionKey(this, true, size);
     if (key == null) key = defaultKey;
     initCipher();
   } else System.exit(0);
 }
Exemplo n.º 8
0
 // Action Listener interface method
 public void actionPerformed(ActionEvent event) {
   Object target = event.getSource();
   if (target == sineButton) {
     // System.out.println ("AE1 JButton sineButton selected");
   } else if (target == squareButton) {
     // System.out.println ("AE2 JButton squareButton selected");
   } else if (target == sawtoothButton) {
     // System.out.println ("AE3 JButton sawtoothButton selected");
   } else if (target == triangleButton) {
     // System.out.println ("AE4 JButton triangleButton selected");
   } else if (target == exitButton) {
     // System.out.println ("AE5 JButton exitButton selected");
     System.exit(0);
   } else {
   } // if
 } // actionPerformed ()
Exemplo n.º 9
0
  public void actionPerformed(ActionEvent e) {
    String cmd = (e.getActionCommand());

    if (cmd.equals(aboutItem.getText()))
      JOptionPane.showMessageDialog(
          this,
          "Simple Image Program for DB2004\nversion 0.1\nThanks to BvS",
          "About imageLab",
          JOptionPane.INFORMATION_MESSAGE);
    else if (cmd.equals(quitItem.getText())) System.exit(0);
    else if (cmd.equals(openItem.getText())) {
      int returnVal = chooser.showOpenDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
          pic2 = new Picture(chooser.getSelectedFile().getName());
          pic1 = new Picture(pic2.width(), pic2.height());
          lab.setIcon(pic2.getJLabel().getIcon());
          sliderPanel.setVisible(false);
          pack();
          repaint();
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this,
              "Could not open " + chooser.getSelectedFile().getName() + "\n" + ex.getMessage(),
              "Open Error",
              JOptionPane.INFORMATION_MESSAGE);
        }
      }

    } else if (cmd.equals(saveItem.getText())) {
      int returnVal = chooser.showSaveDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
          pic2.save(chooser.getSelectedFile().getName());
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this,
              "Could not write " + chooser.getSelectedFile().getName() + "\n" + ex.getMessage(),
              "Save Error",
              JOptionPane.INFORMATION_MESSAGE);
        }
      }
    }
  }
Exemplo n.º 10
0
  // event handling
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == btnok) {
      PreparedStatement pstm;
      ResultSet rs;
      String sql;
      // if no entries has been made and hit ok button throw an error
      // you can do this step using try clause as well
      if ((tf1.getText().equals("") && (tf2.getText().equals("")))) {
        lblmsg.setText("Enter your details ");
        lblmsg.setForeground(Color.magenta);
      } else {

        try {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          Connection connect = DriverManager.getConnection("jdbc:odbc:student_base");
          System.out.println("Connected to the database");
          pstm = connect.prepareStatement("insert into student_base values(?,?)");
          pstm.setString(1, tf1.getText());
          pstm.setString(2, tf2.getText());
          // execute method to execute the query
          pstm.executeUpdate();
          lblmsg.setText("Details have been added to database");

          // closing the prepared statement  and connection object
          pstm.close();
          connect.close();
        } catch (SQLException sqe) {
          System.out.println("SQl error");
        } catch (ClassNotFoundException cnf) {
          System.out.println("Class not found error");
        }
      }
    }
    // upon clickin button addnew , your textfield will be empty to enternext record
    if (e.getSource() == btnaddnew) {
      tf1.setText("");
      tf2.setText("");
    }

    if (e.getSource() == btnexit) {
      System.exit(1);
    }
  }
Exemplo n.º 11
0
 public void exit() {
   // user is attempting to exit the interpreter.
   // make sure this is what they want to do
   // and check if changes need to be saved.
   int r =
       JOptionPane.showConfirmDialog(
           this,
           new JLabel("Exit Interpreter?"),
           "Confirm Exit",
           JOptionPane.YES_NO_OPTION,
           JOptionPane.QUESTION_MESSAGE);
   if (r == JOptionPane.YES_OPTION) {
     // user still wants to go ahead.
     // if file not saved then prompt to check
     // whether it should be.
     if (!dirty || checkForSave()) {
       System.exit(0);
     }
   }
 }
Exemplo n.º 12
0
  /**
   * Class constructor; creates a new Installer object, displays a JFrame introducing the program,
   * allows the user to select an install directory, and copies files from the jar into the
   * directory.
   */
  public Installer(String args[]) {
    // Inputs are --install-dir INSTALL_DIR
    for (int k = 0; k < args.length; k = k + 2) {

      switch (args[k]) {
        case "--install-dir":
          directory = new File(args[k + 1]);
          System.out.println(directory);
          break;
        case "--port":
          port = Integer.parseInt(args[k + 1]);
          break;
      }
    }

    cp = new Stream();

    // Find the installer program so we can get to the files.
    installer = getInstallerProgramFile();
    String name = installer.getName();
    programName = (name.substring(0, name.indexOf("-"))).toUpperCase();

    // Get the installation information
    thisJava = System.getProperty("java.version");
    thisJavaBits = System.getProperty("sun.arch.data.model") + " bits";

    // Find the ImageIO Tools and get the version
    String javaHome = System.getProperty("java.home");
    File extDir = new File(javaHome);
    extDir = new File(extDir, "lib");
    extDir = new File(extDir, "ext");
    File clib = getFile(extDir, "clibwrapper_jiio", ".jar");
    File jai = getFile(extDir, "jai_imageio", ".jar");
    imageIOTools = (clib != null) && clib.exists() && (jai != null) && jai.exists();
    if (imageIOTools) {
      Hashtable<String, String> jaiManifest = getManifestAttributes(jai);
      imageIOVersion = jaiManifest.get("Implementation-Version");
    }

    // Get the CTP.jar parameters
    Hashtable<String, String> manifest = getJarManifestAttributes("/CTP/libraries/CTP.jar");
    programDate = manifest.get("Date");
    buildJava = manifest.get("Java-Version");

    // Get the util.jar parameters
    Hashtable<String, String> utilManifest = getJarManifestAttributes("/CTP/libraries/util.jar");
    utilJava = utilManifest.get("Java-Version");

    // Get the MIRC.jar parameters (if the plugin is present)
    Hashtable<String, String> mircManifest = getJarManifestAttributes("/CTP/libraries/MIRC.jar");
    if (mircManifest != null) {
      mircJava = mircManifest.get("Java-Version");
      mircDate = mircManifest.get("Date");
      mircVersion = mircManifest.get("Version");
    }

    // Set up the installation information for display
    if (imageIOVersion.equals("")) {
      imageIOVersion = "<b><font color=\"red\">not installed</font></b>";
    } else if (imageIOVersion.startsWith("1.0")) {
      imageIOVersion = "<b><font color=\"red\">" + imageIOVersion + "</font></b>";
    }
    if (thisJavaBits.startsWith("64")) {
      thisJavaBits = "<b><font color=\"red\">" + thisJavaBits + "</font></b>";
    }
    boolean javaOK = (thisJava.compareTo(buildJava) >= 0);
    javaOK &= (thisJava.compareTo(utilJava) >= 0);
    javaOK &= (thisJava.compareTo(mircJava) >= 0);
    if (!javaOK) {
      thisJava = "<b><font color=\"red\">" + thisJava + "</font></b>";
    }

    if (directory == null) exit();

    // Point to the parent of the directory in which to install the program.
    // so the copy process works correctly for directory trees.
    //
    // If the user has selected a directory named "CTP",
    // then assume that this is the directory in which
    // to install the program.
    //
    // If the directory is not CTP, see if it is called "RSNA" and contains
    // the Launcher program, in which case we can assume that it is an
    // installation that was done with Bill Weadock's all-in-one installer for Windows.
    //
    // If neither of those cases is true, then this is already the parent of the
    // directory in which to install the program
    if (directory.getName().equals("CTP")) {
      directory = directory.getParentFile();
    } else if (directory.getName().equals("RSNA")
        && (new File(directory, "Launcher.jar")).exists()) {
      suppressFirstPathElement = true;
    }

    // Cleanup old releases
    cleanup(directory);

    // Get a port for the server.
    if (port < 0) {
      if (checkServer(-port, false)) {
        System.err.println(
            "CTP appears to be running.\nPlease stop CTP and run the installer again.");
        System.exit(0);
      }
    }

    // Now install the files and report the results.
    int count =
        unpackZipFile(installer, "CTP", directory.getAbsolutePath(), suppressFirstPathElement);
    if (count > 0) {
      // Create the service installer batch files.
      updateWindowsServiceInstaller();
      updateLinuxServiceInstaller();

      // If this was a new installation, set up the config file and set the port
      installConfigFile(port);

      // Make any necessary changes in the config file to reflect schema evolution
      fixConfigSchema();

      System.out.println("Installation complete.");
      System.out.println(programName + " has been installed successfully.");
      System.out.println(count + " files were installed.");
    } else {
      System.err.println("Installation failed.");
      System.err.println(programName + " could not be fully installed.");
    }
    if (!programName.equals("ISN") && startRunner(new File(directory, "CTP"))) System.exit(0);
  }
Exemplo n.º 13
0
 private static void exit() {
   System.exit(0);
 }
 public void quit() {
   System.exit(0);
 }
Exemplo n.º 15
0
 /** Hide, reclaim resources, and exit. */
 protected void quit() {
   setVisible(false);
   dispose();
   System.exit(0);
 }
 public void actionPerformed(ActionEvent event) {
   System.exit(0);
 }
Exemplo n.º 17
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (e.getActionCommand().equals("下棋")) {
     audience.setEnabled(false);
     fighter.setEnabled(false);
     begin.setEnabled(true);
     //			JOptionPane.showMessageDialog(null, "下棋");
     System.out.println("下棋");
     try {
       System.out.println("客户端发送下棋指令");
       out66.writeObject("对手");
       out66.flush();
       out66.writeObject(new char[0][0]);
       out66.flush();
       out66.writeObject(new boolean[0][0]);
       out66.flush();
     } catch (IOException e1) {
       e1.printStackTrace();
     }
   }
   if (e.getActionCommand().equals("观看")) {
     submit.setEnabled(false);
     regret.setEnabled(false);
     audience.setEnabled(false);
     fighter.setEnabled(false);
     //			JOptionPane.showMessageDialog(null, "观看");
     System.out.println("观看");
     try {
       out66.writeObject("观众");
       out66.flush();
       out66.writeObject(stateList.get(stateList.size() - 1));
       out66.flush();
       out66.writeObject(takenList.get(takenList.size() - 1));
       out66.flush();
     } catch (IOException e1) {
       e1.printStackTrace();
     }
   }
   /*if (e.getActionCommand().equals("人机对弈"))
   {
   	audience.setEnabled(false);
   	fighter.setEnabled(false);
   	AIPlayer.setEnabled(false);
   	begin.setEnabled(true);
   	JOptionPane.showMessageDialog(null, "人机对弈");
   }*/
   if (e.getActionCommand().equals("发送")) {
     //			JOptionPane.showMessageDialog(null, "发送");
     System.out.println("发送");
     String str = myRole + ": " + " " + jt1.getText() + "\n";
     try {
       out99.writeObject(" " + str);
       out99.flush();
       out99.writeObject(new char[8][8]);
       out99.flush();
       out99.writeObject(new boolean[8][8]);
       out99.flush();
     } catch (IOException e1) {
       e1.printStackTrace();
     }
     jt2.append(str);
     jt1.setText("");
   }
   if (e.getActionCommand().equals("取消")) {
     //			JOptionPane.showMessageDialog(null, "取消");
     System.out.println("取消");
     jt1.setText("");
   }
   if (e.getActionCommand().equals("悔棋")) {
     //			JOptionPane.showMessageDialog(null, "悔棋");
     System.out.println("悔棋");
     try {
       out66.writeObject("请求悔棋");
       out66.flush();
       out66.writeObject(new char[8][8]);
       out66.flush();
       out66.writeObject(new boolean[8][8]);
       out66.flush();
     } catch (IOException e1) {
       e1.printStackTrace();
     }
     // RegretChess();
     // ShowChessNumber();
   }
   if (e.getActionCommand().equals("退出")) {
     int quit =
         JOptionPane.showConfirmDialog(null, "您确定要强制退出吗?", "请确认您的选择", JOptionPane.YES_NO_OPTION);
     if (quit == JOptionPane.YES_OPTION) {
       JOptionPane.showMessageDialog(null, "已强制退出");
       System.exit(0);
     } else return;
   }
   if (e.getActionCommand().equals("开始")) {
     begin.setEnabled(false);
     System.out.println("客户端发送开始指令");
     //			JOptionPane.showMessageDialog(null, "开始");
     try {
       out66.writeObject("请求开始");
       out66.flush();
       out66.writeObject(stateList.get(stateList.size() - 1));
       out66.flush();
       out66.writeObject(takenList.get(takenList.size() - 1));
       out66.flush();
     } catch (IOException e1) {
       e1.printStackTrace();
     }
     Begin();
     if (kind == "黑") {
       for (int i = 0; i < 8; i++)
         for (int j = 0; j < 8; j++)
           if (cell[i][j].taken == false) {
             CheckPlace(cell[i][j]);
             if (canPut) {
               cell[i][j].ChangeBackground();
               canPut = false;
             }
           }
     }
   }
   if (e.getActionCommand().equals("存盘")) {
     //			JOptionPane.showMessageDialog(null, "存盘");
     System.out.println("存盘");
     try {
       System.out.println();
       out.writeObject(stateList);
       out.flush();
       out.close();
     } catch (IOException e1) {
       e1.printStackTrace();
     }
   }
 }
Exemplo n.º 18
0
 private void quitProgram() {
   _task.shutdown();
   System.exit(0);
 }
Exemplo n.º 19
0
 public void windowClosing(WindowEvent evt) {
   System.exit(0);
 }
Exemplo n.º 20
0
 public void windowClosing(WindowEvent e) {
   // System.out.println ("Window closing");
   System.exit(0);
 } // windowClosing ()