H
habkeinen
Gast
Java:
package miniprojekt_5b_temperatur;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Celsius extends JFrame implements ActionListener{
//Textfelder und Buttons
private JButton celsius = new JButton("Celsius");
private JButton fahrenheit = new JButton("Fahrenheit");
private JTextField txtcelsius = new JTextField(20);
private JTextField txtfahrenheit = new JTextField(20);
//Titel und Layout und Regierstierung
public Celsius(){
super("Umrechnung Celsius - Fahrenheit");
setLayout(new GridLayout(2,2));
txtcelsius.setEditable(true);
txtfahrenheit.setEditable(true);
txtcelsius.addActionListener(this);
txtfahrenheit.addActionListener(this);
add(celsius);
add(txtcelsius);
add(fahrenheit);
add(txtfahrenheit);
setSize(400,100);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
// umrechnung der eingabe in die textfields
String c;
c=txtcelsius.getText();
String f;
f= txtfahrenheit.getText();
double c1= Double.valueOf(c).doubleValue();
double f1 = Double.valueOf(f).doubleValue();
if(c1 != 0 && f1 ==0){
f1=(((9/5)*c1)+32);
String f2 = String.valueOf(f1);
txtfahrenheit.setText(f2);
}
else if(f1 !=0 && c1 ==0){
c1=(f1-32)/(9/5);
String f3 =String.valueOf(c1);
txtcelsius.setText(f3);
}
}
public static void main(String[]args){
JFrame haha = new Celsius();
haha.setVisible(true);
}
}
hallo an alle.
hab hier ein quellcode,
ich bekomm den celsius fahrenheit umrechner nicht hin.
die oberfläche funktioniert.
aber irgendwie bekomm ich das mit dem umrechnen von celsius zu fahrenheit und zurück nicht hin.
fehlerbehandlung jetzt mal ausgeschlossen.
wäre über hilfe sehr glücklich.,
vielen dank im vorraus,