Java Code

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class RandomEx extends JApplet
	implements ActionListener
{
  JButton next;
  JLabel label;
  Random random = new Random( );
  String[ ] quotes = 
   	{
		"What's up doc?",
		"Have you any Grey Poupon?",
		"Can you hear me now?",
		"<HTML><CENTER>What is the average ground speed <BR> of an unladen swallow?",
		"May a platypus lay its eggs in your jockey shorts"
	};
  public void init( )
  {
     setLayout( new BorderLayout( ) );
     next = new JButton( "Next!" );
     next.addActionListener( this );
     label = new JLabel( "Good morning!", JLabel.CENTER );
     label.setFont( new Font( "Serif", Font.BOLD, 16 ) );
     add( next, BorderLayout.NORTH );
     add( label, BorderLayout.CENTER );
  }
  public void actionPerformed( ActionEvent ae )
  {
     Object obj = ae.getSource( );
     if ( obj == next )
     {
     	int index = random.nextInt( quotes.length );
	label.setText( quotes[index] );
     }
  }
}

©2006 by E.S.Boese. All Rights Reserved