home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java by Example
/
jbecd.bin
/
JBE-CD
/
NTUsers
/
JBECODE.ZIP
/
JavaByExample
/
chap18
/
ButtonLabelApplet.java
< prev
Wrap
Text File
|
1996-02-27
|
2KB
|
62 lines
import java.awt.*;
import java.applet.*;
public class ButtonLabelApplet extends Applet
{
Button button1, button2, button3;
Label label1, label2, label3;
public void init()
{
button1 = new Button("Button1");
button2 = new Button("Button2");
button3 = new Button("Button3");
label1 = new Label("Label1", Label.LEFT);
label2 = new Label("Label2", Label.CENTER);
label3 = new Label("Label3", Label.RIGHT);
add(button1);
add(button2);
add(button3);
add(label1);
add(label2);
add(label3);
}
public boolean action(Event evt, Object arg)
{
if (evt.target instanceof Button)
ChangeLabel(arg);
return true;
}
protected void ChangeLabel(Object button)
{
String str;
if (button == "Button1")
{
str = label1.getText();
if (str == "Label1")
label1.setText("1lebaL");
else
label1.setText("Label1");
}
else if (button == "Button2")
{
str = label2.getText();
if (str == "Label2")
label2.setText("2lebaL");
else
label2.setText("Label2");
}
else
{
str = label3.getText();
if (str == "Label3")
label3.setText("3lebaL");
else
label3.setText("Label3");
}
}
}