Page 1401 - Informatica dalla A a Z
P. 1401
btnConverti.addActionListener (this);
}
public void actionPerformed(ActionEvent e)
{
String pulsante = e.getActionCommand( );
double cent, fahr;
if (pulsante.equals( "Converti" ) )
{
try
{
String numeroLetto = txtCentigradi.getText (
);
cent = Double.valueOf ( numeroLetto) .dou-
bleValue( );
fahr = 32+(cent /100) *180;
txtFahrenheit .setText ( ""+fahr );
}
catch(Exception exc )
{
txtFahrenheit.setText ( "" );
}
}
}
}
Convertitore. java
class Convertitore
{
public static void main(String argv[ ] )
{
ConvertFrame f = new ConvertFrameQ;
f.pack ( );
f.setVisible(true);
}
}
Esercitazione: Scrivere il programma per richiedere all’utente il cognome e il nome.
1397