Results 1 to 4 of 4
Thread: delete string in JtextArea
- 04-01-2008, 10:49 AM #1
Member
- Join Date
- Apr 2008
- Posts
- 1
- Rep Power
- 0
delete string in JtextArea
Dear all,
I'm doing a simulation to demonstrate Linda, and now facing some problems.
This is the printscreen of my simulation

when "connect to server" button is pressed, both agent 1 and agent 2 can input operations into uts (textarea).
out means output a value into uts;
rd means search a value in uts;
and in means search a value in uts, and when it's found, the value will be deleted from uts.
note tat for simplicity of simulation, value here means string.
Now the problem for me is how to delete the string from uts txtarea when a string is found.

I can only output a msgbox when a string is found, and can't delete it.
Here's part of my codes:
Anyone can help me?Java Code:public void actionPerformed(ActionEvent e) { if(e.getSource() == btnServer) { System.out.println("\nbtnServer_actionPerformed(ActionEvent e) called."); txtSrv.setText("Connected to server...\n"); } else if(e.getSource() == btnuts1)//out1 { System.out.println("\nbtnuts1_actionPerformed(ActionEvent e) called."); String out1 = new String(txtOut1.getText()); txtOut1.setText(""); System.out.println(out1); txtSrv.append(out1 + "\n"); } else if(e.getSource() == btnuts2)//in1 { System.out.println("\nbtnuts2_actionPerformed(ActionEvent e) called."); //search String in1 = new String(txtIn1.getText()); txtIn1.setText(""); System.out.println(in1); //search String document = txtSrv.getText(); String [] aWord = document.split(in1); //store the number of elements in array for counting int count = (aWord.length)-1; if(count==1) { JOptionPane.showMessageDialog(null,"\""+in1+"\" was found."); //if found, delete from JTextArea } else { JOptionPane.showMessageDialog(null,"\""+in1+"\" was not found."); } } else if(e.getSource() == btnuts3)//rd1 { System.out.println("\nbtnuts3_actionPerformed(ActionEvent e) called."); String rd1 = new String(txtRd1.getText()); txtRd1.setText(""); System.out.println(rd1); //search String document = txtSrv.getText(); String [] aWord = document.split(rd1); //store the number of elements in array for counting int count = (aWord.length)-1; //proper grammer use in using times or time if(count==1) { JOptionPane.showMessageDialog(null,"\""+rd1+"\" was found."); //if found, delete from JTextArea } else { JOptionPane.showMessageDialog(null,"\""+rd1+"\" was not found."); } }
Thanks in advance.Last edited by cloudet; 04-01-2008 at 10:50 AM. Reason: add more text
- 05-01-2008, 03:25 PM #2
You can use replaceAll(String current,String newS) method....
Copy the content of that textArea....
Do the manipulation.
Replace the old content with the manipulated one....
I assumed no conditionsfreedom exists in the world of ideas
- 05-05-2008, 09:08 AM #3
Senior Member
- Join Date
- May 2008
- Location
- Makati, Philippines
- Posts
- 234
- Rep Power
- 6
You can use
if(count==1)
{
JOptionPane.showMessageDialog(null,"\""+in1+"\" was found.");
YourTextArea.setText(null);
//if found, delete from JTextArea
}
Make sure to back up first.Last edited by Eku; 05-05-2008 at 09:10 AM.
- 05-05-2008, 10:06 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Similar Threads
-
Listbox Add/Delete
By Rageagainst20 in forum New To JavaReplies: 2Last Post: 04-16-2008, 04:49 PM -
Store retrieve and delete
By on7june in forum New To JavaReplies: 1Last Post: 03-08-2008, 05:57 PM -
Error: Cannot delete a.txt:It is being used by another person or program
By trill in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 07:34 AM -
problem when I try to delete a file
By tommy in forum Advanced JavaReplies: 2Last Post: 07-31-2007, 02:44 PM -
How to delete a file
By Alpha in forum New To JavaReplies: 1Last Post: 05-26-2007, 08:11 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks