コード例 #1
0
  public void save() {
    for (String key : fields.keySet()) {
      JComponent comp = fields.get(key);

      if (comp instanceof JTextField) {
        JTextField c = (JTextField) comp;

        if (c.getText().trim().equals("")) {
          sketch.configFile.unset(key);
        } else {
          sketch.configFile.set(key, c.getText());
        }
      } else if (comp instanceof JTextArea) {
        JTextArea c = (JTextArea) comp;

        if (c.getText().trim().equals("")) {
          sketch.configFile.unset(key);
        } else {
          sketch.configFile.set(key, c.getText());
        }
      }
    }

    sketch.saveConfig();
  }
コード例 #2
0
 public void inventory() {
   txtTranscript.insert("You are carrying:\n", txtTranscript.getText().length());
   for (String item : inventory) {
     txtTranscript.insert(item + "\n", txtTranscript.getText().length());
   }
   if (inventory.isEmpty()) {
     txtTranscript.insert("No items.\n", txtTranscript.getText().length());
   }
 }
コード例 #3
0
  /** The listener method. */
  public void actionPerformed(ActionEvent event) {
    Object source = event.getSource();

    if (source == b1) // click button
    {
      try {
        String message = tf.getText();
        server.sendPrivateMessage(parent, selfIdentity, message);
        ta.append("<" + parent.getUserName() + ">: " + message + lineSeparator);
        ta.setCaretPosition(ta.getText().length());
        tf.setText("");
      } catch (RemoteException ex) {
        System.out.print("Exception encountered while sending" + " private message.");
      }
    }

    if (source == tf) // press return
    {
      try {
        String message = tf.getText();
        server.sendPrivateMessage(parent, selfIdentity, message);
        ta.append("<" + parent.getUserName() + ">: " + message + lineSeparator);
        ta.setCaretPosition(ta.getText().length());
        tf.setText("");
      } catch (RemoteException ex) {
        System.out.print("Exception encountered while sending" + " private message.");
      }
    }
    if (source == jMenuItem3) {
      JFileChooser fileChooser = new JFileChooser();

      fileChooser.setDialogTitle("Choose or create a new file to store the conversation");
      fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
      fileChooser.setDoubleBuffered(true);

      fileChooser.showOpenDialog(this);

      File file = fileChooser.getSelectedFile();

      try {
        if (file != null) {

          Writer writer = new BufferedWriter(new FileWriter(file));

          writer.write(ta.getText());
          writer.flush();
          writer.close();
        }
      } catch (IOException ex) {
        System.out.println("Can't write to file. " + ex);
      }
    }
    if (source == jMenuItem4) {
      selfRemove();
      this.dispose();
    }
  }
コード例 #4
0
 public void autoinventory() {
   inv.setText("");
   inv.insert("You are carrying:\n", inv.getText().length());
   for (String item : inventory) {
     inv.insert(item + "\n", inv.getText().length());
   }
   if (inventory.isEmpty()) {
     inv.insert("No items.\n", inv.getText().length());
   }
 }
コード例 #5
0
  public void take(String takable) {
    String takeItem = null;
    int[] mapKey = null;
    int[] pair = {row, col};

    for (int[] key : myMap.items.keySet()) {
      if (Arrays.equals(pair, key)) {
        mapKey = key;
      }
    }
    if (mapKey != null) {
      ArrayList<String> loot = myMap.items.get(mapKey);
      for (String item : loot) {
        if (item.toUpperCase().equals(takable.toUpperCase())) {
          takeItem = item;
        }
      }
      if (takeItem != null) {
        inventory.add(takeItem);
        loot.remove(takeItem);
        txtTranscript.insert(
            "You picked up a " + takeItem + "\n", txtTranscript.getText().length());
        if (takeItem.equals("BLASTER")) {
          txtTranscript.insert(
              "You roll your eyes\nSo uncivilized...\n", txtTranscript.getText().length());
        } else if (takeItem.toUpperCase().equals("LIGHT SABER")) {
          txtTranscript.insert(
              "Now we're talking!\nA key weapon in defeating Vader.\n",
              txtTranscript.getText().length());
        } else if (takeItem.toUpperCase().equals("BAG OF YODA SNACKS")) {
          txtTranscript.insert(
              "You roll your eyes\nSo uncivilized..\n", txtTranscript.getText().length());
        } else if (takeItem.equals("HAIR BRUSH")) {
          txtTranscript.insert(
              "Perhaps these will help convince Yoda to train you.\n",
              txtTranscript.getText().length());
        } else if (takeItem.equals("STORM TROOPER HELMET")) {
          txtTranscript.insert(
              "A disguise to sneek up on Vader?\n", txtTranscript.getText().length());
        } else if (takeItem.equals("GLOWING HULK MASK")) {
          txtTranscript.insert(
              "Maybe you could scare Vader to death?\n", txtTranscript.getText().length());
        } else if (takeItem.equals("MIDICHLORIANS")) {
          txtTranscript.insert(
              "You feel the power of the force surging through you.\n",
              txtTranscript.getText().length());
        }
      }
    }
    if (mapKey == null || takeItem == null) {
      txtTranscript.insert(
          "You can't find \"" + takable + "\" to pick up.\n", txtTranscript.getText().length());
    }
    autoinventory();
  }
コード例 #6
0
ファイル: TestHTML.java プロジェクト: maeyler/PlainJava
 public void mouseMoved(MouseEvent e) {
   int k = html.viewToModel(e.getPoint());
   if (html.hasFocus() && html.getSelectionStart() <= k && k < html.getSelectionEnd()) {
     setMessage("(on selection)", MOVE);
     return;
   }
   String s = text.getText(); // "";
   int m = s.length(); // html.getDocument().getLength();
   /*try {
          s = html.getText(0, m);
      } catch (BadLocationException x) {
   setMessage("BadLocation "+m, TEXT); return;
      } */
   if (!Character.isLetter(s.charAt(k))) {
     setMessage("(not a letter)", TEXT);
     return;
   }
   selB = k;
   selE = k + 1;
   while (!Character.isWhitespace(s.charAt(selB - 1))) selB--;
   while (!Character.isWhitespace(s.charAt(selE))) selE++;
   setMessage(selB + "-" + selE, HAND);
   word = "";
   for (int i = selB; i < selE; i++) if (Character.isLetter(s.charAt(i))) word += s.charAt(i);
   html.setToolTipText(word);
 }
コード例 #7
0
ファイル: JConsoleOutLinker.java プロジェクト: antoniou/vfork
  public synchronized void run() {

    byte[] buffer = new byte[BUFFER_SIZE];

    for (; ; ) {
      try {
        this.wait(100);
      } catch (InterruptedException ie) {
      }

      int len = 0;
      try {
        int noBytes = pin.available();

        if (noBytes > 0) {
          len = pin.read(buffer, 0, Math.min(noBytes, BUFFER_SIZE));
          if (len > 0) {
            jTextArea.append(new String(buffer, 0, len));
            jTextArea.setCaretPosition(jTextArea.getText().length());
          }
        }
      } catch (IOException ioe) {
        throw new UIError("Unable to read from input stream! " + ioe.getMessage());
      }
    }
  }
コード例 #8
0
ファイル: Gui2.java プロジェクト: Emilyxu828/APCS-Homework
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == b1) {
     System.out.println("You Clicked Click me");
     System.out.println("And the textarea has: " + text.getText());
     x = x + 10;
     y = y + 10;
     canvas.update(canvas.getGraphics());
   } else if (e.getSource() == labeler) {
     label.setText(text.getText());
     // pane.add(new JLabel(text.getText()));
     text.setText("");
   } else if (e.getSource() == b2) {
     System.out.println("Shutting down");
     System.exit(0);
   }
 }
コード例 #9
0
ファイル: EditFrame.java プロジェクト: BrotherPhil/ROPE
  public void save() {
    BufferedWriter sourceFile = null;

    try {
      String sourceText = sourceArea.getText();

      String cleanText = cleanupSource(sourceText);

      if (cleanText.length() != sourceText.length()) {
        sourceArea.setText(cleanText);

        String message =
            String.format(
                "One or more invalid characters at the end of the source file have been removed.");
        JOptionPane.showMessageDialog(this, message, "ROPE", JOptionPane.INFORMATION_MESSAGE);
      }

      sourceFile = new BufferedWriter(new FileWriter(sourcePath, false));
      sourceFile.write(cleanText);

      setSourceChanged(false);

      setupMenus();
    } catch (IOException ex) {
      ex.printStackTrace();
    } finally {
      if (sourceFile != null) {
        try {
          sourceFile.close();
        } catch (IOException ignore) {
        }
      }
    }
  }
コード例 #10
0
 /**
  * Will select the Mars Messages tab error message that matches the given specifications, if it is
  * found. Matching is done by constructing a string using the parameter values and searching the
  * text area for the last occurrance of that string.
  *
  * @param fileName A String containing the file path name.
  * @param line Line number for error message
  * @param column Column number for error message
  */
 public void selectErrorMessage(String fileName, int line, int column) {
   String errorReportSubstring =
       new java.io.File(fileName).getName()
           + ErrorList.LINE_PREFIX
           + line
           + ErrorList.POSITION_PREFIX
           + column;
   int textPosition = assemble.getText().lastIndexOf(errorReportSubstring);
   if (textPosition >= 0) {
     int textLine = 0;
     int lineStart = 0;
     int lineEnd = 0;
     try {
       textLine = assemble.getLineOfOffset(textPosition);
       lineStart = assemble.getLineStartOffset(textLine);
       lineEnd = assemble.getLineEndOffset(textLine);
       assemble.setSelectionColor(Color.YELLOW);
       assemble.select(lineStart, lineEnd);
       assemble.getCaret().setSelectionVisible(true);
       assemble.repaint();
     } catch (BadLocationException ble) {
       // If there is a problem, simply skip the selection
     }
   }
 }
コード例 #11
0
ファイル: Swing4.java プロジェクト: mc5827/Java-Programs
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==b)
		{
			temp=tf.getText();
			temp1[]=ta.getText().split();
			index=0;
			index=temp1[].indexOf(temp,index);
			ta.select(index, index+temp.length());
			b.setVisible(false);
			b1.setVisible(true);
		}
		if(e.getSource()==b1)
		{
			index=temp1.indexOf(temp,index+temp.length());
			if(index!=-1)
			{
				ta.requestFocusInWindow();
				ta.select(index, index+temp.length());
			}
			else
			{
				b.setVisible(true);
				b1.setVisible(false);
				index=0;
			}
		}
	}	
コード例 #12
0
  protected void GetFields() {
    if (_PreviousPersonnel == null) return;

    _PreviousPersonnel.setName(_NameTextField.getText());
    _PreviousPersonnel.setCallsign(_CallsignTextField.getText());
    _PreviousPersonnel.setRank((Rank) _RankCombo.getSelectedItem());
    _PreviousPersonnel.setRating((Rating) _RatingCombo.getSelectedItem());
    _PreviousPersonnel.setNotes(_NotesTextArea.getText());
  }
コード例 #13
0
ファイル: ListInputPanel.java プロジェクト: MrSampson/jMIR
  /**
   * Takes the contents of the text area and breaks them into an array with an entry for each line
   * in the text area. Blank lines are removed but no other processing is performed.
   *
   * @return The lines found in text area. Blank lines are removed. Null is returned if the text
   *     area is empty.
   */
  public String[] getStrings() {
    String field_contents = text_area.getText();
    if (field_contents == null) return null;
    if (field_contents.equals("")) return null;

    String[] search_strings =
        mckay.utilities.staticlibraries.StringMethods.breakIntoTokens(field_contents, "\n");
    if (search_strings.length == 0) return null;

    return search_strings;
  }
コード例 #14
0
  public void go(String[] userInput) {
    if (userInput.length == 0) {
      txtTranscript.insert("You did not specify a direction.\n", txtTranscript.getText().length());
    } else {
      char direction = Character.toLowerCase(userInput[0].charAt(0));

      if (direction == 'n') {
        if (row > MINROW) {
          txtTranscript.insert("Moving north . . .\n", txtTranscript.getText().length());
          row--;
        } else {
          txtTranscript.insert("North is out of bounds..\n", txtTranscript.getText().length());
        }
      } else if (direction == 'e') {
        if (col < MAXCOL) {
          txtTranscript.insert("Moving east . . .\n", txtTranscript.getText().length());
          col++;
        } else {
          txtTranscript.insert("East is out of bounds..\n", txtTranscript.getText().length());
        }
      } else if (direction == 's') {
        if (row < MAXROW) {
          txtTranscript.insert("Moving south . . .\n", txtTranscript.getText().length());
          row++;
        } else {
          txtTranscript.insert("South is out of bounds..\n", txtTranscript.getText().length());
        }
      } else if (direction == 'w') {
        if (col > MINCOL) {
          txtTranscript.insert("Moving west . . .\n", txtTranscript.getText().length());
          col--;
        } else {
          txtTranscript.insert("West is out of bounds.\n", txtTranscript.getText().length());
        }
      } else {
        txtTranscript.insert(
            "Which direction did you want to go?\n", txtTranscript.getText().length());
      }
      printLocation();
    }
  }
コード例 #15
0
  public void drop(String dropped) {
    int[] pair = {row, col};
    String takeItem = null;

    for (String item : inventory) {
      if (item.equals(dropped)) {
        takeItem = item;
      }
    }

    if (takeItem != null) {
      inventory.remove(takeItem);
      myMap.addItems(pair, takeItem);
      txtTranscript.insert(
          "You dropped a \"" + takeItem + "\".\n", txtTranscript.getText().length());
    } else {
      txtTranscript.insert(
          "You aren't carrying a \"" + dropped + "\" to drop.\n", txtTranscript.getText().length());
    }
    autoinventory();
  }
コード例 #16
0
 public boolean saveToFile(String namefile) {
   try {
     File file = new File(namefile);
     FileWriter out = new FileWriter(file);
     String text = textArea.getText();
     out.write(text);
     out.close();
     return true;
   } catch (IOException e) {
     System.out.println("Error saving file.");
   }
   return false;
 }
コード例 #17
0
ファイル: Secondtry.java プロジェクト: japanna/unit6.1
  public void calc() {

    if (operator == "+") {
      firstNum += secondNum;
      System.out.println("firstNum plus secondNum is: " + firstNum);
    }
    if (operator == "-") {
      firstNum -= secondNum;
      System.out.println("firstNum minus secondNum is: " + firstNum);
    }
    if (operator == "*") {
      firstNum *= secondNum;
      System.out.println("firstNum times secondNum is: " + firstNum);
    }
    if ((operator == "/") && secondNum != 0.0) {
      System.out.println("firstNum div by secondNum is: " + firstNum);
      firstNum /= secondNum;
    }
    if ((operator == "/") && secondNum == 0.0) {
      display.setText("ERROR");
      System.out.println(display.getText());
      firstNum = 0.0;
      secondNum = 0.0;
      operators = true;
      doClear = true;
    }

    if (!(display.getText().equals("ERROR"))) {
      operators = true;
      decPoint = false;

      display.setText(String.valueOf(firstNum));

      secondNum = firstNum;

      System.out.println("SecondNum is: " + firstNum);
    }
  }
コード例 #18
0
ファイル: prologApplet.java プロジェクト: mberionni/uni
  protected void compile() {
    Sexp curClause;
    goal = new NilSexp();
    prog = new NilSexp();
    prog2 = new NilSexp();
    String codice = code.getText();

    try {
      ProParser p = new ProParser(codice, intmsg);
      for (; ; ) {
        curClause = p.getClause(); // seleziono una singola clausola
        intmsg.append("compiled: " + curClause + "\n");
        if (!(curClause instanceof eofToken)) {
          prog = Sexp.append(prog, Sexp.list1(curClause));
        }
        if (p.atEOF()) {
          break;
        }
      }
      String codice2 = code.getText();
      ProParser p2 = new ProParser(codice2, intmsg);
      for (; ; ) {
        curClause = p2.getClause(); // seleziono una singola clausola
        // intmsg.append( "compiled: " + curClause + "\n" );
        if (!(curClause instanceof eofToken)) {
          prog2 = Sexp.append(prog2, Sexp.list1(curClause));
        }
        if (p2.atEOF()) {
          break;
        }
      }

      showProg(prog, outp);
      // showProg( prog2, outp );
    } catch (Exception e) {
      outp.append("error" + e + " \n");
    }
  }
コード例 #19
0
ファイル: TestHTML.java プロジェクト: maeyler/PlainJava
 public void mouseClicked(MouseEvent e) {
   if (e.getClickCount() != 1) return;
   // String s = html.getToolTipText();
   if (word == null) return;
   setMessage(word);
   String s = text.getText();
   String h =
       s.substring(0, selB)
           + " <FONT color=blue> "
           + s.substring(selB, selE)
           + " </FONT> "
           + s.substring(selE);
   setHTML(h);
 }
コード例 #20
0
ファイル: MailDialog.java プロジェクト: dusken/pegadi
  private boolean sendMail() {

    if (mailToField.getText().trim().length() == 0) {
      JOptionPane.showMessageDialog(
          this, strings.getString("error_emptytofield"), "", JOptionPane.ERROR_MESSAGE);
      return (false);
    }
    if (!checkMailAddress(mailToField.getText())) {
      JOptionPane.showMessageDialog(
          this, strings.getString("error_invalidtofield"), "", JOptionPane.ERROR_MESSAGE);
      return (false);
    }

    if (mailFromField.getText().trim().length() == 0) {
      JOptionPane.showMessageDialog(
          this, strings.getString("error_emptyfromfield"), "", JOptionPane.ERROR_MESSAGE);
      return (false);
    }
    if (!checkMailAddress(mailFromField.getText())) {
      JOptionPane.showMessageDialog(
          this, strings.getString("error_invalidfromfield"), "", JOptionPane.ERROR_MESSAGE);
      return (false);
    }

    String mailText = mailBodyArea.getText();

    boolean value;
    try {
      value =
          LoginContext.server.sendmail(
              mailFromField.getText(),
              mailToField.getText(),
              mailSubjectField.getText(),
              mailText,
              LoginContext.sessionKey);
    } catch (RemoteException ex) {
      JOptionPane.showMessageDialog(
          this, strings.getString("error_sendingfailed"), "Error", JOptionPane.ERROR_MESSAGE);
      log.error("Could not send email beacuse of a server-side error", ex);
      return false;
    }
    if (!value) {
      JOptionPane.showMessageDialog(
          this, strings.getString("error_sendingfailed"), "Error", JOptionPane.ERROR_MESSAGE);
      log.error("Could not send email beacuse of a server-side error");
      return false;
    }
    return true;
  }
コード例 #21
0
 public static void showResult(JTextArea txt, String result) {
   try {
     if (txt.getText().length() == 0) {
       txt.setText(result);
       txt.setSelectionStart(txt.getText().length());
       txt.setSelectionEnd(txt.getText().length() - 1);
     } else {
       if (txt.getText().length() > MAX_LOG_SIZE)
         txt.getDocument().remove(0, txt.getText().length() - MAX_LOG_SIZE);
       txt.setSelectionStart(txt.getText().length());
       txt.getDocument().insertString(txt.getText().length(), result, null);
       txt.setSelectionEnd(txt.getText().length());
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
コード例 #22
0
 public void printLocation() {
   txtTranscript.insert(
       "You are at location "
           + row
           + ","
           + col
           + " in terrain: "
           + myMap.terrainTypes.get(Character.toString(myMap.terrain(row, col)))
           + "\n",
       txtTranscript.getText().length());
   if (myMap.terrain(row, col) == '*') {
     Dragon found = new Dragon();
     found.Dragon();
   }
 }
コード例 #23
0
ファイル: ListInputPanel.java プロジェクト: MrSampson/jMIR
  /**
   * Appends each string in the new_strings parameter as a new line in the text area. Sets the caret
   * is set to the beginning of the text.
   *
   * @param new_strings The strings to add. Each entry is added to a new line. This method performs
   *     no action if this parameter is empty or null.
   */
  public void appendStrings(String[] new_strings) {
    if (new_strings != null)
      if (new_strings.length != 0) {
        // Append the text
        for (int i = 0; i < new_strings.length; i++) {
          if (i == 0) {
            if (!text_area.getText().equals("")) text_area.append("\n");
          } else text_area.append("\n");

          text_area.append(new_strings[i]);
        }

        // Reset the caret position
        text_area.setCaretPosition(0);
      }
  }
コード例 #24
0
  @Override
  public void actionPerformed(ActionEvent e) {
    String prefix = "";
    String userName = settingsPane.returnSetting("IRC_nick");
    String input = "<b><font color=blue>[" + userName + "]:</font></b> " + chatInput.getText();

    if (e.getSource() == g_start) {

      substarterBegin(prefix, userName, input);
    }

    if (e.getSource() == g_end) {
      substarterEnd(prefix, userName, input);
    }

    if (e.getSource() == sendButton) {

      if (!chatInput.getText().equals("")) {

        // toChatScreen(input);

        // chatScreen.append(input + "\n");
        if (chatInput.getText().startsWith("/")) {
          if (chatInput.getText().equals("/substart")) {
            substarterBegin(prefix, userName, input);
          }
          if (chatInput.getText().equals("/substartend")) {
            substarterEnd(prefix, userName, input);
          }
        } else {
          sock.outputToChannel(chatInput.getText(), channelName);

          try {
            // chatter.printScreen();

            toChatScreen(prefix + input, false);
          } catch (IOException | BadLocationException ex) {
            Logger.getLogger(IRCBOT.class.getName()).log(Level.SEVERE, null, ex);
          }
        }
        chatInput.setText("");
        // chatter.addTo(input);

      } else {
        chatInput.setText("");
      }
      chatInput.requestFocus();
    }

    if (e.getSource() == settings) {
      // makeNewWindow("Window " + frameCounter, JFrame.DISPOSE_ON_CLOSE, 800, 500, 2);
      settingsPane.showPane();
    }
  }
コード例 #25
0
ファイル: EditFrame.java プロジェクト: BrotherPhil/ROPE
  public void saveAs() {
    Vector<RopeFileFilter> filters = new Vector<RopeFileFilter>();

    if (fileExt.equals("m") || fileExt.equals("mac")) {
      filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
      filters.add(
          new RopeFileFilter(
              new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
    } else {
      filters.add(
          new RopeFileFilter(
              new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
      filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
    }
    filters.add(new RopeFileFilter(new String[] {".txt"}, "Text files (*.txt)"));

    RopeFileChooser chooser = new RopeFileChooser(selectedPath, null, filters);
    chooser.setDialogTitle("Save Source File");
    String fileName = String.format("%s.%s", baseName, fileExt);
    chooser.setSelectedFile(new File(selectedPath, fileName));
    JTextField field = chooser.getTextField();
    field.setSelectionStart(0);
    field.setSelectionEnd(baseName.length());
    File file = chooser.save(ROPE.mainFrame);
    if (file != null) {
      selectedPath = file.getParent();

      BufferedWriter writer = null;
      try {
        writer = new BufferedWriter(new FileWriter(file));
        writer.write(sourceArea.getText());
      } catch (IOException ex) {
        ex.printStackTrace();
      } finally {
        try {
          if (writer != null) {
            writer.close();
          }
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }
    }
  }
コード例 #26
0
ファイル: EditFrame.java プロジェクト: BrotherPhil/ROPE
  void doCaretUpdate(int dot, int mark) {
    if (dot == mark) {
      mainFrame.cutItem.setEnabled(false);
      mainFrame.copyItem.setEnabled(false);
      mainFrame.deleteItem.setEnabled(false);
    } else {
      mainFrame.cutItem.setEnabled(true);
      mainFrame.copyItem.setEnabled(true);
      mainFrame.deleteItem.setEnabled(true);
    }

    int length = sourceArea.getText().length();
    if (length == 0 || abs(mark - dot) == length) {
      mainFrame.selectAllItem.setEnabled(false);
    } else {
      mainFrame.selectAllItem.setEnabled(true);
    }

    try {
      if (length == 0) {
        mainFrame.selectLineItem.setEnabled(false);
      } else {
        int lineNum = sourceArea.getLineOfOffset(dot);
        int startLine = sourceArea.getLineStartOffset(lineNum);
        int endLine = sourceArea.getLineEndOffset(lineNum);
        if (endLine - startLine <= 1) {
          mainFrame.selectLineItem.setEnabled(false);
        } else {
          mainFrame.selectLineItem.setEnabled(true);
        }
      }
    } catch (BadLocationException ex) {
      ex.printStackTrace();
    }

    try {
      int line = sourceArea.getLineOfOffset(dot);
      lineText.setText(Integer.toString(line + 1));
      int column = dot - sourceArea.getLineStartOffset(line);
      columnText.setText(Integer.toString(column + 1));
    } catch (BadLocationException ex) {
      ex.printStackTrace();
    }
  }
コード例 #27
0
ファイル: SISCFrame.java プロジェクト: igorhvr/bedlam
 public void actionPerformed(ActionEvent e) {
   if (e.getActionCommand().equals("Clear")) input.setText("");
   else {
     String s = input.getText().trim();
     if (s.length() > 1 && s.charAt(s.length() - 1) == '\n') s = s.substring(0, s.length() - 1);
     PushbackReader ip = new PushbackReader(new BufferedReader(new StringReader(s)));
     Value v = Util.VOID;
     try {
       v = sp.dynenv.parser.nextExpression(ip);
     } catch (EOFException eof) {
       // eof.printStackTrace();
       return;
     } catch (Exception ie) {
       System.err.println(ie);
     }
     if (autoClear.isSelected()) input.setText("");
     sp.eval(s);
   }
 }
コード例 #28
0
  public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equals("Add User")) {
      jta.append("\n" + userId.getText());

      User user = new User(userId.getText());
    } else if (ae.getActionCommand().equals("Add Group")) {
      jta.append("\n" + groupId.getText());

      Group group = new Group(groupId.getText());
    } else if (ae.getActionCommand().equals("Open User View")) {
      try {
        if (!jta.getSelectedText().equals("null")) {
          userView.setVisible(true);
        }
      } catch (Exception e) {
        JOptionPane.showMessageDialog(
            frame, "Nothing selected", "Error", JOptionPane.ERROR_MESSAGE);
      }
    } else if (ae.getActionCommand().equals("Show User Total")) {
      JOptionPane.showMessageDialog(frame, User.getUserTotal());
    } else if (ae.getActionCommand().equals("Show Group Total")) {
      JOptionPane.showMessageDialog(frame, Group.getGroupTotal());
    } else if (ae.getActionCommand().equals("Show Messages Total")) {
      JOptionPane.showMessageDialog(frame, User.getMessageTotal());
    } else if (ae.getActionCommand().equals("Show Positive Percentage")) {
      String[] newsFeed = User.getNewsFeed();

      int positive = 0;
      int i = 0;
      while (!(newsFeed[i] == null)) {
        if (newsFeed[i].contains("good")
            || newsFeed[i].contains("great")
            || newsFeed[i].contains("excellent")) positive++;
        i++;
      }

      JOptionPane.showMessageDialog(frame, positive * 100.0 / i + "%");
    } else if (ae.getActionCommand().equals("Follow User")) {
      following.append("\n" + userId2.getText());
    } else if (ae.getActionCommand().equals("Post Tweet")) {
      User.postTweet(tweet.getText());
      newsFeed.append("\n" + jta.getSelectedText() + ": " + tweet.getText());
    }
  }
コード例 #29
0
ファイル: ChatWindow.java プロジェクト: jmacdotorg/volity
  /** Sends the message that the user typed in the input text area. */
  private void doSendMessage() {
    assert (SwingUtilities.isEventDispatchThread()) : "not in UI thread";

    try {
      String message = mInputText.getText();

      /* Make sure we've got the right resource. */
      mRemoteIdFull = applyLastKnownResource(mRemoteIdBare);
      mChatObject.setParticipant(mRemoteIdFull);

      mChatObject.sendMessage(message);
      mInputText.setText("");
      mLog.message(mLocalId, mLocalId, message);
      // Make the noise, since we won't get an incoming copy of this
      Audio.playMessage();
    } catch (XMPPException ex) {
      new ErrorWrapper(ex);
      JOptionPane.showMessageDialog(
          this, ex.toString(), JavolinApp.getAppName() + ": Error", JOptionPane.ERROR_MESSAGE);
    }
  }
コード例 #30
0
  @Override
  public void keyReleased(KeyEvent e) {

    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
      String prefix = "";
      if (!chatInput.getText().equals("")) {
        String userName = settingsPane.returnSetting("IRC_nick");
        String input = "<b><font color=blue>[" + userName + "]:</font></b> " + chatInput.getText();

        // toChatScreen(input);

        // chatScreen.append(input + "\n");
        if (chatInput.getText().startsWith("/")) {
          if (chatInput.getText().equals("/substart")) {
            substarterBegin(prefix, userName, input);
          }
          if (chatInput.getText().equals("/substartend")) {
            substarterEnd(prefix, userName, input);
          }
        } else {

          try {
            // chatter.printScreen();

            toChatScreen(prefix + input, false);
          } catch (IOException | BadLocationException ex) {
            Logger.getLogger(IRCBOT.class.getName()).log(Level.SEVERE, null, ex);
          }
          sock.outputToChannel(chatInput.getText(), channelName);
        }
        chatInput.setText("");
        // chatter.addTo(input);

      } else {
        chatInput.setText("");
      }
      chatInput.requestFocus();
    }
  }