Hallo, kann mir jemand helfen, wo der Fehler liegt? Beim ausführen dieses Codes wird das fenster richtig erzeugt, man kann etwas eingeben, aber der rest funktioniert nicht. Würde mich über eine Hilfestellung sehr freuen!
LG
Hier der Code:
[CODE lang="java" title="Währungsrechcner"]package com.company;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Main
{
static JLabel text = new JLabel("Bitte gieb einen Betrag in Euro ein!");
static JLabel dollarsline = new JLabel("Dollars!");
static JLabel poundsline = new JLabel("Pfund!");
static JLabel yenline = new JLabel("Yen!");
static JFrame frame = new JFrame("Der Währungsrechner! - Damit hast du noch nicht gerechnet");
static JTextField textfield = new JTextField("");
static JButton button = new JButton("Umrechnen");
static Double money;
public static void main(String[] args)
{
openUI();
}
public static void openUI (){
frame.setLocation(150,150);
frame.setSize(800,500);
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
textfield.setBounds(50,50,200,30);
textfield.setText("");
frame.add(textfield);
frame.setLayout(null);
frame.setVisible(true);
frame.add(button);
button.setBounds(250,50,100,30);
frame.add(text);
text.setBounds(50,5,300,30);
frame.add(dollarsline);
dollarsline.setBounds(50,90,300,30);
frame.add(poundsline);
poundsline.setBounds(50,120,300,30);
frame.add(yenline);
yenline.setBounds(50,150,300,30);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String textfromtextfield = textfield.getText();
Double = Integer.parseInt(textfromtextfield);
convertToDollars(money);
convertToPounds(money);
convertToYen(money);
}
});
}
public static void convertToDollars (Double eur )
{
dollarsline.setText("Der Betrag in Dollar ist " + eur * 1.13 + "$ ");
}
public static void convertToPounds (Double eur )
{
poundsline.setText("Der Betrag in Pfund ist " + eur * 0.833 + "£");
}
public static void convertToYen (Double eur )
{
yenline.setText("Der Betrag in Yen ist " + eur * 132.31 + "¥");
}
}
[/CODE]
LG
Hier der Code:
[CODE lang="java" title="Währungsrechcner"]package com.company;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Main
{
static JLabel text = new JLabel("Bitte gieb einen Betrag in Euro ein!");
static JLabel dollarsline = new JLabel("Dollars!");
static JLabel poundsline = new JLabel("Pfund!");
static JLabel yenline = new JLabel("Yen!");
static JFrame frame = new JFrame("Der Währungsrechner! - Damit hast du noch nicht gerechnet");
static JTextField textfield = new JTextField("");
static JButton button = new JButton("Umrechnen");
static Double money;
public static void main(String[] args)
{
openUI();
}
public static void openUI (){
frame.setLocation(150,150);
frame.setSize(800,500);
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
textfield.setBounds(50,50,200,30);
textfield.setText("");
frame.add(textfield);
frame.setLayout(null);
frame.setVisible(true);
frame.add(button);
button.setBounds(250,50,100,30);
frame.add(text);
text.setBounds(50,5,300,30);
frame.add(dollarsline);
dollarsline.setBounds(50,90,300,30);
frame.add(poundsline);
poundsline.setBounds(50,120,300,30);
frame.add(yenline);
yenline.setBounds(50,150,300,30);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String textfromtextfield = textfield.getText();
Double = Integer.parseInt(textfromtextfield);
convertToDollars(money);
convertToPounds(money);
convertToYen(money);
}
});
}
public static void convertToDollars (Double eur )
{
dollarsline.setText("Der Betrag in Dollar ist " + eur * 1.13 + "$ ");
}
public static void convertToPounds (Double eur )
{
poundsline.setText("Der Betrag in Pfund ist " + eur * 0.833 + "£");
}
public static void convertToYen (Double eur )
{
yenline.setText("Der Betrag in Yen ist " + eur * 132.31 + "¥");
}
}
[/CODE]