Hey all, i recently started java programming and im a bit stuck with it all and just wondered if u could help. What i am trying to do id to convert cm to ft and inches, i have the jframe set up with a text field for entering the cm and a text field ready for the output with a button for the convert. However i have only just started, so could someone possibly help me out with the code please to set me on my way? would be much appriciated
Help with conversions in java
Collapse
X
-
Do not use a textfield for output. Use a label instead. Have you gone through a simple event handling tutorial yet?Originally posted by FozziHey all, i recently started java programming and im a bit stuck with it all and just wondered if u could help. What i am trying to do id to convert cm to ft and inches, i have the jframe set up with a text field for entering the cm and a text field ready for the output with a button for the convert. However i have only just started, so could someone possibly help me out with the code please to set me on my way? would be much appriciated -
I was not giving you a link to a solution for your homework. I was pointing you to a tutorial. You should really be trying to do the homework yourself rather than trying to get someone to give you a solution.Originally posted by Fozzicould u just give me a little help with the coding because i looked at the link and its fareheit but could u help me with the coding for cm to ft and inches, would be much appreciatedComment
-
Your reply really surprises me: the supplied example teaches you somethingOriginally posted by Fozzicould u just give me a little help with the coding because i looked at the link and its fareheit but could u help me with the coding for cm to ft and inches, would be much appreciated
about converting X to Y. The example uses Fahrenheit and Celcius; your Xs
and Ys are centimeters and feet. It doesn't take a rocket scientist to convert
the example's constants and conversion formula to the constants and formulas
you need in your example.
kind regards,
JosComment
-
ok sorry about that guys was in a bit of a rush last night, i sat down this morning and got the basics sorted here is my code:
private void cmdConvertActio nPerformed(java .awt.event.Acti onEvent evt) {
int cm = (int)((Double.p arseDouble(txtc m.getText()))
* 2.54);
lblOutput.setTe xt(cm + " inches ");
However there is just 1 thing that i need help with now, i need the output not to come out as a interger but as a decimalComment
-
That's easy: make your 'cm' variable a double then and remove the (int) cast.Originally posted by Fozziok sorry about that guys was in a bit of a rush last night, i sat down this morning and got the basics sorted here is my code:
private void cmdConvertActio nPerformed(java .awt.event.Acti onEvent evt) {
int cm = (int)((Double.p arseDouble(txtc m.getText()))
* 2.54);
lblOutput.setTe xt(cm + " inches ");
However there is just 1 thing that i need help with now, i need the output not to come out as a interger but as a decimal
kind regards,
JosComment
Comment