GUI convert to celsius program

GUI convert to celsius program

View Answers

October 13, 2008 at 1:32 PM

Hi friend,


Code to convert Fahrenheit to Celsius :

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TemperatureConverterInSwing implements ActionListener {

JFrame frame;
JPanel panel;
JTextField fahrenheitText;
JLabel celLabel, fahLabel;
JButton changeTemp;
JTextField celciusText;

public TemperatureConverterInSwing() {

frame = new JFrame("Change Celsius to Fahrenheit");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(new Dimension(180, 80));

panel = new JPanel(new GridLayout(3, 2));
panel.setBorder(BorderFactory.createEmptyBorder(60,
60,
20,
60)
);
addItems();
frame.getRootPane().setDefaultButton(changeTemp);
frame.getContentPane().add(panel, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
private void addItems() {
fahLabel = new JLabel("Fahrenheit", SwingConstants.LEFT);
fahrenheitText = new JTextField(20);

changeTemp = new JButton("Convert");
celLabel = new JLabel("Celcius", SwingConstants.LEFT);
celciusText = new JTextField(20);

changeTemp.addActionListener(this);
panel=new JPanel(new GridLayout(4,1));
panel.add(fahLabel);
panel.add(fahrenheitText);
panel.add(celLabel);
panel.add(celciusText);
panel.add(changeTemp);

celLabel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 5));
fahLabel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 5));
}
public void actionPerformed(ActionEvent event) {
String selected=fahrenheitText.getText();
if (selected.equals("")){
celciusText.setText("");
System.out.println("enter the fahrenheit value");
JOptionPane.showMessageDialog(null,"Enter the fahrenheit value");
}
else{
double f = Double.parseDouble(selected);
double c = (f - 32) / 1.8;
celciusText.setText(Double.toString(c));
}
}
private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
TemperatureConverterInSwing converter = new TemperatureConverterInSwing();
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}


For more information on Swing Examples visit to :

http://www.roseindia.net/java/example/java/swing/

Thanks









Related Tutorials/Questions & Answers:
GUI convert to celsius program - Java Beginners
GUI 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
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
Advertisements
Convert the code to GUI
How to Convert the code to GUI   How to convert a code into GUI
Convert Celsius to Fahrenheit
Convert Celsius to Fahrenheit     ... In this example you will learn how to convert the temperature Celsius to Fahrenheit.... <html> <head> <title>Convert Celsius to Fahrenheit Jsp<
Convert the code to GUI
Java Code to GUI   can any one convert My code to GUI code
Convert the code to GUI
Convert the code   How to convert a code to GUI look alike
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
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
How to create GUI application in Java   How to create GUI application in Java
Convert the code to GUI ??
Convert the code to GUI ??  hi >> can anyone help me to conver this code to GUI ?? /** * @(#)RegistorClass.java * *. * @author...! ***"); System.out.println("*** Please enter your program one instruction
Convert the code to GUI
Convert the code to GUI   can any one convert My code to GUI code... to Simpletron! ***"); System.out.println("*** Please enter your program one... to stop entering your program. ***"); System.out.println
Convert the code to GUI
GUI example for beginners  GUI example for beginners  sory... program one instruction ***"); System.out.println("*** (or data word...("*** Type -99999 to stop entering your program. ***"); System.out.println
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
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
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
GUI application program
GUI application program  Write a GUI application program that meets the following requirements: Create an array with 100 randomly chosen integers. Create a textfield to enter an array index and another textfield to display
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
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
java GUI program - Java Beginners
java GUI program  java program that creates the following GUI, when user enter data in the textfield, the input will be displayed in the textarea.   Hi friend, import javax.swing.*; import
Writing a GUI program - Java Beginners
Writing a GUI program  Hello everyone! I'm trying to write a program... if that number is prime or not. When the second button is pressed the program... to write the code for the GUI. Could anyone please help?  Hi Friend
Java GUI Program - Java Beginners
Java GUI Program  How is the following program supposed to be coded? Write an application that prompts the user to enter the radius of a circle by Day 7 under a thread in your Team Forum called Week Three Program for 10 points
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... JLabel("In Inches"); l5=new JLabel("In CM"); b=new JButton("Convert
"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 AWT
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 ATM import javax.swing.*; import java.awt.*; public
please convert for me this code to GUI - Swing AWT
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 ATM import javax.swing.*; import java.awt.*; public class ATM
Java gui program for drawing rectangle and circle
Java gui program for drawing rectangle and circle   how to write java gui program for drawing rectangle and circle? there shoud be circle.... and the program must also show message dialog "this is a red circle" when click
java program to convert decimal in words
java program to convert decimal in words  write a java program to convert a decimal no. in words.Ex: give input as 12 output must be twelve
Java program - convert words into numbers?
Java program - convert words into numbers?   convert words into numbers?   had no answer sir
Convert Miles To Kilometers program in java
Convert Miles To Kilometers program in java  Write a program... input argument to tell the program whether to convert from kilometres to miles... the table. The program should then print out a table of converted values to 2 decimal
Convert To Java Program - Java Beginners
Convert To Java Program  Can anyone convert this C program codes to Java codes,please...thanks! #include int array[20]; int dcn; int cntr=0; void add(); void del(); void insert(); void display(); void exit(); void
Java GUI to build a Student Registration Program
Java GUI to build a Student Registration Program   Write a program... in sorted order by last name. Demonstrate the correct operation of your program by creating a driver program to load the student data base and the course data
I really need a tutor for Java program that has to do with multithreading and gui!
I really need a tutor for Java program that has to do with multithreading and gui!  I am looking for a Tutor to help me with a Java program, specially GUI and multithreading. If you can tutor, please email me
Convert Temperature
Convert Temperature       This section illustrates you how to convert the temperature from Fahrenheit to Celsius. To convert the temperature, we have created two

Ads