RandomGUI - panel = new JPanel(); panel.setPreferredSize...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // RandomGUI.java Author: Lewis/Loftus // // Solution to Programming Project 5.11 //******************************************************************** / import java.awt.Dimension; import java.awt.event.*; import javax.swing.*; import java.util.Random; i public class RandomGUI { private int WIDTH = 100; private int HEIGHT = 75; private int MAX_NUMBER = 100; private JFrame frame; private JPanel panel; private JLabel numberLabel; private JButton randomButton; private Random generator; //----------------------------------------------------------------- // Sets up the GUI. //----------------------------------------------------------------- public RandomGUI() { frame = new JFrame ("Random Numbers"); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); generator = new Random(); numberLabel = new JLabel (String.valueOf(generator.nextInt(MAX_NUMBER)+1)); randomButton = new JButton("New Number"); randomButton.addActionListener (new RandomListener());
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: panel = new JPanel(); panel.setPreferredSize (new Dimension(WIDTH, HEIGHT)); panel.add (numberLabel); panel.add(randomButton); frame.getContentPane().add (panel); } //-----------------------------------------------------------------// Displays the primary application frame. //-----------------------------------------------------------------public void display() { frame.pack(); frame.setVisible(true); } //***************************************************************** // Represents an action listener for the random button. //***************************************************************** private class RandomListener implements ActionListener { //--------------------------------------------------------------// Generates and displays a new random number //--------------------------------------------------------------public void actionPerformed (ActionEvent event) { numberLabel.setText (Integer.toString (generator.nextInt(MAX_NUMBER)+1)); } } }...
View Full Document

This note was uploaded on 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

Page1 / 2

RandomGUI - panel = new JPanel(); panel.setPreferredSize...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online