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
11 1274
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
Do not use a textfield for output. Use a label instead. Have you gone through a simple event handling tutorial yet?
Uhm no i havnt been through 1 of those yet, could u give me a link?
Thanks for the reply
Uhm no i havnt been through 1 of those yet, could u give me a link?
Thanks for the reply
Have a look at this and this.
uhm had a look at them and it just isnt making any sense
uhm had a look at them and it just isnt making any sense
You can always ask here anything you don't understand.
could 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
could 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
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.
could 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
Your reply really surprises me: the supplied example teaches you something
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,
Jos
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 cmdConvertActionPerformed(java.awt.event.ActionEve nt evt) {
int cm = (int)((Double.parseDouble(txtcm.getText()))
* 2.54);
lblOutput.setText(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
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 cmdConvertActionPerformed(java.awt.event.ActionEve nt evt) {
int cm = (int)((Double.parseDouble(txtcm.getText()))
* 2.54);
lblOutput.setText(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
That's easy: make your 'cm' variable a double then and remove the (int) cast.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ted |
last post by:
I've written a little function to remove everything after the 2nd decimal
place for prices which is as follows: -
ReturnConvertedCurrency = (fix(iSterling * session("ExchangeRate") *
100) / 100)...
|
by: amit |
last post by:
Hi,
What will happen in following scenario..
long a = -2;
longlong b = a
long c;
c = *(ulonglong *)&b;
b = c;
also when
|
by: buda |
last post by:
Let me see if I got this :)
1. I know the rules for type conversions in arithmetic expressions
2. I know that an implicit type conversion is done at assignment, so
float x = 1.23;
int t = (int)...
|
by: MFC |
last post by:
Ok, after three C# books, (C# How to Program, Programming in the Key
of C#, and C# Weekend Crash Course) and three weeks, I believe I have
tried everything to make a certain form function...
|
by: Cap'n Ahab |
last post by:
I have used VB3 - VB6, so learning all this OO stuff is reasonably new
to me (although I looked at Java a few years ago). Anyway, I thought I
would write a small class to begin with, with a...
|
by: pipito |
last post by:
Hi...i am a beginner in C programming...
my question is like this...
im using the scanf in C to accept input data in output area,
printf("name: ");scanf("%s",name);
printf(Address:...
|
by: arindam.mukerjee |
last post by:
I was running code like:
#include <stdio.h>
int main()
{
printf("%f\n", 9/5);
return 0;
}
|
by: robtyketto |
last post by:
Greetings,
I have the following code below which allows the date to be added via a JDBC connection as a STRING.
The value of dateString is inserted into the MS ACCESS database.
What is the...
|
by: robtyketto |
last post by:
Greetings,
I'm a newbie to Java and I cant quite get my head around why it seems most integers appears to be formatted as strings and then later have to be parsed.
The code below, passes in the...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |