Пример #1
0
  /**
   * opens the chosen file, reads in the file, and prints out a receipt
   *
   * @param chosenFile
   */
  private void readSource(File chosenFile) {
    String chosenFileName = chosenFile.getName();
    TextFileInput inFile = new TextFileInput(chosenFileName);
    Container myContentPane = jframe.getContentPane();
    // chosenFile TextArea myTextArea = new TextArea();
    myContentPane.add(myTextArea);

    int count = 0;
    float priceTotal = 0.0f;
    Database db = new Database("database2.txt");
    String[] transaction = new String[100];
    String line = inFile.readLine();
    DecimalFormat df = new DecimalFormat("#00.00");
    while (line != null) {
      StringTokenizer tokenized = new StringTokenizer(line, ",");
      String code = tokenized.nextToken();
      float weight = Float.parseFloat(tokenized.nextToken());
      String name;
      float price;

      try {
        name = db.getName(code);

      } catch (ItemNotFoundException e) {
        name = JOptionPane.showInputDialog(null, "Item " + code + " not found. Enter Name: ");
      }
      try {
        price = db.getPrice(code);
      } catch (ItemNotFoundException e) {
        price =
            Float.valueOf(
                JOptionPane.showInputDialog(
                    null, "Price for " + name + " not found. Enter price: "));
      }
      float itemTotal = weight * price;
      priceTotal += itemTotal;
      transaction[count] =
          name + "\t" + price + "\t" + df.format(weight) + "\t $" + df.format(itemTotal);
      count++;
      line = inFile.readLine();
    } // while
    myTextArea.setText("ITEM: \t PRICE\\LB: \t POUNDS: \t TOTAL:");
    myTextArea.append("\n");
    for (int i = 0; i < count; i++) {
      myTextArea.append(transaction[i]);
      myTextArea.append("\n");
    }
    myTextArea.append("\t\t   TOTAL: $" + df.format(priceTotal));
    jframe.setVisible(true);
  } // openFile
Пример #2
0
  // DO NOT call this directly, go through Sysout
  public void printInstructions(String[] instructions) {
    // Clear out any current instructions
    instructionsText.setText("");

    // Go down array of instruction strings

    String printStr, remainingStr;
    for (int i = 0; i < instructions.length; i++) {
      // chop up each into pieces maxSringLength long
      remainingStr = instructions[i];
      while (remainingStr.length() > 0) {
        // if longer than max then chop off first max chars to print
        if (remainingStr.length() >= maxStringLength) {
          // Try to chop on a word boundary
          int posOfSpace = remainingStr.lastIndexOf(' ', maxStringLength - 1);

          if (posOfSpace <= 0) posOfSpace = maxStringLength - 1;

          printStr = remainingStr.substring(0, posOfSpace + 1);
          remainingStr = remainingStr.substring(posOfSpace + 1);
        }
        // else just print
        else {
          printStr = remainingStr;
          remainingStr = "";
        }

        instructionsText.append(printStr + "\n");
      } // while
    } // for
  } // printInstructions()
 // Called in the event thread when done() has terminated, whether
 // by completing or by being cancelled.
 public void done() {
   try {
     textArea.append(get());
     // textArea.append("Done");
   } catch (InterruptedException exn) {
   } catch (ExecutionException exn) {
     throw new RuntimeException(exn.getCause());
   } catch (CancellationException exn) {
   } // (3)
 }
Пример #4
0
 // Item Listener stuff
 public void showMessages(ItemEvent e) {
   int index = 0;
   if (e != null) index = ((Integer) e.getItem()).intValue();
   allmessagesTextArea.setText("");
   TracesSession tS = tracesSessions.elementAt(index);
   for (int i = 0; i < tS.size(); i++) {
     TracesMessage tM = tS.elementAt(i);
     // allmessagesTextArea.setForeground(Color.red);
     // allmessagesTextArea.setFont(new Font ("Dialog", 1, 18));
     allmessagesTextArea.append(
         "Message " + (i + 1) + " from " + tM.getFrom() + " to " + tM.getTo());
     allmessagesTextArea.append("\n\n");
     // allmessagesTextArea.setForeground(Color.black);
     // allmessagesTextArea.setFont(new Font ("Dialog", 1, 14));
     allmessagesTextArea.append(tM.getMessageString());
     allmessagesTextArea.append("\n");
   }
   allmessagesTextArea.select(0, 0);
 }
Пример #5
0
  public void initComponents() {
    /** ******************** The main container *************************** */
    Container container = this.getContentPane();
    container.setLayout(new BorderLayout());
    container.setBackground(Color.black);
    this.setSize(650, 600);
    this.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {}
        });

    /** ************************* MAIN PANEL ******************************* */
    mainPanel = new JPanel();
    // If put to False: we see the container's background
    mainPanel.setOpaque(false);
    mainPanel.setLayout(new BorderLayout());
    container.add(mainPanel, BorderLayout.CENTER);

    allmessagesTextArea = new TextArea();
    allmessagesTextArea.setEditable(false);
    allmessagesTextArea.setFont(new Font("Dialog", 1, 12));
    allmessagesTextArea.setForeground(Color.black);
    allmessagesTextArea.append("Select a session in the list to view its messages");
    mainPanel.add(allmessagesTextArea, BorderLayout.CENTER);

    sessionsList = new List();
    sessionsList.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            showMessages(e);
          }
        });
    sessionsList.setForeground(Color.black);
    sessionsList.setFont(new Font("Dialog", 1, 14));
    mainPanel.add(sessionsList, BorderLayout.WEST);

    okButton = new JButton("  OK  ");
    okButton.setToolTipText("Returns to the main frame");
    okButton.setFont(new Font("Dialog", 1, 16));
    okButton.setFocusPainted(false);
    okButton.setBackground(Color.lightGray);
    okButton.setBorder(new BevelBorder(BevelBorder.RAISED));
    okButton.setVerticalAlignment(SwingConstants.CENTER);
    okButton.setHorizontalAlignment(SwingConstants.CENTER);
    container.add(okButton, BorderLayout.SOUTH);
    okButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            setVisible(false);
          }
        });
  }
Пример #6
0
 // DO NOT call this directly, go through Sysout
 public void displayMessage(String messageIn) {
   messageText.append(messageIn + "\n");
   System.out.println(messageIn);
 }
Пример #7
0
  public void consoleOutput(String word) {
    //		System.out.println(word);
    testtextarea.append(word + newline);
    //		testtextarea.setText(word);

  }
 // (4) Called on the event thread to process results previously
 // published by calls to the publish method.
 public void process(List<String> results) {
   if (isCancelled()) return;
   for (String result : results) textArea.append(result);
 }