what am I doing wrong ? I really do not get it.
It is basically supposed to display the text I enter into input, however if mark off the checkbox, it should recognize \n and \t
and respond to them according in the output.
Thank you !
//html code is all follows
<applet code="Echo.class" height=400 width=500></applet>
<param name="parameter" value="Echo.class">
</applet>
// this is the .java file
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Echo extends Applet
{
TextArea output;
TextField input;
Checkbox escape;
Button submit;
String s;
boolean bool=true;
String args;
public void init ()
{
setLayout(new BorderLayout());
final Applet Echo = this;
s = "enter some text";
input = new TextField(s);
this.add(input,BorderLayout.SOUTH);
output = new TextArea("");
this.add(output,BorderLayout.CENTER);
submit = new Button("button");
this.add(submit,BorderLayout.EAST);
submit.addActionListener(new Listener());
escape = new Checkbox("checkbox");
this.add(escape, BorderLayout.EAST);
escape.addItemListener(new Listener());
}
public class Listener implements ActionListener, ItemListener
{
public void actionPerformed(ActionEvent e)
{
args = this.getParameter("parameter");
input.getText();
output.setText();
if (bool)
{
System.out.println(args.replaceAll("\\\\n", "\n").replaceAll("\\\\t","\t"));
}
else {
System.out.println(args);
}
}
public void itemStateChanged(ItemEvent ie)
{
if(!escape.getState())
bool=false;
}
}
}