Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners GUI convert to celsius program
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


lancau
GUI convert to celsius program
1 Answer(s)      6 years and 3 months ago
Posted in : Java Beginners



Advertisement
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 Celsius to Fahrenheit
Convert Celsius to Fahrenheit     ... will learn how to convert the temperature Celsius to Fahrenheit. To change...;head> <title>Convert Celsius to Fahrenheit Jsp</title> <
Advertisements
Convert the code to GUI
How to Convert the code to GUI   How to convert a code into GUI
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
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
Java Code to GUI   can any one convert My code to GUI code
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  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  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.*; 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  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
 

 

 

DMCA.com