Java Reference
In-Depth Information
TRY IT OUT: Setting Up the Lucky Number Buttons
The init() method has to execute only the createGUI() method on the event-dispatching thread:
// Initialize the applet
@Override
public void init() {
SwingUtilities.invokeLater(
// Create interface
components
new Runnable() {
// on the event
dispatching thread
public void run() {
createGUI();
}
});
}
Directory "Lottery 1"
In the class outline, you identified two tasks for the createGUI() method. The first was setting up the
lucky number buttons to be contained in the luckyNumbers array.
Here is the code to do that:
// Create User Interface for applet
public void creatGUI() {
// Set up the selection buttons
Container content = getContentPane();
content.setLayout(new GridLayout(0,1)); // Set the layout for the
applet
// Set up the panel to hold the lucky number buttons
JPanel buttonPane = new JPanel();
// Add the pane
containing numbers
// Let's have a fancy panel border
buttonPane.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(Color.cyan,
Color.blue),
"Every One
a Winner!"));
int[] choices = getNumbers();
// Get initial set of
numbers
Search WWH ::




Custom Search