0

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;

        }
    }
}
DanielBarbarian
  • 5,093
  • 12
  • 35
  • 44
  • 1
    Is this related with PHP in any area? – Thamilhan May 18 '16 at 04:48
  • 1) Why use AWT? See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT using components in favor of Swing. 2) Why code an applet? If it is due to the teacher specifying it, please refer them to [Why CS teachers should **stop** teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). .. – Andrew Thompson May 19 '16 at 03:46
  • .. 3) See [Java Plugin support deprecated](http://www.gizmodo.com.au/2016/01/rest-in-hell-java-plug-in/) and [Moving to a Plugin-Free Web](https://blogs.oracle.com/java-platform-group/entry/moving_to_a_plugin_free). – Andrew Thompson May 19 '16 at 03:46
  • I have to, this is what the assignment dictates – Stardust1992 May 19 '16 at 18:55

1 Answers1

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

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • 1
    *"The newer JApplet (swing) has no longer that large a browser support too."* I would state that as 'the **majority** of current browsers do **not** support applets'. If the major makers of browsers have not already removed Java support, they are planning to do so. – Andrew Thompson May 19 '16 at 03:48
  • 1
    @AndrewThompson Thanks confirming what I heard but was not certain about. Java WebStart / JNLP might be an alternative? Though simple I heard it has other problems. – Joop Eggen May 19 '16 at 09:56
  • 1
    *"Though simple I heard it has other problems."* It's not bulletproof (what is?). The biggest latest concerns are 1) The deployment toolkit script, which relied on the plug-in being installed to check Java version, is obsolete now the plug-in is disappearing. 2) Added to that, Chrome at least has decided that every file (including JNLP files) will be downloaded rather than passed directly to the app. that claims a file association. So the deployment of a JWS app. is not as easy for the user as it used to be. Of course, Oracle has no one but itself to blame, constantly letting security bugs .. – Andrew Thompson May 19 '16 at 12:23
  • .. to sneak back into the plug-in. Security bugs they had found and fixed earlier, multiple times. (shakes head sadly..) – Andrew Thompson May 19 '16 at 12:24
  • Thank you! this helped, I have to use awt as per the directions of the assignment. – Stardust1992 May 19 '16 at 18:56