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 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..
View Answers
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");
t1.addKeyListener(new KeyAdapter() {
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()) {
JOptionPane.showMessageDialog(null, "Please enter only numbers");
}
}
});
b.addActionListener(new ActionListener(){
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");
}
}
});
p1.add(l1);
p1.add(t1);
p1.add(b);
p2.add(l2);
p2.add(t2);
p2.add(l3);
p2.add(t3);
p2.add(l4);
p2.add(t4);
p2.add(l5);
p2.add(t5);
p.add(p1);
p.add(p2);
add(p);
setVisible(true);
pack();
}
public static void main(String[] args)
{
ConvertMile m=new ConvertMile();
}
}
Thanks
Related Tutorials/Questions & Answers:
GUI and how to convert a distance - Java BeginnersGUI 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 GUIHOW 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
Advertisements
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 to GUIconvert 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 ??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 GUIconvert 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 GUIconvert 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 GUIconvert 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 GUIconvert 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 GUIconvert 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 GUIconvert 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 GUIconvert 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 GUIconvert 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 GUIconvert 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 GUIconvert 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 GUIconvert 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
convert this code to GUIconvert 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
Convert this code to GUI - Java Beginners);
}
} hi friend,
We have
convert your code into
GUI...
Convert this code to GUI I have written this.i need to
convert the following code to
GUI:-
import java.awt.*;
import java.applet.*;
import
GUI convert to celsius program - Java BeginnersGUI convert to celsius program
how to write java
GUI program to
convert Fahrenheit to Celsius that need user to input value of Fahrenheit then click button
convert and value of Celsius will display as a output. Hi
"Urgent" convert this code to GUI - Swing AWT"Urgent"
convert this code to GUI
please
convert for me this code to
GUI
THE CODES ARE BELOW, CLASS ATMCaseStudy is the driver class that runs all the other classes. its very urgent.
//CLASS CashDispenser
public class
please convert for me this code to GUI - Swing AWTplease
convert for me this code to
GUI
THE CODES ARE BELOW, CLASS ATMCaseStudy is the driver class that runs all the other classes. its very urgent.
// class ATM
import javax.swing.*;
import java.awt.*;
public
please convert for me this code to GUI - Swing AWTplease
convert for me this code to GUI THE CODES ARE BELOW, CLASS ATMCaseStudy is the driver class that runs all the other classes. its very urgent.
// class ATM
import javax.swing.*;
import java.awt.*;
public class ATM
how to do gui is RM" + num1);
}
}
}
how to do
gui for this coding..tq
import...
how to do gui import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class ShippingCost {
public static void
Edit DistanceEdit Distance I want java programming ask from user input two string and the program find the edit
distance between two strings and find table and optimal solution using
GUI GUIGUI
How to
GUI in Net-beans ... ??
Please visit the following link:
http://www.roseindia.net/java/java-tips/background/30java_tools/netbeans.shtml
how to connect mysql from gui?how to connect mysql from
gui? i am unable to connet to mysql server from my projet that is
gui for mysql...can anyone help me in this...its urgent? i have to connet to mysql from
gui..
Hi Friend,
Try the following
How to Convert ArrayList to Array?How to
Convert ArrayList to Array? Hi,
I am trying to learn to
Convert ArrayList to Array.
How it is possible?
How to
Convert ArrayList to Array?
Thanks
Hi,
To
Convert ArrayList to array ArrayList.toArray
How to convert NSString to NSInteger?How to
convert NSString to NSInteger? Hi,
Provide me code to
convert NSString into NSInteger.
Thanks
Hi,
Use the following code example:
NSString * s= @"100";
NSInteger i = [s intValue];
Thanks
how to convert ACSII to HEXhow to
convert ACSII to HEX
How to
convert perticular ASCII... value of ~:00
The given code accepts the string and
convert...() to
convert it to Hex value.
class ConvertAsciiToHex
{
public static void
How to Convert String to Date?How to
Convert String to Date? Hi,
I am new in Java and learning... have to
convert it to Date object.
Tell me
How to
Convert String to Date?
Thanks
Hi Dude,
Its very easy to
convert the String into date format
How to convert a String to an int?How to
convert a String to an int? I my program I am taking... format. Now I want to
convert into int value.
Tell me
How to
convert a String... contains the value 1025, then you can use the following code to
convert the String
How to convert String into java.util.DateHow to
convert String into java.util.Date Hi,
How I can
convert String date into java.util.Date in a Java program?
Thanks
Hi...
Getting time in Milliseconds
Convert Date To Calendar
How to
convert String Date