Conversor de temperatura

Solo disponible en BuenasTareas
  • Páginas : 2 (373 palabras )
  • Descarga(s) : 0
  • Publicado : 3 de noviembre de 2011
Leer documento completo
Vista previa del texto
package example8;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*
* @author Mdo
*/
public class Example8 extends JFrame {
private JTextField txt;private JRadioButton celcius,faren, kelvin;
private ButtonGroup grupo;
double x,y,z;
String c,f,k,inicio,value;
public Example8(){
super("Conversor");setLayout(new FlowLayout());
txt=new JTextField("0",10);
//txt.setText("celcius");
add(txt);
celcius =new JRadioButton("c",true);
faren =new JRadioButton("f",true);kelvin =new JRadioButton("k",true);
add(celcius);
add(faren);
add(kelvin);
grupo=new ButtonGroup();
grupo.add(celcius);grupo.add(faren);
grupo.add(kelvin);
inicio="c";
celcius.addItemListener(new RadioButtonHandler());
faren.addItemListener(new RadioButtonHandler());kelvin.addItemListener(new RadioButtonHandler());
}
private class RadioButtonHandler implements ItemListener{
private String value;

public void itemStateChanged(ItemEvent e){if (celcius.isSelected()){
if (inicio.equals("k")){
try{
x=Double.parseDouble(txt.getText());z=x-273.15;
value=String.valueOf(z);
txt.setText(value);}
catch(NumberFormatException x){JOptionPane.showMessageDialog( null,"Tiene que ser un valor numericoigual o mayor a 0");
}
}
else if (inicio.equals("f")){
try{x=Double.parseDouble(txt.getText());
System.out.println(x);
y=((x-32)/1.8);
value=String.valueOf(y);...
tracking img