Kilometer to Miles Converter in Java GUI
Submitted by donbermoy on Tuesday, May 6, 2014 - 17:42.
In this tutorial, i will teach you how to create a program for converting kilometer to miles in java with GUI. It is necessary for java beginners to undergo and learn this simple program that i have made.
Now, let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of kmToMiles.java.
2. Import javax.swing package. Hence we will use a GUI (Graphical User Interface) here like the inputting the kilometer.
We will use kmStr as String as an inputbox, variable km for kilometer, and mi for miles.
4. Use variable kmStr as an InputDialogBox for inputting kilometer. And convert the input to double (hence we will input only number here) with the use of variable km.
5. Create the code for formula. We all know that 1km is equivalent to 0.621 miles. So, we will use this formula and pass the value to mi variable.
6. After computing, display the equivalent value of kilometers to miles using JOptionPane.showMessageDialog.
Output:
Here's the full code of this tutorial:
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware
- import javax.swing.*;
- </java
- 3. Declare your variables.
- <java>
- String kmStr;
- double km;
- double mi;
- mi = km * 0.621;
- + mi + " miles.");
- import javax.swing.*;
- public class kmToMiles {
- String kmStr;
- double km;
- double mi;
- //... Input
- //... Computation
- mi = km * 0.621;
- //... Output
- + mi + " miles.");
- }
- }
Add new comment
- 1380 views