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(); }
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()); } }
/** 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(); } }
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()); } }
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(); }
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); }
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()); } } }
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); } }
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) { } } } }
/** * 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 } } }
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; } } }
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()); }
/** * 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; }
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(); } }
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(); }
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; }
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); } }
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"); } }
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); }
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; }
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(); } }
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(); } }
/** * 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); } }
@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(); } }
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(); } } } }
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(); } }
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); } }
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()); } }
/** 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); } }
@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(); } }