import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.swing.*; public class sample01 extends Applet implements ActionListener{ int w, h; String tmp_str ; public void init() { w = getWidth(); h = getHeight(); setBackground(Color.white); Button Button_0_ON = (Button)add(new Button("S0 ON")); Button Button_1_ON = (Button)add(new Button("S1 ON")); Button Button_2_ON = (Button)add(new Button("S2 ON")); Button Button_0_OFF = (Button)add(new Button("S0 OFF")); Button Button_1_OFF = (Button)add(new Button("S1 OFF")); Button Button_2_OFF = (Button)add(new Button("S2 OFF")); Button_0_ON.addActionListener(this); Button_1_ON.addActionListener(this); Button_2_ON.addActionListener(this); Button_0_OFF.addActionListener(this); Button_1_OFF.addActionListener(this); Button_2_OFF.addActionListener(this); } public void actionPerformed(ActionEvent e) { if(e.getActionCommand() == "S0 ON") { tmp_str = "Switch 0 ON"; }else if(e.getActionCommand() == "S1 ON") { tmp_str = "Switch 1 ON"; }else if(e.getActionCommand() == "S2 ON") { tmp_str = "Switch 2 ON"; }else if(e.getActionCommand() == "S0 OFF") { tmp_str = "Switch 0 OFF"; }else if(e.getActionCommand() == "S1 OFF") { tmp_str = "Switch 1 OFF"; }else if(e.getActionCommand() == "S2 OFF") { tmp_str = "Switch 2 OFF"; } repaint(); } public void paint(Graphics g) { g.drawString(tmp_str, 10, w/2 ); } }