PDA

View Full Version : cs504 assignment no 2 fall 2011 on 15th November, 2011



Xpert
11-03-2011, 09:46 PM
Instructions
Please read the following instructions carefully before solving & submitting assignment:
It should be clear that your assignment will not get any credit (zero marks) if:
o The assignment is submitted after due date.
o The submitted assignment does not open or file corrupt.
o The assignment is copied (from other student or ditto copy from handouts or internet).
o Student ID is not mentioned in the assignment File or name of file is other than student ID.

Uploading instructions

Your Submission must include:


All the Source Code (.java files) and other if necessary files to compile and run your program.
If and only if there are multiple files to submit place all the files in a Zip file and Upload it on VULMS else only source code file is required to be submitted.


Note: Use Notepad for coding and JDK package for java source code compilation and running (JDK is also available on download section of VULMS)
Objective

The objective of this assignment is

o To give you some practice exercise of GUI and understanding use of it.




(cs506@vu.edu.pk)
GOOD LUCK
Marks: 15
Question:
Write the ideal weight calculator so that height in inches is entered by using a slider. Use the approximate formula:
W = H2 / 30 , for femalehttp://1.bp.blogspot.com/-yJ1RMAmiHSA/TrJ-hXrPHJI/AAAAAAAAATg/GjWP77wAyMg/s1600/cs504.jpg

W = H2 / 28 , for male

where W is the ideal weight in pounds,
H is the height in inches
Set an action command for each radio button using setActionCommand(String).
Add an action listener for each button using addActionListener().
Add a change listener for the slider using addChangeListener().
The ideal weight should be displayed in a text field when the user changes either a radio button or the slider.
Pick initial settings for the buttons and slider. When the program starts up display the ideal weight for those settings.

Note: Your code must justify enough for 15 marks.


Lectures Covered: This assignment covers Lecture # 10-13
Deadline
Your assignment must be uploaded/submitted at or before 15/11/2011.

saneha
11-09-2011, 05:56 PM
import java.awt.*;
import javax.swing.*;
public class Slider
{
public void initGUI()
{
frame = new JFrame("Your Ideal Weight");
l1 = new JLabel("Your Gender");
l2 = new JLabel("Your Height in inches");
l3 = new JLabel("Ideal Weight");
male = new JRadioButton("Male", true);
female = new JRadioButton("Female", false);
tfwt = new JTextField(15);
slider = new JSlider(1, 40, 80, 70);
slider.setPaintTicks(true);
slider.setSnapToTicks(true);
slider.setMajorTickSpacing(10);
slider.setMinorTickSpacing(1);
slider.setPaintLabels(true);
p1 = new JPanel(new GridLayout(1, 2, 0, 75));
p1.add(l1);
p1.add(l2);
p2 = new JPanel(new GridLayout(1, 2, 0, 75));
p2.add(l3);
p2.add(tfwt);
p3 = new JPanel(new GridLayout(2, 1, 20, 0));
p3.add(male);
p3.add(female);
Container container = frame.getContentPane();
container.setLayout(new BorderLayout());
container.add(p1, "North");
container.add(slider, "Center");
container.add(p3, "West");
container.add(p2, "South");
frame.setDefaultCloseOperation(3);
frame.setSize(250, 400);
frame.setVisible(true);
}

public Slider()
{
initGUI();
}

public static void main(String args[])
{
Slider slide = new Slider();
}
JFrame frame;
JLabel l1;
JLabel l2;
JLabel l3;
JRadioButton male;
JRadioButton female;
JTextField tfwt;
JSlider slider;
JPanel p1;
JPanel p2;
JPanel p3;
}

Fawadvu
11-10-2011, 03:15 PM
What is this?????????