\n and \t
并根据输出对它们做出响应。
谢谢 !
//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;
}
}
}
答案 0 :(得分:1)
output.setText(input.getText());
FYI。 Applet(awt)是一种相对废弃的技术。较新的JApplet(swing)也不再具有那么大的浏览器支持。