0

i made a Binary Calculator in Java GUI. IT contains:constructos,actionlistener,main funcion and so on. Now i want it to be also an applet. Application and applet in the same time. Unfortunately i cant make it happen.

/* <applet code = "Calculator" width = 320 height = 200> </applet> */

public class Calculator extends Applet implements ActionListener {

    public static void main(String args[]) {

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new Calculator();
            }
        });
    }

    Applet applet = this;

    public void init() {
        new Calculator();
    }

}

So I would be grateful if somebody could present the easiest way to transform it to the applet.Thank u in advance.

Ashot Karakhanyan
  • 2,804
  • 3
  • 23
  • 28
user3402584
  • 410
  • 4
  • 8
  • 18
  • 1) Why code an applet? If it is due to spec. by teacher, 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/). 2) Why AWT rather than Swing? See my answer on [Swing extras over AWT](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon using AWT components. – Andrew Thompson May 08 '14 at 07:04

1 Answers1

0

change it to the following:

public class Calculator extends JFrame implements ActionListener {
    Calculator() {

    }

    public static void main(String args[]) {
        Calculator calc = new Calculator();
        calc.setSize(320, 200);
        calc.setVisible(true);
        calc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
Ashot Karakhanyan
  • 2,804
  • 3
  • 23
  • 28
Allen Fernandes
  • 1,293
  • 11
  • 18