Bmi Calculator Coding

Only available on StudyMode
  • Topic: Comment
  • Pages : 6 (744 words )
  • Download(s) : 18
  • Published : November 22, 2012
Open Document
Text Preview
import javax.swing.JOptionPane;

public class BMICalculator extends javax.swing.JFrame {

/**
* Creates new form BMICalculator
*/
public BMICalculator() {
initComponents();
}

/**
* This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor.

*/
@SuppressWarnings("unchecked")
//
private void initComponents() {

jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
txtWeight = new javax.swing.JTextField();
txtHeight = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
btnCalculate = new javax.swing.JButton();
btnClear = new javax.swing.JButton();
lblBMI = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("BMI Index Calculator");

jLabel1.setText("Weight (KG) :");

jLabel2.setText("Height (metres):");

jLabel3.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel3.setText("BMI:");

btnCalculate.setText("Calculate");
btnCalculate.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCalculateActionPerformed(evt);

}
});

btnClear.setText("Clear");
btnClear.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnClearActionPerformed(evt);
}
});

lblBMI.setBorder(javax.swing.BorderFactory.createEtchedBorder());

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(42, 42, 42)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txtWeight, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txtHeight, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(layout.createSequentialGroup() .addGap(31, 31, 31)

.addComponent(jLabel3)
.addGap(18, 18, 18)
.addComponent(lblBMI, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGap(22, 22, 22))
.addGroup(layout.createSequentialGroup()
.addGap(41, 41, 41)
.addComponent(btnCalculate)
.addGap(27, 27, 27)
.addComponent(btnClear, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap())
);
layout.setVerticalGroup(...
tracking img