home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java by Example
/
jbecd.bin
/
JBE-CD
/
NTUsers
/
JBECODE.ZIP
/
JavaByExample
/
chap19
/
CheckboxApplet.java
< prev
next >
Wrap
Text File
|
1996-02-26
|
1KB
|
53 lines
import java.awt.*;
import java.applet.*;
public class CheckboxApplet extends Applet
{
Checkbox checkbox1;
Checkbox checkbox2;
Checkbox checkbox3;
public void init()
{
checkbox1 = new Checkbox("Option 1", null, true);
checkbox2 = new Checkbox("Option 2", null, false);
checkbox3 = new Checkbox("Option 3", null, false);
add(checkbox1);
add(checkbox2);
add(checkbox3);
}
public void paint(Graphics g)
{
Font font = g.getFont();
FontMetrics fontMetrics = g.getFontMetrics(font);
int height = fontMetrics.getHeight();
boolean checked = checkbox1.getState();
if (checked)
g.drawString("Option1 selected", 20, 120);
else
g.drawString("Option1 not selected", 20, 120);
checked = checkbox2.getState();
if (checked)
g.drawString("Option2 selected", 20, 120 + height);
else
g.drawString("Option2 not selected", 20, 120 + height);
checked = checkbox3.getState();
if (checked)
g.drawString("Option3 selected", 20, 120 + 2 * height);
else
g.drawString("Option3 not selected", 20, 120 + 2 * height);
}
public boolean action(Event evt, Object arg)
{
repaint();
return true;
}
}