RE:problema con DecimalFormat
MIRA, LO QUE TENGO ES UN CÓDIGO COMO ESTE PERO NO APLICA EL DECIMAL FORMAT GRACIAS
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;
public class temperaturas extends JFrame{
private JLabel jltemp, jlson;
private JTextField jttemp, jtresultado;
private JRadioButton celciusafaren, farenacelcius;
private ButtonGroup grupo;
private double conver, entrada = 0, op = 0;
private DecimalFormat tresDigitos;
private temperaturas(){
super( "Conversión de temperaturas" );
Container contenedor = getContentPane();
contenedor.setLayout( new FlowLayout() );
//Crear las etiquetas y los campos de texto
jltemp = new JLabel( "Temperatura" );
jlson = new JLabel( "Son" );
jttemp = new JTextField( 5 );
jtresultado = new JTextField( 15 ); jtresultado.setEditable( false );
//Crear los botones de Radio
celciusafaren = new JRadioButton( "De Celcius a Farenheit", true );
celciusafaren.setToolTipText( "Convierte de grados centígrados a grados farenheit" );
farenacelcius = new JRadioButton( "De Farenheit a Celcius", false );
farenacelcius.setToolTipText( "Convierte de grados farenheit a grados celcius" );
tresDigitos = new DecimalFormat( "0.00" );
//Crear relación lógica entre los botones de Radio
grupo = new ButtonGroup();
grupo.add( celciusafaren );
grupo.add( farenacelcius );
//Agregar los objetos al contenedor
contenedor.add( jltemp );
contenedor.add( jttemp );
contenedor.add( celciusafaren );
contenedor.add( farenacelcius );
contenedor.add( jlson );
contenedor.add( jtresultado );
//Asignar los escuchadores y manejadores de eventos
manejadorcampodetexto manejador = new manejadorcampodetexto();
jttemp.addActionListener( manejador );
setSize( 180, 190 );
setVisible( true );
}
public static void main( String args[] ){
temperaturas ventana = new temperaturas();
ventana.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
private class manejadorcampodetexto implements ActionListener{
public void actionPerformed( ActionEvent evento ){
if( celciusafaren.isSelected() == true ){
if( evento.getSource() == jttemp ){
entrada = Double.parseDouble( evento.getActionCommand());
op = ( entrada * 1.8 ) +32;
tresDigitos.format( op );
jtresultado.setText( Double.toString( op ) );
}
op = 0;
}
op = 0;
if( farenacelcius.isSelected() == true ){
if( evento.getSource() == jttemp ){
entrada = Double.parseDouble( evento.getActionCommand());
op = ( entrada - 32 )/1.8;
tresDigitos.format( op );
jtresultado.setText( Double.toString( op ) );
}
}
op = 0;
}
}
}