import java.awt.*; import java.applet.Applet; import java.awt.event.*; public class HelloApplet extends Applet implements ActionListener{ Button bt1 = new Button("red"); Button bt2 = new Button("blue"); Button convert = new Button("convert dollar to pound"); TextField txt1= new TextField(20); Label lb1= new Label("Pound"); Label lb2= new Label("Dollar"); TextField txt2= new TextField(20); public void init() { System.out.println("I am called once when applet is initialized"); add(bt1); add(bt2); add(txt1); add(lb2); add(txt2); add(lb1); txt1.addActionListener(this); bt1.addActionListener(this); convert.addActionListener(this); } /* Note that init() start() stop() and destroy() methods are in the Applet superclass and you are overriding them */ public void start() { //this will add button to the applet setBackground(Color.yellow); add(convert); //this will add the listener to the button bt2 object bt2.addActionListener(this); System.out.println("I am called whenever you activate my applet browser"); } public void stop() { System.out.println("I am called whenever you minimize the browser"); } public void destroy() { System.out.println("I am called whenever you exit the applet"); } public void paint(Graphics g) { g.drawString("Java in Unix.....", 50, 150); } public void actionPerformed(ActionEvent e) { if(e.getSource()==bt1) { setBackground(Color.red); // add(bt3); } else if (e.getSource()==convert) { double d; d= Double.parseDouble(txt1.getText()); txt2.setText(Double.toString(d*.4839)); } else if(e.getSource()==txt1) { txt2.setText(txt1.getText()); } else { setBackground(Color.blue); } } }//end applet