Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/08/2011, 19:34
Checho360
 
Fecha de Ingreso: marzo-2011
Mensajes: 94
Antigüedad: 13 años, 1 mes
Puntos: 3
Duda con JOptionPane

Por que no funciona el JOptionPane.showMessageDialog(...) que tengo definido en actionPerformed (ActionEvent e) ?? ademas si lo pongo dentro de otra funcion como celsius2farenheit () tampoco funciona...

Código ASP:
Ver original
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. public class udsTemperatura extends JApplet implements ActionListener{
  6.    
  7.     JTextField campo;
  8.     JButton c2f;
  9.     JButton f2c;
  10.    
  11.     public void init (){
  12.  
  13.         Container c = getContentPane ();
  14.         c.setLayout(new FlowLayout () );
  15.        
  16.         JLabel etiqueta = new JLabel ("Introduzca la temperatura : ");
  17.        
  18.         campo = new JTextField (10);
  19.         campo.setEditable (true);
  20.         campo.addActionListener(this);
  21.        
  22.         c2f = new JButton ("Celsius a farenheit");
  23.         f2c = new JButton ("Farenheit a celsius");
  24.        
  25.         c.add(etiqueta);
  26.         c.add(campo);
  27.         c.add(c2f);
  28.         c.add(f2c);
  29.        
  30.     }
  31.    
  32.     public void actionPerformed (ActionEvent e){
  33.    
  34.         String s = campo.getText();
  35.         float nTemp;
  36.        
  37.         if ( e.getSource () == c2f )
  38.             nTemp = celsius2farenheit ( Float.parseFloat(s) );
  39.         else
  40.             nTemp = farenheit2celsius ( Float.parseFloat(s) );
  41.        
  42.         JOptionPane.showMessageDialog ( null, "La nueva temperatura es : " + nTemp );
  43.         showStatus("Hecho!");
  44.        
  45.     }
  46.    
  47.     public float celsius2farenheit (float c){
  48.        
  49.         return (float) ( 9.0 / 5.0 * ( c + 32 ) );
  50.        
  51.     }
  52.    
  53.     public float farenheit2celsius (float f){
  54.        
  55.         return (float) ( 5.0 / 9.0 * ( f - 32 ) );
  56.        
  57.     }
  58.  
  59.    
  60. }

Un saludo!!