This page was saved using WebZIP 6.0.8.918 (Unregistered) on 01/20/05 오후 3:27:46.
Address: http://www.leepoint.net/notes-java/45examples/20components/20body_mass_index/10-bmi-main.html
Title: Java: Example - BMI Main  •  Size: 2876  •  Last Modified: Fri, 14 Jan 2005 00:25:26 GMT

Java: Example - BMI Main

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
The text from the above example can be selected, copied, and pasted into an editor.