Why did we not use setActionCommand() with the doit Button?

A good answer might be:

There will be only one action event---when the user clicks on the single button. So there is no need for the action listener to check which component an event comes from.

Action Listener

The user clicks the "Do It!" button after entering numeric text in the top two TextFields. 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.

Here is the part of the program concerned with all of that:

  . . . . . .
public void actionPerformed( )
{ String userIn ;
userIn = inFat. ;
fatGrams = Integer. ;
userIn = inCal.getText() ; calories = Integer.parseInt( userIn ) ; calcPercent() ;
outPer.setText( + " " ) ;
repaint(); } public static void main ( String[] args ) { percentFat fatApp = new percentFat() ; WindowQuitter wquit = new WindowQuitter(); fatApp.addWindowListener( wquit ); fatApp.setSize( 280, 200 );
fatApp.( true ) ;
}

The definition of the WindowQuitter class is as before (not shown here.)

QUESTION 15:

Fill in the blanks. Click the buttons.

Click Here after you have answered the question