June 2002
Beginner to intermediate
640 pages
14h 24m
English
Checkboxes represent a true or false condition. Let's illustrate them with an example application for choosing pizza toppings (jfc_checkbox.py). Import java.awt.Checkbox, and create checkboxes that represent pizza toppings.
>>> from javax.swing import JCheckBox
>>> pepperoni = JCheckBox("pepperoni")
>>> peppers = JCheckBox("peppers")
>>> olives = JCheckBox("olives")
>>> anchovies = JCheckBox("anchovies")
>>> onions = JCheckBox ("onions")
>>> sausage = JCheckBox ("sausage")
Create a frame to put the checkboxes in.
>>> from java.swing import JFrame >>> frame = JFrame(title="Pick your topping", visible = 1)
Add the checkboxes to the frame.
>>> frame.contentPane.add(pepperoni) >>> frame.contentPane.add(peppers) >>> frame.contentPane.add(olives) ...
Read now
Unlock full access