// test multiplication facts
// keep answering until you get it right
// only count first response for score

import java.awt.*;        // Container, FlowLayout
import java.awt.event.*;  // ActionEvent, ActionListener
import javax.swing.*;     // JApplet, JButton, JLabel, JTextField

public class Math2 extends JFrame implements ActionListener {

   int answer = 0;
   int right  = 0;
   int wrong = 0;
   int product;
   boolean done = false;
   boolean firsttime = true;
   // graphical user interface components
   JLabel num1Label,num2Label, sumLabel, pointLabel, numrightLabel,numwrongLabel;
   JTextField num1Field, num2Field, sumField,numrightField,numwrongField;
   JTextField status;
  JButton playAgain;

   // set up GUI components
   public Math2()
   {
	  super("Math Problems");   // window title

     GridLayout grid1 = new GridLayout( 8, 1 );  // 8 rows 1 column

	 // get content pane and set its layout
 Container container = getContentPane();
 container.setLayout( grid1 );

      // create label and text field for number 1
      num1Label = new JLabel( "Number 1" );
      container.add( num1Label );
      num1Field = new JTextField( 20 );
      num1Field.setEditable( false );
      container.add( num1Field );

      // create label and text field for number 2
      num2Label = new JLabel( "Number 2" );
      container.add( num2Label );
      num2Field = new JTextField( 20 );
      num2Field.setEditable( false );
      container.add( num2Field );

      // create label and text field for sum
      sumLabel = new JLabel( "Product is" );
      container.add( sumLabel );
      sumField = new JTextField( 20 );
      sumField.setEditable( true );
      sumField.addActionListener(this);
      container.add( sumField );

  // create label and text field for sum
      numrightLabel = new JLabel( "Number Right" );
      container.add( numrightLabel );
      numrightField = new JTextField( 20 );
      numrightField.setEditable( false );
      container.add( numrightField );

  //  // create label and text field for sum
      numwrongLabel = new JLabel( "Number Wrong" );
      container.add( numwrongLabel );
      numwrongField = new JTextField( 20 );
      numwrongField.setEditable( false );
      container.add( numwrongField );

      // create button user clicks to play again
      playAgain = new JButton( "Play Again" );
      playAgain.addActionListener( this );
      container.add(playAgain);

	  //create status bar area
	  status = new JTextField(30);
	  status.setEditable(false);
	  container.add(status);

	  answer = pickNumbers();

   } // end method init

   // process one roll of dice
   private int toInt(String s)
    {int n = 0;
     for (int x=0; x