# GUI and how to convert a distance

zam
GUI and how to convert a distance
Posted in : Java Beginners
i need help..
how to create a GUI application that can be is used to convert a distance unit in miles into its corresponding units in kilometer, meter, inches and centimeter. When a user enters a mile value in a text field and followed by pressing a button, its equivalent values in unit of kilometer, meter, inches and centimeter will be displayed in the corresponding text fields. If the user enters the value of miles that is less or equals to zero, a dialogue error message that contains a message ?The value must be greater than zero? will be displayed.
The formula for each of unit conversion is as follows:
1 mile = 2.5 km
1 km = 1000 m
1 meter = 60 inches
1 inches = 2.54 m

--------
i'm use netbeans soffware..

March 15, 2010 at 5:31 PM

Hi Friend,

Through the following values, we have converted miles into different units.
1 mile=1.609344, 1 meter=39.3700787 inches and 1 inch=0.0254 meter.

Try the following:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.regex.*;
import java.text.*;

class ConvertMile extends JFrame{
JTextField t1,t2,t3,t4,t5;
JLabel l1,l2, l3, l4, l5;
JPanel p,p1,p2;
JButton b;
ConvertMile(){
p=new JPanel(new GridLayout(6,2));
p1=new JPanel(new GridLayout(2,2));
p2=new JPanel(new GridLayout(4,2));
t1=new JTextField(20);
t2=new JTextField(20);
t3=new JTextField(20);
t4=new JTextField(20);
t5=new JTextField(20);
l1=new JLabel("Enter distance( in Miles)");
l2=new JLabel("In KM");
l3=new JLabel("In M");
l4=new JLabel("In Inches");
l5=new JLabel("In CM");
b=new JButton("Convert");
public void keyTyped(KeyEvent e) {
String input=t1.getText();
Pattern p = Pattern.compile("[A-Z,a-z,&%\$#@!()*^]");
Matcher m = p.matcher(input);
if (m.find()) {
}
}
});
public void actionPerformed(ActionEvent e){
String value=t1.getText();
double distance=Double.parseDouble(value);
if(distance<=0){
JOptionPane.showMessageDialog(null,"The value must be greater than zero");
}
else{
double km=distance * 1.609344;
double m=km * 1000;
double cm=m * 100;
double inch=m * 39.3700787;
DecimalFormat f = new DecimalFormat("##.### ");
t2.setText(f.format(km)+" KM");
t3.setText(f.format(m)+" M");
t4.setText(f.format(inch)+" Inches");
t5.setText(f.format(cm)+" CM");

}
}
});

setVisible(true);
pack();
}
public static void main(String[] args)
{

ConvertMile m=new ConvertMile();
}
}
Thanks

GUI and how to convert a distance - Java Beginners
GUI and how to convert a distance  i need help.. how to create a GUI application that can be is used to convert a distance unit in miles into its...=new JTextField(20); t5=new JTextField(20); l1=new JLabel("Enter distance
HOW TO CONVERT THIS CODE INTO GUI
HOW TO CONVERT THIS CODE INTO GUI   System.out.println("\n\t UGANDA CHRISTIAN UNIVERSITY\n"); System.out.println("\n\tFACULTY OF SCIENCE AND TECHNOLOGY\n"); System.out.println("\n BACHELOR OF SCIENCE IN COMPUTER
How to convert this Java code into GUI?
How to convert this Java code into GUI?   import java.util.Scanner; public class StudentMarks { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks
Convert the code to GUI
How to Convert the code to GUI   How to convert a code into GUI
Convert the code to GUI
Convert the code   How to convert a code to GUI look alike
convert to GUI
convert to GUI  import java.util.Scanner; public class Exam { public static void main (String args[]) { int numberStudent, mark, markAplus = 0, markA = 0, markBplus = 0, markB = 0, markBminus = 0, i; int markCplus = 0, markC
Convert the code to GUI
Is it possible to convert a code into GUI  Is it possible to convert a code into GUI
Convert the code to GUI
Java Code to GUI   can any one convert My code to GUI code
Convert the code to GUI
How to create GUI application in Java   How to create GUI application in Java
Convert the code to GUI
GUI code  GUI code
Convert the code to GUI
GUI Application example  GUI Application example
Convert the code to GUI
GUI Example  GUI Example code to learn
Convert the code to GUI
Java GUI Class Example  Java GUI Class Example
Convert the code to GUI
GUI Java JSP application  GUI Java JSP application
Convert the code to GUI
GUI Application Development   GUI Application Development
Convert the code to GUI
Java and GUI application Example  Java and GUI application Example
Convert the code to GUI
Write a GUI Application  best way to write a GUI based application
Convert the code to GUI ??
Convert the code to GUI ??  hi >> can anyone help me to conver this code to GUI ?? /** * @(#)RegistorClass.java * *. * @author * @version 1.00 2011/12/16 */ import java.util.Scanner; public class RegistorClass
Convert the code to GUI
Convert the code to GUI   can any one convert My code to GUI code import java.util.Scanner; public class RegistorClass { private int accumulator; private int instructionCounter; private int instructionRegister
Convert the code to GUI
GUI example for beginners  GUI example for beginners  sory ,, I will posted my code again import java.util.Scanner; public class RegistorClass { private int accumulator; private int instructionCounter; private
convert this code to GUI
convert this code to GUI  hello.. this is my code.. import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks
convert this code to GUI
convert this code to GUI  hello.. this is my code.. import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks
convert this code to GUI
convert this code to GUI  hello.. this is my code.. import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.*; class Author{ public String name; public BookList<Book>books=new BookList<Book>(); public Author(){ } public boolean equals(Object node){ return name.equals