Results 1 to 4 of 4
  1. #1
    cloudet is offline Member
    Join Date
    Apr 2008
    Posts
    1
    Rep Power
    0

    Default 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
    delete string in JtextArea-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.

    delete string in JtextArea-pic2.jpg

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

    Here's part of my codes:

    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.");
      }
     }
    Anyone can help me?
    Thanks in advance.
    Last edited by cloudet; 04-01-2008 at 10:50 AM. Reason: add more text

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    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
    freedom exists in the world of ideas

  3. #3
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    7

    Default

    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.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Listbox Add/Delete
    By Rageagainst20 in forum New To Java
    Replies: 2
    Last Post: 04-16-2008, 04:49 PM
  2. Store retrieve and delete
    By on7june in forum New To Java
    Replies: 1
    Last Post: 03-08-2008, 05:57 PM
  3. Replies: 1
    Last Post: 08-07-2007, 07:34 AM
  4. problem when I try to delete a file
    By tommy in forum Advanced Java
    Replies: 2
    Last Post: 07-31-2007, 02:44 PM
  5. How to delete a file
    By Alpha in forum New To Java
    Replies: 1
    Last Post: 05-26-2007, 08:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •