# Thread: Create a tab called LengthCalc that converts millimeters, meters, yards, feet, and in

1. Member
Join Date
Apr 2011
Posts
9
Rep Power
0

## Create a tab called LengthCalc that converts millimeters, meters, yards, feet, and in

I just need some help in the right direction. Thanks

The Length Calc tab offers the user a length converter (millimeters, meters, yards, feet, and inches).

Shannon
Last edited by Sarge; 04-21-2011 at 01:31 AM. Reason: insert picture

2. Wow, with such a plethora of information I'm sure people will be showering you with help.
[/sarcasm]

3. Member
Join Date
Apr 2011
Posts
9
Rep Power
0
I wanted to add this pic to the origanial message, this is what the applet should look like

thanks

4. Oooh goodie a picture!

5. Member
Join Date
Apr 2011
Posts
9
Rep Power
0
bascially how do I code this? thanks

6. Are you serious?

I want to build a car. Do you think I could walk up to the Chairman of Ford, show him a drawing and ask "How do I do this?"

7. Member
Join Date
Apr 2011
Posts
9
Rep Power
0
Sorry, so basically here is what I have so far.

//create LengthCalc function
public void createLengthCalc()
{
LengthCalc = new JPanel();
LengthCalc.setLayout(null);

JLabel millimetersLabel = new JLabel("Millimeters:");
millimetersLabel.setBounds(0, 15, 260, 10);

JTextField lengthText3 = new JTextField();
lengthText3.setBounds(10, 15, 150, 20);
JLabel metersLabel = new JLabel("Meters:");
metersLabel.setBounds(10, 40, 260, 20);
JTextField widthText2 = new JTextField();
widthText2.setBounds(10, 40, 150, 20);
JLabel yardsLabel = new JLabel("Yards:");
yardsLabel.setBounds(10, 65, 200, 20);
JTextField depthText2 = new JTextField();
depthText2.setBounds(10, 65, 150, 20);
JLabel feetLabel = new JLabel("Feet:");
feetLabel.setBounds(10, 100, 260, 20);
JLabel inchesLabel = new JLabel("Inches:");
inchesLabel.setBounds(10, 150, 260, 20);

}

the part where im struggling is with the conversion part. thanks

8. Member
Join Date
Apr 2011
Posts
9
Rep Power
0
Any help with this would be great. Thanks

9. Continuing my analogy

The part I'm struggling with is the steering.

10. @Junky
ROFL!

@Sarge
Do you know how to write code that works together? Do you know how to use listeners? More importantly, do you know how to do basic mathematical conversions?

Please ask us a specific question, not just: "I don't know what to do, please post some code."

11. Member
Join Date
Apr 2011
Posts
9
Rep Power
0
//create lengthCalc function
public void createLengthCalc()
{
LengthCalc = new JPanel();
LengthCalc.setLayout( null );

JButton convertButton = new JButton("Convert");
this.setLayout(new FlowLayout());

}
class ConvertListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
double millVal = Double.parseDouble(millimetersField.getText());
double meterVal = Double.parseDouble(metersField.getText());
double yardVal = Double.parseDouble(yardsField.getText());
double feetVal = Double.parseDouble(feetField.getText());
double inchVal = Double.parseDouble(inchesField.getText());
}
}
}

this is where im at now

12. So now what do you think is left to do?

13. Java Code:
```double millVal = Double.parseDouble(millimetersField.getText());
double meterVal = Double.parseDouble(metersField.getText());
double yardVal = Double.parseDouble(yardsField.getText());
double feetVal = Double.parseDouble(feetField.getText());
double inchVal = Double.parseDouble(inchesField.getText());```
See here is the part where I was hoping you could provide some additional information such as what exactly is the program supposed to do?

Your code is getting values from ALL textfields but my assumption is that it should only get the value in one field (all the other should be blank). You then perform the calculations and display the results in the other fields. You have the assignment not us so only you know what the requirements are because you are reluctant to provide any details.

14. Member
Join Date
Apr 2011
Posts
9
Rep Power
0
Thanks for you help if feet is entered then all other fields automatically generate the conversion.

Here is your assignment: You work for a Landscape architect. They have asked you to be a part of their team as they need a computer programmer, analyst, and designer to aid them in calculating engineering specification. Specifically, you have been assigned to the Pools, Hot Tubs and Spas section of their landscaping team. Your skills will be needed in creating a GUI program that calculates engineering specifications.

15. Originally Posted by Sarge
You work for a Landscape architect. They have asked you to be a part of their team as they need a computer programmer, analyst, and designer to aid them in calculating engineering specification. Specifically, you have been assigned to the Pools, Hot Tubs and Spas section of their landscaping team. Your skills will be needed in creating a GUI program that calculates engineering specifications.
Is that it? None of that mentions the LengthCalc function.

16. Member
Join Date
Apr 2011
Posts
9
Rep Power
0
attached is the sample program with screen shots of what the assignment should look like.

The tab i'm struggling with is the LengthCalc tab. which in my code is the createLengthCalc function. This function converts millimeters, meters, yards, feet and inches. Any field recieves an input number on the GUI and the rest of the field are automatically populated.

17. Member
Join Date
Apr 2011
Posts
9
Rep Power
0
I can't get the doc to attach the file is to big even when compressed.

18. What remains right now is to do the calculations and set the textfields to the updated values: "textField.setText(String)".

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•