Step 3


Introduction

In this step, you will add two combo box controls into the control panel of the applet. All of the code that you add should be in the init() method of the FractalApplet class.

Installing Combo Box Controls

You need to add two JComboBox variables and add titled borders to each. Since you have set up a BoxLayout layout manager for the control panel, the combo boxes will be layed out in a vertical column in the order that you add them. The code for setting up the combo boxes should be entered just before the control panel is added into the content pane of the applet.

Each of the combo box controls is set up as follows:

For example, the following code sets up a combo box control for the angle of the fractal, assuming that you used the name controlPanel for the control panel variable.

    JComboBox angleControl = new JComboBox();
    angleControl.addItem("0");
    angleControl.addItem("15");
    angleControl.addItem("30");
    angleControl.addItem("45");
    angleControl.addItem("60");
    angleControl.addItem("75");
    angleControl.setSelectedItem("0");
    angleControl.setBorder(BorderFactory.createTitledBorder("Angle"));
    controlPanel.add(angleControl);
This combo box will display the choices 0, 15, 30, 45, 60, and 75, with 0 being the initially selected choice. The title for the combo box will be "Angle".

You should also set up another combo box control for the length of the fractal pattern. This control should display the choices 75, 100, and 150, with 100 as the initially selected choice. Its title should be "Length".

When you have made these modifications, try recompiling the FractalApplet class and display the applet again with appletviewer. The controls should respond visually to mouse operations, but they will have no effect on the drawing in the fractal panel. Your applet should have the same appearence as the following demonstration applet.

Demonstration Applet