Next: 3.3 テキストフィールドの処理 TextListener
Up: 3 イベント処理
Previous: 3.1 ボタンなどのイベント処理ActionListener
/*<applet code='CheckboxView'
width='150' height='100'>
</applet>*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class CheckboxView
extends Applet implements ItemListener{
Checkbox checkbox;
public void init() {
checkbox = new Checkbox("表示");
checkbox.addItemListener(this);
add(checkbox);
}
public void
itemStateChanged(ItemEvent event) {
if ( checkbox.getState() ) {
setBackground(Color.black);
checkbox.setBackground(Color.black);
checkbox.setForeground(Color.white);
} else {
setBackground(Color.white);
checkbox.setBackground(Color.white);
checkbox.setForeground(Color.black);
}
}
}
generated through LaTeX2HTML. M.Inaba 平成18年5月7日