private static void badFetch() {
   final JFrame frame = new JFrame("TestFetchWebGui");
   final JPanel outerPanel = new JPanel(), buttonPanel = new JPanel();
   final JButton fetchButton = new JButton("Fetch"), cancelButton = new JButton("Cancel");
   frame.add(outerPanel);
   outerPanel.setLayout(new BorderLayout());
   buttonPanel.setLayout(new GridLayout(2, 1));
   buttonPanel.add(fetchButton);
   buttonPanel.add(cancelButton);
   outerPanel.add(buttonPanel, BorderLayout.EAST);
   final TextArea textArea = new TextArea(25, 80);
   textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
   outerPanel.add(textArea, BorderLayout.WEST);
   fetchButton.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           for (String url : urls) {
             System.out.println("Fetching " + url);
             String page = getPage(url, 200);
             textArea.append(String.format("%-40s%7d%n", url, page.length()));
           }
         }
       });
   frame.pack();
   frame.setVisible(true);
 }
Ejemplo n.º 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()
Ejemplo n.º 3
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);
          }
        });
  }
Ejemplo n.º 4
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
Ejemplo n.º 5
0
  public void actionPerformed(ActionEvent e) {

    chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("C:\\Program Files (x86)\\Tango04\\Dashboards\\Web"));
    chooser.setDialogTitle("Browse...");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);

    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
      textArea.setText("");
      new Exportator().startExporting(chooser.getSelectedFile().getPath(), textArea);
    } else {
      textArea.setText("No Selection");
    }
  }
 // 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)
 }
Ejemplo n.º 7
0
  public AppExport() {
    JLabel label = new JLabel("Choose Dashboard's Web directory:               ");
    add(label);

    JButton go = new JButton("Browse...");
    go.addActionListener(this);
    add(go);

    textArea = new TextArea("", 20, 100, TextArea.SCROLLBARS_NONE);
    textArea.setEditable(false);
    add(textArea);
  }
Ejemplo n.º 8
0
 public VertexInfoDialog(Vertex vertex) {
   v = vertex;
   setTitle("Vertex: " + v.getName());
   Container cp = getContentPane();
   JPanel p = new JPanel();
   p.setLayout(new GridLayout(1, 1));
   opis = new TextArea(v.getInfo());
   opis.setEditable(false);
   p.add(opis, new FlowLayout());
   cp.add(p);
   setSize(200, 300);
   setDefaultCloseOperation(DISPOSE_ON_CLOSE);
 }
  public void actionPerformed(ActionEvent e) {
    JButton b = (JButton) e.getSource();
    if (b == bu) {
      j14 = new JLabel("NEW IMAGE");
      j14.setBounds(840, 200, 300, 300);
      q.add(j14);

      JFileChooser filechooser = new JFileChooser();
      int result = filechooser.showOpenDialog(this);
      f = filechooser.getSelectedFile();
      try {
        String dir1 = f.getAbsolutePath();
        // setText(dir);
        str = dir1;
        // ResizeImage.resize(dir);
        f = new File(dir1);
      } catch (Exception e1) {
      }
      repaint();
      // b=(JButton)e.getSource();

    }
    if (b == ba) {
      try {
        read();
        patient.add(tadd.getText(), tsym.getText(), f, str);
        JOptionPane.showMessageDialog(null, "Patient ID: " + patient.pid + " Record Added");
      } catch (Exception e4) {
        System.out.println("" + e4);
      }
    }
    if (b == bm) {
      try {
        setVisible(false);
      } catch (Exception e4) {
        System.out.println("" + e4);
      }
    }
  }
Ejemplo n.º 10
0
  public void addComponentsToPane() {

    testfield = new JTextField("", 33);
    testfield.addKeyListener(this);

    testtextarea = new TextArea(buffer, 15, 33, TextArea.SCROLLBARS_VERTICAL_ONLY);
    testtextarea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(testtextarea);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.setPreferredSize(new Dimension(600, 200));

    getContentPane().add(testfield, BorderLayout.PAGE_END);
    getContentPane().add(testtextarea, BorderLayout.CENTER);
  }
Ejemplo n.º 11
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);
 }
Ejemplo n.º 12
0
 public void refresh() {
   opis.setText(v.getInfo());
 }
 // (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);
 }
Ejemplo n.º 14
0
  public void consolefunction(String command) {
    command = command.toLowerCase();
    if (command.length() == 5) {
      String a =
          String.valueOf(
              this.world.theBook.findCitizen(
                      this.world.theBook.findAt(
                              Integer.valueOf(command.split(":")[0]),
                              Integer.valueOf(command.split(":")[1]))
                          .block
                          .spots[1]
                          .area
                          .labour[1])
                  .workBlock);
      testtextarea.setText(
          a
              + " "
              + String.valueOf(
                  this.world.theBook.findCitizen(
                          this.world.theBook.findAt(
                                  Integer.valueOf(command.split(":")[0]),
                                  Integer.valueOf(command.split(":")[1]))
                              .block
                              .spots[1]
                              .area
                              .labour[1])
                      .liveBlock));
    } else if (command.equals("clear")) {
      testtextarea.setText("");
    } else if (command.equals("time")) {
    } else if (command.equals("data")) {
      // String test = this.world.theBook.findAt(0, 0).block.spots[2].area.getClass().getName();
      // System.out.println(test);
      // System.out.println(this.world.theBook.findAt(0,
      // 0).block.spots[2].area.getClass().isInstance(new BizRetailandResident()));
      business tempF = new BizFactory();
      business tempR = new BizRetail();
      business tempW = new BizWarehouse();
      business tempB = new BizBank();
      System.out.println("Factory");
      System.out.println(this.world.theBook.totalDeliveriesFrom(tempF));
      System.out.println(this.world.theBook.totalProfit(tempF, this.world.theBook));

      System.out.println("Retail");
      System.out.println(this.world.theBook.totalDeliveriesTo(tempR));
      System.out.println(this.world.theBook.totalProfit(tempR, this.world.theBook));

      System.out.println("Warehouse");
      System.out.println(this.world.theBook.totalSpace(tempW));
      System.out.println(this.world.theBook.totalProfit(tempW, this.world.theBook));

      System.out.println("Banks");
      System.out.println(this.world.theBook.totalSpace(tempB));

      System.out.println("G");
      System.out.println(
          this.world.theBook.totalGIncome(tempF, this.world.theBook)
              + this.world.theBook.totalGIncome(tempR, this.world.theBook)
              + this.world.theBook.totalGIncome(tempW, this.world.theBook));

      System.out.println("Wages total: ");
      System.out.println(
          this.world.theBook.totalWages(tempF, this.world.theBook)
              + this.world.theBook.totalWages(tempR, this.world.theBook)
              + this.world.theBook.totalWages(tempW, this.world.theBook));

      System.out.println("Total ppl: " + (this.world.theBook.nextCitizen - 1));
      System.out.println("Total homeless: " + this.world.theBook.totalHomeless(this.world.theBook));
      System.out.println("Total homes " + (block.nextBlock - 1) * 54);

    } else {
      consoleOutput(command);
    }
  }
  private static void goodFetch() {
    final JFrame frame = new JFrame("TestFetchWebGui");
    final JPanel outerPanel = new JPanel(), buttonPanel = new JPanel();
    final JButton fetchButton = new JButton("Fetch"), cancelButton = new JButton("Cancel");
    frame.add(outerPanel);
    outerPanel.setLayout(new BorderLayout());
    buttonPanel.setLayout(new GridLayout(2, 1));
    buttonPanel.add(fetchButton);
    buttonPanel.add(cancelButton);
    outerPanel.add(buttonPanel, BorderLayout.EAST);
    final TextArea textArea = new TextArea(25, 80);
    textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
    outerPanel.add(textArea, BorderLayout.WEST);

    // (2) Add a progress bar
    JProgressBar progressBar = new JProgressBar(0, 100);
    outerPanel.add(progressBar, BorderLayout.SOUTH);

    // (1) Use a background thread, not the event thread, for work
    ArrayList<DownloadWorker> dw = new ArrayList<>();
    AtomicInteger count = new AtomicInteger();

    fetchButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            dw.clear();
            count.set(0);
            progressBar.setValue(0);

            for (String url : urls) {
              DownloadWorker downloadTask = new DownloadWorker(textArea, url, count);
              dw.add(downloadTask);
            }

            for (DownloadWorker dlw : dw) {
              dlw.execute();
              dlw.addPropertyChangeListener(
                  new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent e) {
                      if ("progress".equals(e.getPropertyName())) {
                        progressBar.setValue((Integer) e.getNewValue());
                      }
                    }
                  });
            }
          }
        });

    // (3) Enable cancellation
    cancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            for (DownloadWorker dlw : dw) {
              dlw.cancel(false);
            }
            textArea.append("Cancelled\n");
          }
        });
    frame.pack();
    frame.setVisible(true);
  }
  DoctorInfomodify() {
    super("Doctor Information");

    setSize(1200, 750);
    setLocationRelativeTo(null);
    setLayout(null);

    lmain = new JLabel("Doctor Information");
    lmain.setBounds(440, 35, 107, 15);
    add(lmain);

    ldi = new JLabel("Doctor Information");
    ldi.setBounds(40, 70, 120, 15);
    add(ldi);

    lname = new JLabel("Name :");
    lname.setBounds(104, 97, 70, 25);
    add(lname);

    tfname = new JTextField(30);
    tfname.setBounds(270, 97, 250, 20);
    add(tfname);

    ladd = new JLabel("Address :");
    ladd.setBounds(104, 138, 70, 15);
    add(ladd);

    taadd = new TextArea();
    taadd.setBounds(270, 138, 250, 100);
    add(taadd);

    ltel = new JLabel("Contact :");
    ltel.setBounds(575, 138, 50, 25);
    add(ltel);

    ldid = new JLabel("Doctor ID:");
    ldid.setBounds(570, 97, 70, 25);
    add(ldid);

    tfdid = new JTextField(30);
    tfdid.setBounds(643, 97, 50, 20);
    add(tfdid);

    tftel = new JTextField(30);
    tftel.setBounds(640, 138, 200, 20);
    add(tftel);
    settings.Numvalidator(tftel);

    ldspec = new JLabel("Specialization :");
    ldspec.setBounds(104, 310, 100, 25);
    add(ldspec);

    taspecial = new TextArea();
    taspecial.setBounds(270, 310, 250, 100);
    add(taspecial);

    lwork = new JLabel("Working hours :");
    lwork.setBounds(570, 310, 100, 15);
    add(lwork);

    lworkfrom = new JLabel("From :");
    lworkfrom.setBounds(670, 305, 37, 25);
    add(lworkfrom);

    tfworkf = new JTextField(30);
    tfworkf.setBounds(710, 310, 30, 20);
    add(tfworkf);
    settings.Numvalidator(tfworkf);

    lworkto = new JLabel("to :");
    lworkto.setBounds(747, 305, 20, 25);
    add(lworkto);

    tfworkt = new JTextField(30);
    tfworkt.setBounds(775, 310, 30, 20);
    add(tfworkt);
    settings.Numvalidator(tfworkt);

    bsub = new JButton("SEARCH", new ImageIcon("images/search.png"));
    bsub.setBounds(250, 643, 110, 30);
    add(bsub);

    bclr = new JButton("CLEAR", new ImageIcon("images/LOGGOFF.PNG"));
    bclr.setBounds(390, 643, 100, 30);
    add(bclr);

    bmod = new JButton("MODIFY", new ImageIcon("images/modify.png"));
    bmod.setBounds(530, 643, 100, 30);
    add(bmod);

    bback = new JButton("BACK", new ImageIcon("images/restore.png"));
    bback.setBounds(700, 643, 100, 30);
    add(bback);

    try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      cn = DriverManager.getConnection("Jdbc:Odbc:doc");
    } catch (Exception e) {
      System.out.println(e);
    }

    bclr.addActionListener(new clear());
    bsub.addActionListener(new submit());
    bmod.addActionListener(new modify());
    bback.addActionListener(new back());

    setVisible(true);
  }
  public void focusLost(FocusEvent e) {
    int id = 0;
    boolean res = false;
    JTextField t = (JTextField) e.getSource();
    if (t == tpid) {
      try {
        id = Integer.parseInt(tpid.getText());
        res = patient.psearch(id);
      } catch (Exception e1) {
      }

      if (res) {
        int no, ag = 0, fee = 0;
        String pfn = "",
            bg = "",
            pmn = "",
            dt1 = "",
            pln = "",
            add = "",
            sym = "",
            dn = "",
            dig = "",
            cn = "",
            gender = "",
            wgt = "";
        try {
          dt1 = patient.rs.getString(1);
          no = patient.rs.getInt(2);
          pfn = patient.rs.getString(3);
          pmn = patient.rs.getString(4);
          pln = patient.rs.getString(5);
          gender = patient.rs.getString(6);
          ag = patient.rs.getInt(7);
          wgt = patient.rs.getString(8);
          add = patient.rs.getString(9);
          cn = patient.rs.getString(10);
          dn = patient.rs.getString(11);
          sym = patient.rs.getString(12);
          dig = patient.rs.getString(13);
          fee = patient.rs.getInt(14);
          bg = patient.rs.getString(15);
          dir = patient.rs.getString(17);

          s = dir;
          repaint();
          j13 = new JLabel("OLD IMAGE");
          j13.setBounds(840, 5, 300, 300);
          JLabel j12 =
              new JLabel("OLD PHOTO") {
                public void paint(Graphics g) {
                  ImageIcon ic = new ImageIcon(s);
                  Image img = ic.getImage();
                  g.drawImage(img, 0, 0, 150, 150, this);
                }
              };

          //	q.flushAll()

          /*ImageIcon ic=new ImageIcon(dir);
          JLabel j12=new JLabel("",ic,JLabel.CENTER);*/
          j12.setBounds(670, 70, 300, 300);
          //	image.setBounds(700,300,100,100);

          q.add(j12);
          q.add(j13);
          repaint();
          System.out.println("8743t32874" + dir);
        } catch (Exception e2) {
        }
        if (gender.equals("Male")) cm.setState(true);
        else cf.setState(true);
        tdt.setText(dt1);
        tpfnm.setText(pfn);
        tpmnm.setText(pmn);
        tplnm.setText(pln);
        tage.setText("" + ag);
        tfee.setText("" + fee);
        tadd.setText(add);
        tdig.setText(dig);
        tdnm.setText(dn);
        tsym.setText(sym);
        tcno.setText(cn);
        twt.setText(wgt);
        tbg.setText(bg);

        // cm.setState(set1State());
        // cf.setSelectedCheckbox(gender);
        ba.setEnabled(false);
        bm.setEnabled(true);
        bd.setEnabled(true);
      } else {
        if (id == 0) {
          bl.setEnabled(true);
          ba.setEnabled(false);
        } else ba.setEnabled(true);
        bm.setEnabled(false);
        bd.setEnabled(false);
      }
    }
  }
Ejemplo n.º 18
0
  public void consoleOutput(String word) {
    //		System.out.println(word);
    testtextarea.append(word + newline);
    //		testtextarea.setText(word);

  }
Ejemplo n.º 19
0
 private void clearData() {
   tfSourc.setText("");
   tfSourc_6.setText("");
   taDictionary.setText("");
   // tfWordSize.setText("");
 }
Ejemplo n.º 20
0
  @Override
  public void actionPerformed(ActionEvent actionEvent) {
    Object obj = actionEvent.getSource();

    if (obj == btFindPat) {

      testpanel.removeAll();
      validate();
      repaint();
      if (taDictionary.getText().isEmpty()) {
        JOptionPane.showMessageDialog(
            frame, "Please load words so they appear in Text Area before Finding Path. ");

      } else if ((tfSourc.getText().isEmpty()) || (tfSourc_6.getText().isEmpty())) {
        JOptionPane.showMessageDialog(
            frame, "Please enter Source and Destination words before Finding Path. ");
      } else if (testpanel.getComponents().length != 0) {
        JOptionPane.showMessageDialog(frame, "Please clear results before continuing.");
      } else {
        wordLadder.findPath(
            tfSourc.getText(), tfSourc_6.getText(), Integer.parseInt(tfWordSize.getText()));
        lblFindPat.setText(
            "Time to find Path: " + String.valueOf(wordLadder.getTimeForPath()) + " milliseconds");
        lblCos.setText("Cost of Path: " + String.valueOf(wordLadder.g.getCost()));
        results = wordLadder.getResults();
        Collections.reverse(results);
        int x = 10;
        int y = 20;

        for (String s : results) {
          x += 20;
          y += 20;
          JLabel _lbl = new JLabel(s);
          _lbl.setLocation(x, y);
          _lbl.setSize(100, 26);

          if (results.indexOf(s) == 0) {
            _lbl.setForeground(new Color(-14646771));
          } else if (results.indexOf(s) == (results.size() - 1)) {
            _lbl.setForeground(new Color(-8254711));
          } else {
            _lbl.setForeground(new Color(-16777216));
          }
          testpanel.add(_lbl);
          testpanel.repaint();
        }
        if (wordLadder.g.getCost() == 0) {
          // if (wordLadder.g.getGraphError() != null){
          JLabel _lbl = new JLabel(wordLadder.g.getGraphError());
          _lbl.setLocation(x, y);
          _lbl.setSize(100, 26);
          testpanel.add(_lbl);
          testpanel.repaint();
          // }

        }
      }
      /*if (taDictionary.getText().isEmpty()){
      wordLadder = new WordLadder(tfFilePat.getText(), tfSourc.getText(), tfSourc_6.getText());
       }else if (!taDictionary.getText().isEmpty()){
          ArrayList<String> taList = new ArrayList<String>();
          StringTokenizer stringTokenizer = new StringTokenizer(taDump, "\t\n\r\f,\"");
          while (stringTokenizer.hasMoreTokens()) {
              String token = stringTokenizer.nextToken();
              taList.add(token);
          }
        */
      // }
    }

    if (obj == btLoadFil) {
      clearData();
      // wordLadder.setWords_size(Integer.parseInt(tfWordSize.getText()));
      // String size = tfWordSize.getText();
      // int intSize = Integer.parseInt(size);
      // WordLadderGUI.showMessage("Loading words of" + tfWordSize.getText() + " characters from
      // file: " + tfFilePat.getText(), Color.GREEN, Color.GREEN);
      lblIndexing1.setText("Indexing...");
      System.out.println(
          "Loading words of "
              + tfWordSize.getText()
              + " characters from file: "
              + tfFilePat.getText());
      wordLadder = new WordLadder(tfFilePat.getText(), Integer.parseInt(tfWordSize.getText()));
      // wordLadder.
      guiDictionary = new WordCollection(wordLadder.getWordList());
      WordLadderGUI.showMessage(
          "Displaying "
              + wordLadder.getWordList().size()
              + " words from file with length of "
              + tfWordSize.getText(),
          Color.GREEN,
          Color.GREEN);
      System.out.println(
          "Displaying "
              + wordLadder.getWordList().size()
              + " words from file with length of "
              + tfWordSize.getText());
      taDictionary.setText(guiDictionary.toString());
      lblIndexing1.setText("Indexing... done.");
      lblDictCoun.setText("Words in Dictionary = " + wordLadder.getWordList().size() + " words");
      wordLadder.buildGraph();
      System.out.println("Graph Built");
      lblProgres.setText("Time to Build Graph: " + wordLadder.getTimeForGraph() + " milliseconds");
    }

    if (obj == btLoadTextFiel) {
      wordLadder.setWords_size(Integer.parseInt(tfWordSize.getText()));
      String taDump = taDictionary.getText();
      System.out.println("Loading Words from Text Area");
      lblIndexing1.setText("Indexing...");
      ArrayList<String> taList = new ArrayList<String>();
      StringTokenizer stringTokenizer = new StringTokenizer(taDump, "\t\n\r\f,\"");
      while (stringTokenizer.hasMoreTokens()) {
        String token = stringTokenizer.nextToken();
        taList.add(token);
      }
      guiDictionary = new WordCollection();
      guiDictionary.setWords(taList);
      wordLadder = new WordLadder(taList);
      WordLadderGUI.showMessage(
          "Loading " + wordLadder.getWordList().size() + " words from Text Field",
          Color.GREEN,
          Color.GREEN);
      lblIndexing1.setText("Indexing... done.");
      lblDictCoun.setText("Words in Dictionary = " + wordLadder.getWordList().size() + " words");
      wordLadder.buildGraph();
      System.out.println("Graph Built");
      lblProgres.setText("Time to Build Graph: " + wordLadder.getTimeForGraph() + " milliseconds");
    }
    if (obj == btClear) {
      testpanel.removeAll();
      testpanel.validate();
      testpanel.repaint();
      wordLadder = null;
      lblCos.setText("Cost of Path: 0.0");
      lblCos.repaint();
      lblDictCoun.setText("Words in Dictionary = 0 words");
      lblFindPat.setText("Time to find Path: 0 milliseconds");
      tfSourc.setText("");
      tfSourc_6.setText("");
      taDictionary.setText("");
      results = null;
      lblProgres.setText("Time to Build Graph: 0 milliseconds");
    }
  }
Ejemplo n.º 21
0
 public void itemStateChanged(ItemEvent e) {
   msg = "currnet selection ";
   msg += cbg.getSelectedCheckbox().getLabel();
   l.setText(msg);
 }
Ejemplo n.º 22
0
  void setupGUI() {
    taDictionary = new TextArea();
    taDictionary.setLocation(0, 0);
    taDictionary.setSize(106, 567);
    taDictionary.setBackground(new Color(-1));
    taDictionary.setText("");
    taDictionary.setRows(5);
    taDictionary.setColumns(1);
    getContentPane().add(taDictionary);

    tfSourc = new TextField();
    tfSourc.setLocation(224, 90);
    tfSourc.setSize(266, 25);
    tfSourc.setBackground(new Color(-1));
    tfSourc.setText("");
    tfSourc.setColumns(10);
    getContentPane().add(tfSourc);

    lblSourc = new Label();
    lblSourc.setLocation(106, 90);
    lblSourc.setSize(119, 25);
    lblSourc.setText("Source Word:");
    getContentPane().add(lblSourc);
    /*
    lblDestinatio = new Label();
    lblDestinatio.setLocation(106,97);
    lblDestinatio.setSize(119,25);
    lblDestinatio.setText("Destination Wor");
    getContentPane().add(lblDestinatio);
       */

    lblDestinatio = new Label();
    lblDestinatio.setLocation(106, 120);
    lblDestinatio.setSize(119, 25);
    lblDestinatio.setText("Destination Word:");
    getContentPane().add(lblDestinatio);

    lblWordSize = new Label();
    lblWordSize.setLocation(106, 27); // 106,120
    lblWordSize.setSize(119, 25);
    lblWordSize.setText("Word Size:");
    getContentPane().add(lblWordSize);

    tfWordSize = new TextField();
    tfWordSize.setLocation(224, 27); // 224,120
    tfWordSize.setSize(263, 25);
    tfWordSize.setBackground(new Color(-1));
    tfWordSize.setText("5");
    tfWordSize.setColumns(10);
    getContentPane().add(tfWordSize);

    tfSourc_6 = new TextField();
    tfSourc_6.setLocation(226, 120);
    tfSourc_6.setSize(263, 25);
    tfSourc_6.setBackground(new Color(-1));
    tfSourc_6.setText("");
    tfSourc_6.setColumns(10);
    getContentPane().add(tfSourc_6);

    lblFileNam = new Label();
    lblFileNam.setLocation(104, 0);
    lblFileNam.setSize(119, 25);
    lblFileNam.setText("FilePath:");
    getContentPane().add(lblFileNam);

    tfFilePat = new TextField();
    tfFilePat.setLocation(224, 0);
    tfFilePat.setSize(266, 25);
    tfFilePat.setBackground(new Color(-1));

    // OS Detection
    if (System.getProperty("os.name").startsWith("Windows")) {
      // includes: Windows 2000,  Windows 95, Windows 98, Windows NT, Windows Vista, Windows XP
      tfFilePat.setText("c:\\ics340\\words.txt");
      System.out.println("Detected Windows: " + System.getProperty("os.name"));
    } else {
      tfFilePat.setText("/Users/jasonedstrom/ics340/d1.txt");
      System.out.println("Detected Mac OS X: " + System.getProperty("os.name"));
    }

    tfFilePat.setColumns(10);
    getContentPane().add(tfFilePat);

    btLoadTextFiel = new JButton();
    btLoadTextFiel.setLocation(108, 50); // 108,27
    btLoadTextFiel.setSize(198, 32);
    btLoadTextFiel.setText("Load Words from Text Field");
    getContentPane().add(btLoadTextFiel);

    btLoadFil = new JButton();
    btLoadFil.setLocation(306, 50); // 306,27
    btLoadFil.setSize(183, 32);
    btLoadFil.setText("Load Words from File");
    getContentPane().add(btLoadFil);

    btFindPat = new JButton();
    btFindPat.setLocation(106, 160);
    btFindPat.setSize(384, 38);
    btFindPat.setText("Find Path");
    getContentPane().add(btFindPat);

    lblDictCoun = new JLabel();
    lblDictCoun.setLocation(108, 513);
    lblDictCoun.setSize(300, 27);
    lblDictCoun.setForeground(new Color(-65536));
    lblDictCoun.setText("Words in Dictionary = 0 words");
    getContentPane().add(lblDictCoun);

    lblIndexing1 = new JLabel();
    lblIndexing1.setLocation(107, 454);
    lblIndexing1.setSize(130, 27);
    lblIndexing1.setForeground(new Color(-16777216));
    lblIndexing1.setText("");
    getContentPane().add(lblIndexing1);

    lblFindPat = new JLabel();
    lblFindPat.setLocation(108, 540);
    lblFindPat.setSize(250, 27);
    lblFindPat.setForeground(new Color(-14646771));
    lblFindPat.setText("Time to find Path: 0 milliseconds");
    getContentPane().add(lblFindPat);

    lblCos = new JLabel();
    lblCos.setLocation(360, 540);
    lblCos.setSize(175, 27);
    lblCos.setForeground(new Color(-16777216));
    lblCos.setText("Cost of Path: 0.0");
    getContentPane().add(lblCos);

    lblProgres = new JLabel();
    lblProgres.setLocation(108, 484);
    lblProgres.setSize(371, 26);
    lblProgres.setForeground(new Color(-14646771));
    lblProgres.setText("Time to Build Graph: 0 milliseconds");
    getContentPane().add(lblProgres);

    testpanel = new JPanel();
    testpanel.setLocation(106, 200);
    testpanel.setSize(350, 200);
    testpanel.setForeground(new Color(-14646771));
    // testpanel.setText("Test Location");
    getContentPane().add(testpanel);

    btClear = new JButton();
    btClear.setLocation(355, 513);
    btClear.setSize(125, 25);
    btClear.setText("Clear Results");
    getContentPane().add(btClear);

    // add actionlisteners to buttons
    btFindPat.addActionListener(this);
    btLoadTextFiel.addActionListener(this);
    btLoadFil.addActionListener(this);
    btClear.addActionListener(this);

    setTitle("WordLadderGUI");
    setSize(500, 600);
    setVisible(true);
    setResizable(false);
  }
  public patientAdd(String s) {
    super(s);
    image =
        new JLabel() {
          public void paint(Graphics g) {
            ImageIcon ic = new ImageIcon(str);
            Image img = ic.getImage();
            g.drawImage(img, 0, 0, 150, 150, this);
          }
        };

    image.setBounds(670, 270, 300, 300);
    bu = new JButton("UPLOAD");
    bu.setBounds(700, 230, 100, 20);
    bu.addActionListener(this);
    //	q.add(bu);

    ldt = new JLabel("Date");
    lpid = new JLabel("Patient ID");
    lpnm = new JLabel("Patient Name");
    lgen = new JLabel("Gender");
    lbg = new JLabel("Blood Group");
    lage = new JLabel("Age");
    lwt = new JLabel("Weight                                          Kg");
    ladd = new JLabel("Address");
    lcno = new JLabel("Cont. no.");
    ldnm = new JLabel("Doctor Name            Dr.");
    lsym = new JLabel("Symptoms");
    ldig = new JLabel("Diagnosis");
    lfee = new JLabel("Fee                            Rs.");
    cbg = new CheckboxGroup();
    cm = new Checkbox("Male", cbg, false);
    cm.addItemListener(this);
    cf = new Checkbox("Female", cbg, false);
    cf.setState(true);
    cf.addItemListener(this);
    tdt = new JTextField(15);
    tpid = new JTextField(6);
    tpid.addFocusListener(this);
    tpfnm = new JTextField("first");
    tpmnm = new JTextField("middle");
    tplnm = new JTextField("last");
    tage = new JTextField(4);
    tage.addFocusListener(this);
    tbg = new JTextField(6);
    twt = new JTextField(5);
    tadd = new TextArea(patient.addr);
    tcno = new JTextField(20);
    tdnm = new JTextField(20);
    tsym = new TextArea();

    tdig = new JTextField(20);
    tfee = new JTextField(6);
    tfee.addFocusListener(this);
    ba = new JButton("ADD");
    ba.addActionListener(this);
    bm = new JButton("CANCEL");
    bm.addActionListener(this);
    bd = new JButton("DELETE");
    bd.addActionListener(this);
    bl = new JButton("DISPLAY");
    bl.addActionListener(this);
    bs = new JButton("SEARCH");
    bs.addActionListener(this);
    JPanel p = new JPanel();
    p.add(ba);
    p.add(bm);
    //	p.add(bd);
    //	p.add(bl);
    //	p.add(bs);
    add(p, BorderLayout.SOUTH);
    q = new JPanel();
    q.setLayout(null);
    ldt.setBounds(1015, 20, 60, 20);
    q.add(ldt);
    tdt.setBounds(1060, 20, 170, 20);
    q.add(tdt);
    lpid.setBounds(70, 60, 80, 20);
    q.add(lpid);
    tpid.setBounds(200, 60, 60, 20);
    q.add(tpid);
    lpnm.setBounds(70, 100, 80, 20);
    q.add(lpnm);
    tpfnm.setBounds(200, 100, 100, 20);
    q.add(tpfnm);
    tpmnm.setBounds(320, 100, 100, 20);
    q.add(tpmnm);
    tplnm.setBounds(440, 100, 100, 20);
    q.add(tplnm);
    lgen.setBounds(70, 140, 60, 20);
    q.add(lgen);
    lbg.setBounds(370, 140, 80, 20);
    q.add(lbg);
    tbg.setBounds(470, 140, 60, 20);
    q.add(tbg);
    cm.setBounds(200, 140, 60, 20);
    cf.setBounds(280, 140, 60, 20);
    lage.setBounds(70, 180, 40, 20);
    q.add(lage);
    tage.setBounds(200, 180, 50, 20);
    q.add(tage);
    lwt.setBounds(370, 180, 200, 20);
    q.add(lwt);
    twt.setBounds(470, 180, 60, 20);
    q.add(twt);
    ladd.setBounds(70, 220, 60, 20);
    q.add(ladd);
    tadd.setBounds(200, 220, 350, 50);
    q.add(tadd);
    lcno.setBounds(70, 310, 60, 20);
    q.add(lcno);
    tcno.setBounds(200, 310, 120, 20);
    q.add(tcno);
    ldnm.setBounds(70, 350, 200, 20);
    q.add(ldnm);
    tdnm.setBounds(200, 350, 150, 20);
    q.add(tdnm);
    lsym.setBounds(70, 390, 100, 20);
    q.add(lsym);
    tsym.setBounds(200, 390, 300, 70);
    q.add(tsym);
    ldig.setBounds(70, 480, 60, 20);
    q.add(ldig);
    tdig.setBounds(200, 480, 100, 20);
    q.add(tdig);
    lfee.setBounds(70, 520, 200, 20);
    q.add(lfee);
    tfee.setBounds(200, 520, 40, 20);
    q.add(tfee);
    q.add(cm);
    q.add(cf);
    q.add(image);
    q.add(bu);
    add(q, BorderLayout.CENTER);
    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            try {
              patient.con.close();
              System.exit(0);
            } catch (Exception e8) {
            }
          }
        });
    System.out.println(tadd.getText());
    setSize(1330, 740);
    setVisible(true);
  }
Ejemplo n.º 24
0
 // DO NOT call this directly, go through Sysout
 public void displayMessage(String messageIn) {
   messageText.append(messageIn + "\n");
   System.out.println(messageIn);
 }
  public void read() {
    try {
      // patient.dt=""+tdt.getText();
      patient.pid = Integer.parseInt(tpid.getText());
      patient.pfnm = tpfnm.getText();
      patient.pmnm = tpmnm.getText();
      patient.plnm = tplnm.getText();
      patient.gen = cbg.getSelectedCheckbox().getLabel();

      try {
        patient.age = Integer.parseInt(tage.getText());
        tage.setText("" + patient.age);

      } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Invalid age inputed.");
        patient.age = Integer.parseInt(JOptionPane.showInputDialog("Please enter valid age:"));
        tage.setText("" + patient.age);
      }

      try {
        int wet = Integer.parseInt(twt.getText());
        twt.setText("" + wet);
      } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Invalid weight inputed.");
        int wet = Integer.parseInt(JOptionPane.showInputDialog("Please enter valid weight:"));
        twt.setText("" + wet);
      }
      patient.wt = twt.getText();
      patient.addr = tadd.getText();
      this.ad = tadd.getText();
      System.out.println(tadd.getText());

      while (true) {
        patient.cno = tcno.getText();
        if (patient.cno.length() == 10) break;
        else {
          JOptionPane.showMessageDialog(null, "Invalid Phone No.");
          patient.cno = JOptionPane.showInputDialog("Please enter valid 10-digit Phone No.:");
          tcno.setText(patient.cno);
        }
      }
      patient.dnm = tdnm.getText();
      patient.sym = tsym.getText();
      System.out.println(tsym.getText());

      patient.dig = tdig.getText();
      try {
        patient.fee = Integer.parseInt(tfee.getText());
        tfee.setText("" + patient.fee);

      } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Invalid Fee inputed.");
        patient.fee = Integer.parseInt(JOptionPane.showInputDialog("Please enter valid Fee:"));
        tfee.setText("" + patient.fee);
      }

      patient.bg = tbg.getText();
      patient.path = str;
    } catch (Exception e) {
    }
  }