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

• 04-21-2011, 01:30 AM
Sarge
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
• 04-21-2011, 01:33 AM
Junky
Wow, with such a plethora of information I'm sure people will be showering you with help.
[/sarcasm]
• 04-21-2011, 01:33 AM
Sarge
I wanted to add this pic to the origanial message, this is what the applet should look like

thanks
• 04-21-2011, 01:36 AM
Junky
Oooh goodie a picture!

• 04-21-2011, 01:37 AM
Sarge
bascially how do I code this? thanks
• 04-21-2011, 01:42 AM
Junky
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?"
• 04-21-2011, 01:52 AM
Sarge
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
• 04-21-2011, 04:28 AM
Sarge
Any help with this would be great. Thanks
• 04-21-2011, 04:32 AM
Junky
Continuing my analogy

The part I'm struggling with is the steering.
• 04-21-2011, 05:21 AM
ra4king
@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."
• 04-21-2011, 05:27 AM
Sarge
//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
• 04-21-2011, 05:30 AM
ra4king
So now what do you think is left to do?
• 04-21-2011, 05:39 AM
Junky
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.
• 04-21-2011, 05:47 AM
Sarge
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.
• 04-21-2011, 05:50 AM
Junky
Quote:

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.
• 04-21-2011, 08:43 AM
Sarge
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.
• 04-21-2011, 09:13 AM
Sarge
I can't get the doc to attach the file is to big even when compressed.
• 04-21-2011, 07:34 PM
ra4king
What remains right now is to do the calculations and set the textfields to the updated values: "textField.setText(String)".