Example - BMI Main, Example - BMI GUI and Logic, Example - BMI Notes, Example - BMI Extensions, Example - BMI with DecimalFormat, Example - BMI with try...catch
The Body Mass Index program is divided into two files, the main program is in one file, and the GUI and logic are in another. They could also be in one file, but it is usually easier to work on them when they are in separate files.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
// BMI.java -- Compute Body Mass Index (kg/(m*m)
// Fred Swartz 2003-06-20
// Level : Introductory.
// Structure : Two files, main in one,
// GUI and logic as subclass of JPanel in another.
// Components: JButton, JTextArea
// Containers: JFrame, JPanel
// Layouts : FlowLayout
// Listeners : ActionListener as anonymous local class.
// Other :
import javax.swing.JFrame;
////////////////////////////////////////////////////////////// class BMI
class BMI {
//=============================================== static method main
public static void main(String[] args) {
JFrame window = new JFrame("Body Mass Index");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setContentPane(new BMIPanel());
window.pack();
window.show();
}//end main
}//endclass BMI
|