Java Reference
In-Depth Information
public BMICalculator() {
super();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("BMI Calculator");
getContentPane().setLayout(
new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
txtMass.setPreferredSize(new Dimension(200,30));
txtHeight.setPreferredSize(new Dimension(200,30));
txtMass.setMaximumSize(txtMass.getPreferredSize());
txtHeight.setMaximumSize(txtHeight.getPreferredSize());
getContentPane().add(new JLabel("Your mass (kg):"));
getContentPane().add(Box.createRigidArea(new Dimension(5,5)));
getContentPane().add(txtMass);
getContentPane().add(Box.createRigidArea(new Dimension(5,5)));
getContentPane().add(Box.createVerticalGlue());
getContentPane().add(new JLabel("Your height (cm):"));
getContentPane().add(Box.createRigidArea(new Dimension(5,5)));
getContentPane().add(txtHeight);
getContentPane().add(Box.createRigidArea(new Dimension(5,5)));
getContentPane().add(Box.createVerticalGlue());
getContentPane().add(btnCalc);
getContentPane().add(Box.createRigidArea(new Dimension(5,5)));
pack();
setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new BMICalculator();
}
});
}
}
2.
Run the project from Eclipse. You should see the window in Figure 11-19.
figure 11-19  
Search WWH ::




Custom Search