private void saveCurrent() {
    PrintWriter writer = null;

    try {
      writer = new PrintWriter("config.txt", "UTF-8");
      writer.println("PhoneNumbers:");

      for (String s : Main.getEmails()) {
        writer.println(s);
      }

      writer.println("Items:");

      for (Item s : Main.getItems()) {
        writer.println(s.getName() + "," + s.getWebsite());
      }

      results.setText("Current settings have been saved sucessfully.");
    } catch (FileNotFoundException e1) {
      e1.printStackTrace();
    } catch (UnsupportedEncodingException e1) {
      e1.printStackTrace();
    }

    writer.close();
  }
Exemple #2
0
  public void init() {
    add(intitule);
    add(texte);
    add(bouton);
    bouton.addActionListener(this);

    try {
      ORB orb = ORB.init(this, null);
      FileReader file = new FileReader(iorfile.value);
      BufferedReader in = new BufferedReader(file);
      String ior = in.readLine();
      file.close();
      org.omg.CORBA.Object obj = orb.string_to_object(ior);
      annuaire = AnnuaireHelper.narrow(obj);

    } catch (org.omg.CORBA.SystemException ex) {
      System.err.println("Error");
      ex.printStackTrace();
    } catch (FileNotFoundException fnfe) {
      System.err.println(fnfe.getMessage());
    } catch (IOException io) {
      System.err.println(io.getMessage());
    } catch (Exception e) {
      System.err.println(e.getMessage());
    }
  }
Exemple #3
0
  private void onOK() {
    // add your code here
    try {
      PrintWriter pw = new PrintWriter("data\\out.txt");
      pw.println(textField1.getText());
      pw.close();

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
  }
Exemple #4
0
  private Scanner scanFile() {

    Scanner s = null;

    try {
      s = new Scanner(new BufferedReader(new FileReader("./lab3/Liv.xml")));
      s.nextLine();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }

    return s;
  }
  private OutputStream createFile(String fileName) {

    OutputStream outputStream = null;

    File outputFile = new File(fileName);

    try {
      outputStream = new FileOutputStream(outputFile);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }

    return outputStream;
  }
  public static void main(final String[] args) {

    File logdir = new File(LOG_DIR);
    if (!logdir.exists()) logdir.mkdirs();
    File log = new File(logdir, "client.log");
    // redirect all console output to the file
    try {
      PrintStream out = new PrintStream(new FileOutputStream(log, true), true);
      out.format("[%s] ===== Client started =====%n", timestampf.format(new Date()));
      System.setOut(out);
      System.setErr(out);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }

    /* Set up the error handler as early as humanly possible. */
    ThreadGroup g = new ThreadGroup("Haven main group");
    String ed;
    if (!(ed = Utils.getprop("haven.errorurl", "")).equals("")) {
      try {
        final haven.error.ErrorHandler hg = new haven.error.ErrorHandler(new java.net.URL(ed));
        hg.sethandler(
            new haven.error.ErrorGui(null) {
              public void errorsent() {
                hg.interrupt();
              }
            });
        g = hg;
      } catch (java.net.MalformedURLException e) {
      }
    }
    Thread main =
        new HackThread(
            g,
            new Runnable() {
              public void run() {
                main2(args);
              }
            },
            "Haven main thread");
    main.start();
  }
Exemple #7
0
  public static void music(char gameResult) {
    AudioPlayer MGP = AudioPlayer.player;
    AudioStream BGM, BGM1;
    AudioData MD;

    ContinuousAudioDataStream loop = null;

    try {
      InputStream winAudio = new FileInputStream("Audio/winrevised.wav");
      InputStream loseAudio = new FileInputStream("Audio/loserevised.wav");
      BGM = new AudioStream(winAudio);
      BGM1 = new AudioStream(loseAudio);
      if (gameResult == 'w') AudioPlayer.player.start(BGM);
      else if (gameResult == 'l') AudioPlayer.player.start(BGM1);
      // MD = BGM.getData();
      // loop = new ContinuousAudioDataStream(MD);

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException error) {
      error.printStackTrace();
    }
    MGP.start(loop);
  }
  private void savePhone() {

    if (phone.getText().length() == 10) {
      File f = new File("config.txt");
      Scanner sc;

      ArrayList<String> config = new ArrayList<String>();

      try {
        sc = new Scanner(f);

        while (sc.hasNext()) {
          String s = sc.nextLine();
          config.add(s);
        }
        sc.close();

      } catch (FileNotFoundException e2) {
        results.setText("Error reading config.txt");
      }

      int i = 0;

      for (String s : config) {

        if (s.equals("PhoneNumbers:")) {
          break;
        }
        i++;
      }

      if (carriers.getSelectedIndex() == 0) {
        config.add(i + 1, phone.getText() + "@txt.att.net");
      }
      if (carriers.getSelectedIndex() == 1) {
        config.add(i + 1, phone.getText() + "@myboostmobile.com");
      }
      if (carriers.getSelectedIndex() == 2) {
        config.add(i + 1, phone.getText() + "@mobile.celloneusa.com");
      }
      if (carriers.getSelectedIndex() == 3) {
        config.add(i + 1, phone.getText() + "@messaging.nextel.com");
      }
      if (carriers.getSelectedIndex() == 4) {
        config.add(i + 1, phone.getText() + "@tmomail.net");
      }
      if (carriers.getSelectedIndex() == 5) {
        config.add(i + 1, phone.getText() + "@txt.att.net");
      }
      if (carriers.getSelectedIndex() == 6) {
        config.add(i + 1, phone.getText() + "@email.uscc.net");
      }
      if (carriers.getSelectedIndex() == 7) {
        config.add(i + 1, phone.getText() + "@messaging.sprintpcs.com");
      }
      if (carriers.getSelectedIndex() == 8) {
        config.add(i + 1, phone.getText() + "@vtext.com");
      }
      if (carriers.getSelectedIndex() == 9) {
        config.add(i + 1, phone.getText() + "@vmobl.com");
      }

      PrintWriter writer = null;
      try {
        writer = new PrintWriter("config.txt", "UTF-8");
        for (String s : config) {
          writer.println(s);
        }

      } catch (FileNotFoundException e1) {
        e1.printStackTrace();
      } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
      }
      writer.close();
      addPhone();
    } else {
      results.setText("Please add 10 digit cell number.");
    }
  }
Exemple #9
0
  @Override
  public void actionPerformed(ActionEvent action) {
    // Get the file the user wants to use and store it.
    if (action.getSource() == chooseFile) {
      // *sigh* I spent like 10 minutes trying to figure out why my if statement was not working
      // and then I found a semicolon on the end...noob mistake...
      // I had written a paragraph about it to send you too.
      if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {
          System.out.println(
              "File: "
                  + fileChooser.getSelectedFile()
                  + "\nInt: "
                  + fileChooser.showOpenDialog(this));
          file = fileChooser.getSelectedFile();
          inputFile = new Scanner(file);
          if (JOptionPane.showConfirmDialog(
                  this,
                  "Overwrite orginal file?",
                  "Overwrite Confimration",
                  JOptionPane.YES_NO_OPTION)
              == JOptionPane.YES_OPTION) {
            outputFile = new PrintWriter(file);
          } else {
            fileChooser.showOpenDialog(this);
            outputFile = new PrintWriter(fileChooser.getSelectedFile());
          }
          // Enable the buttons now that a file has been chosen.
          sort.setEnabled(true);
          next.setEnabled(true);
        } catch (FileNotFoundException exception) {
          JOptionPane.showMessageDialog(this, "Error: Could not find or open file.");
          exception.printStackTrace();
        }
        // Just in case something weird happens and all those files don't get linked correctly,
        // this will get called and prevent the buttons from being enabled.  Essentially, the user
        // won't see anything.
        catch (NullPointerException exception) {
          sort.setEnabled(false);
          next.setEnabled(false);
          exception.printStackTrace();
        }
      }
    } else if (action.getSource() == sort) {
      // Call the quicksort method to sort, and handle the file writing.
      while (inputFile.hasNextLine()) {
        arrayList.add(inputFile.nextLine());
      }
      inputFile.close();
      temp = new String[arrayList.size()];
      array = arrayList.toArray(temp);
      sorter.quicksort(array, 0, array.length - 1);

      for (int i = 0; i < array.length; i++) {
        outputFile.println(array[i]);
      }
      outputFile.close();
      JOptionPane.showMessageDialog(this, "List successfully sorted.");
    } else if (action.getSource() == next) {
      // Go to the search options.
      buttonPanel.remove(chooseFile);
      buttonPanel.remove(sort);
      buttonPanel.add(search);
      repaint();
      setVisible(true);
    } else if (action.getSource() == exit) {
      // Exit, obviously.
      dispose();
    } else if (action.getSource() == search) {
      // Call the binarySearch method and display the result.
      String searchValue = JOptionPane.showInputDialog("Enter the value to search for:");
      boolean ignoreCase;
      int result;
      if (JOptionPane.showConfirmDialog(
              this,
              "Case-sensitive search?",
              "Case-sensitive",
              JOptionPane.YES_NO_OPTION,
              JOptionPane.QUESTION_MESSAGE)
          == JOptionPane.YES_OPTION) {
        ignoreCase = false;
      } else {
        ignoreCase = true;
      }
      result = searcher.binarySearch(array, searchValue, ignoreCase) + 1;
      if (result == 0) {
        text.setText("The value, " + searchValue + ", was not found.");
      } else {
        text.setText("The value, " + searchValue + ", was found on line: " + result + ".");
      }
    }
  }
  private void doSave() {
    myFile = doRead();
    if (myFile == null) {
      return;
    }

    String name = myFile.getName();
    showMessage("compressing " + name);
    String newName =
        JOptionPane.showInputDialog(this, "Name of compressed file", name + HUFF_SUFFIX);
    if (newName == null) {
      return;
    }
    String path = null;
    try {
      path = myFile.getCanonicalPath();
    } catch (IOException e) {
      showError("trouble with file canonicalizing");
      return;
    }
    int pos = path.lastIndexOf(name);
    newName = path.substring(0, pos) + newName;
    final File file = new File(newName);
    try {
      final FileOutputStream out = new FileOutputStream(file);
      ProgressMonitorInputStream temp = null;
      if (myFast) {
        temp = getMonitorableStream(getFastByteReader(myFile), "compressing bits...");
      } else {
        temp = getMonitorableStream(myFile, "compressing bits ...");
      }
      final ProgressMonitorInputStream pmis = temp;
      final ProgressMonitor progress = pmis.getProgressMonitor();
      Thread fileWriterThread =
          new Thread() {
            public void run() {
              try {
                while (!myFirstReadingDone) {
                  try {
                    sleep(100);
                  } catch (InterruptedException e) {
                    // what to do?
                    HuffViewer.this.showError("Trouble in Thread " + e);
                  }
                }
                myModel.compress(pmis, out, myForce);
              } catch (IOException e) {
                HuffViewer.this.showError("compression exception\n " + e);
                cleanUp(file);
                // e.printStackTrace();
              }
              if (progress.isCanceled()) {
                HuffViewer.this.showError("compression cancelled");
                cleanUp(file);
              }
            }
          };
      fileWriterThread.start();
    } catch (FileNotFoundException e) {
      showError("could not open " + file.getName());
      e.printStackTrace();
    }
    myFile = null;
  }
  private void doDecode() {
    File file = null;
    showMessage("uncompressing");
    try {
      int retval = ourChooser.showOpenDialog(null);
      if (retval != JFileChooser.APPROVE_OPTION) {
        return;
      }
      file = ourChooser.getSelectedFile();
      String name = file.getName();
      String uname = name;
      if (name.endsWith(HUFF_SUFFIX)) {
        uname = name.substring(0, name.length() - HUFF_SUFFIX.length()) + UNHUFF_SUFFIX;
      } else {
        uname = name + UNHUFF_SUFFIX;
      }
      String newName = JOptionPane.showInputDialog(this, "Name of uncompressed file", uname);
      if (newName == null) {
        return;
      }
      String path = file.getCanonicalPath();

      int pos = path.lastIndexOf(name);
      newName = path.substring(0, pos) + newName;
      final File newFile = new File(newName);
      ProgressMonitorInputStream temp = null;
      if (myFast) {
        temp = getMonitorableStream(getFastByteReader(file), "uncompressing bits ...");
      } else {
        temp = getMonitorableStream(file, "uncompressing bits...");
      }
      final ProgressMonitorInputStream stream = temp;

      final ProgressMonitor progress = stream.getProgressMonitor();
      final OutputStream out = new FileOutputStream(newFile);
      Thread fileReaderThread =
          new Thread() {
            public void run() {
              try {
                myModel.uncompress(stream, out);
              } catch (IOException e) {

                cleanUp(newFile);
                HuffViewer.this.showError("could not uncompress\n " + e);
                // e.printStackTrace();
              }
              if (progress.isCanceled()) {
                cleanUp(newFile);
                HuffViewer.this.showError("reading cancelled");
              }
            }
          };
      fileReaderThread.start();
    } catch (FileNotFoundException e) {
      showError("could not open " + file.getName());
      e.printStackTrace();
    } catch (IOException e) {
      showError("IOException, uncompression halted from viewer");
      e.printStackTrace();
    }
  }
Exemple #12
0
  public void jFileChooserActionPerformed(java.awt.event.ActionEvent evt)
      throws FileNotFoundException, IOException {
    File initialBoard = this.jFileChooser.getSelectedFile();
    InputStream inputStream = new FileInputStream(initialBoard);
    Scanner scanner = new Scanner(inputStream);

    if (!initialBoard
        .getName()
        .toLowerCase()
        .contains("initialboard")) { // .toLowerCase().compareTo("initialboard")!=0){
      JOptionPane.showMessageDialog(
          frame, "Wrong File \n Please select InitialBoard.txt", "Eror", JOptionPane.ERROR_MESSAGE);
    } else {

      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

      try {
        in = new BufferedReader(new FileReader(initialBoard.getAbsolutePath()));

      } catch (FileNotFoundException e) {
        System.out.println(e.getCause());
        System.out.println("Error loading initial board");
      }

      int[] boardRows = new int[15];

      // ----------------
      String text = in.readLine();

      StringTokenizer tokenizer = new StringTokenizer(text, " ");

      int boardSize = 0;
      while (tokenizer.hasMoreElements()) {
        boardRows[boardSize] = Integer.parseInt(tokenizer.nextToken());
        boardSize++;
      }

      int[] newBoard = new int[boardSize * boardSize + 1];
      System.arraycopy(boardRows, 0, newBoard, 1, boardSize);

      int index = 0;
      while (in.ready()) {
        index++;
        text = in.readLine();

        tokenizer = new StringTokenizer(text, " ");
        int pos = 0;
        while (tokenizer.hasMoreElements()) {
          pos++;
          newBoard[index * boardSize + pos] = Integer.parseInt(tokenizer.nextToken());
        }
      }

      this.jFrameFileChooser.setVisible(false);
      // this.boardPanel.s

      gameInitialBoard = new Board(newBoard, boardSize);
      gameBoard = new Board(newBoard, boardSize);
      init();
    }
  }