import java.util.*;
import javax.swing.*;

/**
 * A simple example of a GUI JApplet
 *
 * Note: This example contains a subtle mistake.  Specifically, it
 * manipulates GUI elements in the init() method which is
 * NOT called in the event dispatch thread.
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class   BadRandomMessageJApplet 
       extends JApplet
{
    // 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."
    };


    /**
     * Default Constructor
     */
    public BadRandomMessageJApplet()
    {
       super();
    }


    /**
     * "Create" a message at random
     *
     * @return   The message
     */
    private static String createRandomMessage()
    {
       return  MESSAGES[rng.nextInt(MESSAGES.length)];
    }
    

    /**
     * Called to indicate that this JApplet has been loaded
     */
    public void init()
    {
       JPanel                    contentPane;
       String                    s;
       
       // Select a message at random
       s = createRandomMessage();

       // Get the container for all content
       contentPane = (JPanel)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);    
    }
}
