Java Reference
In-Depth Information
TRY IT OUT: A Lottery Applet
You can outline the broad structure of the applet's code as follows:
// Applet to generate lottery entries
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
// For random
number generator
public class Lottery extends JApplet {
// Initialize the applet
@Override
public void init() {
// Create interface components on event dispatch thread...
}
// Create User Interface for applet
public void createGUI() {
// Set up the lucky numbers buttons...
// Set up the control buttons...
}
// Class defining custom buttons showing lottery selection
private class Selection extends JButton implements ActionListener {
// Constructor...
public Selection(int value) {
// Create the button showing the value...
}
// Handle selection button event
public void actionPerformed(ActionEvent e) {
// Change the current selection value to a new selection value
}
// Details of the rest of the selection class definition...
}
// Class defining a handler for a control button
private class HandleControlButton implements ActionListener {
// Constructor...
// Handle button click
public void actionPerformed(ActionEvent e) {
// Handle button click for a particular button...
}