// This program reads a leter grade and and displays the running total
// of As, Bs , Cs, Ds, and Fs

// Modified to display results only after actionPerformed() is called once
// Note that the actual calculations using Switch have been cut out

// Imports
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;

public class SwitchTestB extends Applet
             implements ActionListener {
   // Declare GUI objects and primitive data
   Label prompt;      // label for text field
   TextField input;   // text field to enter grades

   int aCount = 0, bCount = 0, cCount = 0,
       dCount = 0, fCount = 0;

   boolean firstGradeEntered;


   // Initialize the applet and identifiers
   public void init()
   {
      prompt = new Label( "Enter grade" );
      input = new TextField( 2 );
      input.addActionListener( this );
      add( prompt );
      add( input );
      firstGradeEntered = false;
   }

   // Display all output
   public void paint( Graphics g )
   {
      if (firstGradeEntered) {

        g.drawString( "Totals for each letter grade:", 25, 40 );
        g.drawString( "A: " + aCount, 25, 55 );
        g.drawString( "B: " + bCount, 25, 70 );
        g.drawString( "C: " + cCount, 25, 85 );
        g.drawString( "D: " + dCount, 25, 100 );
        g.drawString( "F: " + fCount, 25, 115 );
      }
   }

   // Detect Events and Process Input
   public void actionPerformed( ActionEvent e )
   {
      firstGradeEntered = true;
      // Process the letter grade
      // Request that the Applet gets updated
      repaint();  // display summary of results
   }
}
