December 5, 2011

Ideal Weight Calculator

Ideal Weight Calculator

Code Highlights:

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import javax.swing.event.ChangeEvent;

import javax.swing.event.ChangeListener;

JTextField txtWeight;

static JSlider heightScale;

ButtonGroup btnGroup;

JRadioButtonMenuItem btnMale;

JRadioButtonMenuItem btnFemale;
public void calculate_weight()


String genderValue;



genderValue = btnMale.getActionCommand();




genderValue = btnFemale.getActionCommand();


Integer userHeight = heightScale.getValue();

Integer heightSqr = (userHeight*userHeight);

String idealWeight = Integer.toString(heightSqr/Integer.parseInt(genderValue));




I hope this post ideal weight calculator will help java beginners to understand the JSlider, Radio, Labels and Listeners usage. If any query you have regarding this, must ask.

Last updated: March 19, 2014