Chapter 15
602
We derive from Applet (not JApplet), and we implement the ItemListener for the radio button
selection, and the ActionListener to handle the Update button click event:
public class VacationApplet extends Applet
implements ItemListener,
ActionListener {
static final int LISTWIDTH = 400;
static final int LISTHEIGHT = 200;
static final int FONTSIZE = 16;
private Font myFont;
private FontMetrics myFM;
private int numLines = 0;
private int myLineHeight = 0;
private int curLineIndex = 1;
curTripNumber contains the trip number from the last update; it starts at 0:
private int curTripNumber = 0;
int minCommision = 0;
listNeedUpdate is used initially to determine if the list has been initialized. This occurs if the user
clicks one of the radio buttons without first clicking the Update button.
private boolean listNeedUpdate;
private CheckboxGroup destGroup;
private Checkbox allClick, mexicoClick, caribClick, hawaiiClick;
private Button updateButton;
private Panel clickPanel;
private List tripList;
The currentRegionFilter contains the region code for filtering the listbox, depending on the
clicked radio button. curDeals is a Vector of TravelDeals instances that is used to populate and
filter the listbox. minCommission is obtained from the applet parameter mincom, and is used to filter
the trips in the listbox based on minimum acceptable commission:
public int currentRegionFilter = 0;
public Vector curDeals = null;
public int minCommission = 0;
public void init() {
super.init();