// button
test program : taken from Javaranch tanveer:15/12/00
// and modified
// using switch & case instead of a group of nested if statements
import java.awt.*;
public class ButtonApplet extends Applet implements ActionListener{
Button button1,button2,button3;
Label label1,label2,label3;
public void init()
{
setLayout(new GridLayout(2,3));
add(button1=new Button("button1"));
add(button2=new Button("button2"));
add(button3=new Button("button3"));
add(label1=new Label("Label1"));
add(label2=new Label("Label2"));
add(label3=new Label("Label3"));
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
Button b=(Button)ae.getSource();
switch (b)
case button1:
if(label1.getText().equals("Label1"))
label1.setText("1lebaL");
else label1.setText("Label1");
break;
case button2:
if(label2.getText().equals("Label2"))
label1.setText("2lebaL");
else label1.setText("Label2");
break;
case button3:
if(label3.getText().equals("Label3"))
label1.setText("3lebaL");
else label1.setText("Label3");
break;
default :
break;
}
}