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:
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.