import java.awt.;
applets.
Import javax.swing.;
/
Escreva uma descrição da classe M4L1T1 aqui.
@author (seu nome)
@version (uma data ou um número de versão)
/
public class M4L1T1 {
estático JTextField fInput, cInput, kInput;
estático JLabel fLabel, cLabel, kLabel;
classe estática privada ButtonHandler implementa ActionListener {
public void actionPerformed (ActionEvent evt) {
duplo f, c, k;
String fStr, cStr, kStr;
Tente {
fStr = fInput.getText();
f = Double.parseDouble(fStr);
} catch (NumberFormatException e) {
fLabel.setText ("ilegais dados para Farenheit.");
fInput.requestFocus();
retorno;
}
Tente {
RPA = fInput.getText();
c = Double.parseDouble(cStr);
} catch (NumberFormatException e) {
cLabel.setText ("ilegais dados para Celcius.");
cInput.requestFocus();
retorno;
}
Tente {
kStr = kInput.getText();
k = Double.parseDouble(kStr);
} catch (NumberFormatException e) {
kLabel.setText ("ilegais dados para Kelvin.");
kInput.requestFocus();
retorno;
}
Op de seqüência de caracteres = evt.getActionCommand();
se (evt.getSource() = = cInput) {
fInput.setText(celciusToFahrenheit(c));
kInput.setText(celciusToKelvin(c));
} else if (evt.getSource() = = fInput) {
cLabel.setText(fahrenheitToCelcius(f));
}
}
public String celciusToFahrenheit (double c) {
duplo f = c 5/9 + 32;
String fahrenheit = Double.toString(f);
retornar fahrenheit;
}
public String fahrenheitToCelcius (double f) {
duplo c = f 9/5 - 32;
String celcius = Double.toString(c);
retornar celcius;
}
public String celciusToKelvin (double c) {
dupla k = c + 273;
Kelvin de seqüência de caracteres = Double.toString(k);
retornar kelvin;
}
public String kelvinToCelcius (double k) {
duplo c = k - 273;
String celcius = Double.toString(c);
retornar celcius;
}
}
public static void main (String [] Args) {
JFrame janela = new JFrame ("conversor de temperatura");
JPanel principal = JPanel() novo;
JPanel fPanel = novo JPanel();
JPanel cPanel = JPanel() novo;
JPanel kPanel = novo JPanel();
Ouvinte ButtonHandler = ButtonHandler() novo;
FLabel JLabel = JLabel("Farenheit") novo;
JLabel cLabel = JLabel("Celcuis") novo;
JLabel kLabel = new JLabel("Kelvin");
main.setLayout (nova GridLayout(3,1));
fInput = new JTextField ("0", 5);
cInput = new JTextField ("0", 5);
kInput = new JTextField ("0", 5);
fPanel.add(fLabel);
fPanel.add(fInput);
cPanel.add(cLabel);
cPanel.add(cInput);
kPanel.add(kLabel);
kPanel.add(kInput);
Main.Add(fPanel);
Main.Add(cPanel);
Main.Add(kPanel);
window.setContentPane(main);
window.setSize(300,160);
window.setLocation(100,100);
window.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
}
}
Eu pedi um par de vezes, mas com informação não suficiente nas respostas, b/c eu não tenho idéia como fazer isso... Quando eu digitar o Celsius, Fahrenheit e Kelvin permanecem 0... O principal problema é o if instrução você disse que... haha, sim, eu acredito em você, eu não estava pensando quando escrevi essa última parte