Código ASP:
Ver original
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class udsTemperatura extends JApplet implements ActionListener{ JTextField campo; JButton c2f; JButton f2c; public void init (){ Container c = getContentPane (); c.setLayout(new FlowLayout () ); JLabel etiqueta = new JLabel ("Introduzca la temperatura : "); campo = new JTextField (10); campo.setEditable (true); campo.addActionListener(this); c2f = new JButton ("Celsius a farenheit"); f2c = new JButton ("Farenheit a celsius"); c.add(etiqueta); c.add(campo); c.add(c2f); c.add(f2c); } public void actionPerformed (ActionEvent e){ String s = campo.getText(); float nTemp; if ( e.getSource () == c2f ) nTemp = celsius2farenheit ( Float.parseFloat(s) ); else nTemp = farenheit2celsius ( Float.parseFloat(s) ); JOptionPane.showMessageDialog ( null, "La nueva temperatura es : " + nTemp ); showStatus("Hecho!"); } public float celsius2farenheit (float c){ return (float) ( 9.0 / 5.0 * ( c + 32 ) ); } public float farenheit2celsius (float f){ return (float) ( 5.0 / 9.0 * ( f - 32 ) ); } }
Un saludo!!