import java.util.*;
import javax.swing.*;


/**
 * A simple example of a GUI application 
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
//[declaration.
public class      BadRandomMessageSwingApplication
       implements Runnable
//]declaration.
{
    // Attributes
    private JLabel                label;       

    // The pseudo-random number generator
    private static Random         rng = new Random();    

    // The messages
    private static final String[] MESSAGES = 
    {
       "What a great example!",
       "This class is great.",
       "I can't wait to do the programming assignments.",
       "I wish lectures lasted for 5 hours.",
       "I've never had a better Professor."
    };

//[main.

    /**
     * The entry point of the application
     *
     * @param args   The command-line arguments
     */
    public static void main(String[] args) throws Exception
    {
       SwingUtilities.invokeAndWait(
                      new BadRandomMessageSwingApplication());
    }
//]main.
    
    
    /**
     * "Create" a message at random
     *
     * @return   The message
     */
    private static String createRandomMessage()
    {
       return  MESSAGES[rng.nextInt(MESSAGES.length)];
    }

    
//[run.

    /**
     * The code to be executed in the event dispatch thread
     * (required by Runnable)
     */
    public void run()
    {
       JFrame                    window;     
       JPanel                    contentPane;
       String                    s;
       
       // Select a message at random
       s = createRandomMessage();

       // Construct the "window"
       window = new JFrame();
       window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);       
       window.setSize(600,400);
       
       // Get the container for all content
       contentPane = (JPanel)window.getContentPane();
       contentPane.setLayout(null);  
       
       // Add a component to the container
       label = new JLabel(s, SwingConstants.CENTER);
       label.setBounds(50,50,500,100);       
       contentPane.add(label);    

       // Make the "window" visible
       window.setVisible(true);
    }
//]run.

}
