home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java by Example
/
jbecd.bin
/
JBE-CD
/
NTUsers
/
JBECODE.ZIP
/
JavaByExample
/
chap20
/
ChoiceApplet.java
< prev
next >
Wrap
Text File
|
1996-02-27
|
1KB
|
58 lines
import java.awt.*;
import java.applet.*;
public class ChoiceApplet extends Applet
{
Choice menu;
Color color;
public void init()
{
Choice menu = new Choice();
menu.addItem("Black");
menu.addItem("Red");
menu.addItem("Green");
menu.addItem("Blue");
add(menu);
color = Color.black;
}
public void paint(Graphics g)
{
Font font = new Font("TimesRoman", Font.BOLD, 24);
int height = font.getSize();
g.setFont(font);
g.setColor(color);
g.drawString("This text is drawn in", 32, 75);
g.drawString("the color selected from", 32, 75+height);
g.drawString("the above choice menu.", 32, 75+2*height);
}
public boolean action(Event evt, Object arg)
{
if (evt.target instanceof Choice)
HandleMenu(arg);
return true;
}
protected void HandleMenu(Object item)
{
if (item == "Black")
color = Color.black;
else if (item == "Red")
color = Color.red;
else if (item == "Green")
color = Color.green;
else
color = Color.blue;
repaint();
}
}