Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-01-2008, 11:49 AM
Member
 
Join Date: Apr 2008
Posts: 1
cloudet is on a distinguished road
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
pic1.jpg

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.

pic2.jpg

I can only output a msgbox when a string is found, and can't delete it.

Here's part of my codes:

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."); } }
Anyone can help me?
Thanks in advance.

Last edited by cloudet : 04-01-2008 at 11:50 AM. Reason: add more text
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-01-2008, 04:25 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 324
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
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 conditions
__________________
best regards,
sukatoa
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-05-2008, 10:08 AM
Eku Eku is offline
Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 78
Eku is on a distinguished road
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 10:10 AM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-05-2008, 11:06 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,294
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by Eku View Post
Make sure to back up first.
Cheers, a good point it is....
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox Add/Delete Rageagainst20 New To Java 2 04-16-2008 05:49 PM
Store retrieve and delete on7june New To Java 1 03-08-2008 06:57 PM
Error: Cannot delete a.txt:It is being used by another person or program trill Advanced Java 1 08-07-2007 08:34 AM
problem when I try to delete a file tommy Advanced Java 2 07-31-2007 03:44 PM
How to delete a file Alpha New To Java 1 05-26-2007 09:11 AM


All times are GMT +3. The time now is 02:47 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org