Senin, 15 November 2010

Konversi Suhu

Sebelumnya, importkan terlebih dahulu
“import java.text.DecimalFormat;”
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double hasil = 0;
DecimalFormat model = new DecimalFormat("#0.0#");
double suhuawal = 0;
suhuawal = Double.parseDouble(txtsuhu.getText());
if (jComboBox1.getSelectedIndex() == 0){
hasil = (suhuawal + 459.67)/1.8;
}else{
hasil = (suhuawal / 1.8) - 459.67;
}
txthasil.setText(String.valueOf(model.format(hasil)));
}

Tidak ada komentar:

Powered By Blogger