Java Reference
In-Depth Information
public class
UiTestApplet
extends JApplet
{
/** Create the GUI with OutputPanel and ControlPanel. **/
public void init ()
{
Container content
-
pane
=
getContentPane ();
// Create an instance of OutputPanel
OutputPanel output
-
panel
=
new OutputPanel ();
// Find out from the applet tag which of the four
// panels to use. Each panel demonstrates a different
// type of control component.
String panel
-
choice
=
getParameter (
"
Choose Panel
"
);
JPanel control
-
panel;
// Create an instance of the control panel
if (panel
-
choice.equals (
"
Checkboxes
"
))
control
-
panel
=
new CheckBoxesPanel (output
-
panel);
else if (panel
-
choice.equals (
"
Radiobuttons
"
))
control
-
panel
=
new RadioButtonsPanel (output
-
panel);
else if (panel
-
choice.equals (
"
List
"
))
control
-
panel
=
new ListPanel (output
-
panel);
else
control
-
panel
=
new SliderPanel (output
-
panel);
// Add the panels to applet's pane.
content
-
pane.add (output
-
panel, BorderLayout.CENTER);
content
-
pane.add (control
-
panel, BorderLayout.SOUTH);
}
// init
}
// class UiTestApplet
Here is the code listing for
OutputPanel
,whose job is just to display the color
currently selected by the user:
import javax.swing.*;
import java.awt.*;
/** Create a JPanel subclass called OutputPanel.
*Itprovides a method to set its color plus
*apaintComponent method. **/
public class
OutputPanel
extends JPanel
Search WWH ::
Custom Search