简体   繁体   中英

Why isnt my Java Echo applet working?

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;

        }
    }
}
output.setText(input.getText());

FYI. Applet (awt) is a relatively discarded technology. The newer JApplet (swing) has no longer that large a browser support too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM