private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String box1 = (String)jComboBox1.getSelectedItem();
String box2 = (String)jComboBox2.getSelectedItem();
//------------------------------------------------------------------------------
if(box1.equals("Celsius") && box2.equals("Fahrenheit"))
{
double c = Double.parseDouble(jTextField1.getText());
double f = (double)(c * 1.8 + 32);
jTextField2.setText(String.valueOf(f));
}
else if(box1.equals("Celsius") && box2.equals("Kelvin"))
{
double c = Double.parseDouble(jTextField1.getText());
double k = (double)(c + 273.15 );
jTextField2.setText(String.valueOf(k));
}
else if(box1.equals("Celsius") && box2.equals("Celsius"))
{
double c = Double.parseDouble(jTextField1.getText());
jTextField2.setText(String.valueOf(c));
}
//------------------------------------------------------------------------------
if(box1.equals("Fahrenheit") && box2.equals("Celsius"))
{
double f = Double.parseDouble(jTextField1.getText());
double c = (double)((f - 32)*5/9);
jTextField2.setText(String.valueOf(c));
}
else if(box1.equals("Fahrenheit") && box2.equals("Kelvin"))
{
double f = Double.parseDouble(jTextField1.getText());
double k = (double)((f - 32)*5/9 + 273.15);
jTextField2.setText(String.valueOf(k));
}
else if(box1.equals("Fahrenheit") && box2.equals("Fahrenheit"))
{
double f = Double.parseDouble(jTextField1.getText());
jTextField2.setText(String.valueOf(f));
}
//------------------------------------------------------------------------------
if(box1.equals("Kelvin") && box2.equals("Celsius"))
{
double k = Double.parseDouble(jTextField1.getText());
double c = (double)(0 - 273.15);
jTextField2.setText(String.valueOf(c));
}
else if(box1.equals("Kelvin") && box2.equals("Fahrenheit"))
{
double k = Double.parseDouble(jTextField1.getText());
double f = (double)(0 - 273.15) * 9/5 +32;
jTextField2.setText(String.valueOf(f));
}
else if(box1.equals("Kelvin") && box2.equals("Kelvin"))
{
double k = Double.parseDouble(jTextField1.getText());
jTextField2.setText(String.valueOf(k));
}
}
30 дек 2018