percent = fatGrams * 9 / calories * 100 ;
The statement is correct, although you must think carefully about operator precidence and associativity to be sure. It is better to use a few parentheses to make the calculation clear:
percent = ((fatGrams * 9) / calories) * 100 ;
JTextField has a
JLabel to its left, and the whole GUI
JLabel at the top to act as a heading.
All this is much as in the previous example.
There is something different about this GUI, though.
The user inputs two values.
The calculation should only be carried out when both values are
With the previous program,
JTextField had a listener registered for it.
When the user typed something and hit
an event was "fired" and the listener received it.
(Design Question: ) Will this style work with the current program?