Hello all, I'm working on a simple self-chat program, which will eventually lead into a server/client chat program, but for now I am trying to learn the basics. When I run my applet, when I type something in the textarea, it shows up in the text field just fine, but when I backspace whatever is in the text area, it adds letters to what is displayed in the text field.
For example:
I type hello in the line provided;
now if i backspace i'll get this in the text field hellolleh.
this is the code I have: I'm wondering what I need to add so that the textarea will delete the characters, and not add them when I press backspace. Something with Keycode I'm assuming, just unaware of how to set this up.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class AppletThree extends Applet implements ActionListener, TextListener {
TextField tf;
TextArea ta;
Button b;
public void init() {
setLayout(new BorderLayout());
tf = new TextField();
add(tf, BorderLayout.NORTH);
ta = new TextArea();
add(ta, BorderLayout.CENTER);
//tf.addActionListener(this);
tf.addTextListener(this);
b = new Button("Clear");
add(b, BorderLayout.SOUTH);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == b) {
ta.setText("");
} else {
String temp = tf.getText();
ta.append(temp + "\n");
tf.setText("");
}
}
public void textValueChanged(TextEvent te) {
String temp = tf.getText();
char c = temp.charAt(temp.length()-1);
ta.append(""+c);
}
}