Answer:

There is only one action event that has a registered listener--when the user clicks on the only button. So the action listener does not need to check which component caused an event. Action events from the JTextFields have no registered listener and are ignored.

Action Listener

The user clicks the "Do It!" button after entering numeric text in the top two JTextFields. This generates an ActionEvent which is passed to the registered listener for the button, in this case the same object as contains the button. That object implements ActionListener which means that it has an actionPerformed() method.

int calories ;  // input: total calories per serving
int fatGrams ;  // input: grams of fat per serving
double percent; // result: percent of calories from fat
  . . . . . .
public void actionPerformed(  )
{
  String userIn ;
  
  userIn    = inFat.    ;
  fatGrams  = Integer.   ;
  
  userIn    = inCal.getText()  ;
  calories  = Integer.parseInt( userIn ) ;
  
  calcPercent() ;
  
  outPer.setText( + " " ) ;
  repaint();                  
}

QUESTION 15:

Fill in the blanks. Click the buttons.