M
Milkaselnuss
Gast
Ich hab ein Problem. Ich habe ein Programm, in dem ein Zinsrechner verbaut ist (der funtkioniert auch) und ich habe das Ganze mit einem Swing am Anfang erweitert. Jetzt ist es so, dass ich im Swing die Variablen anzeigen will, aber es nicht funktioniert und ich komme auch nicht drauf, wie ich das hinkriegen soll.
Hier der Code:
Hier der Code:
Java:
package Zinsrechner1;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JOptionPane;
public class Fenster extends JFrame implements ActionListener{
private JButton Starten;
private JButton Beenden;
public static String eingabe = "";
public static String prozenteingabe = "";
public static String laufzeitseingabe = "";
public static int Kapital = 0;
public Fenster(){
super ("Zinsrechner");
JPanel Panel1 = new JPanel();
JLabel Leer1 = new JLabel("Letztes Ergebnis:");
JLabel Leer2 = new JLabel("");
JLabel Leer3 = new JLabel("Kapital: " + eingabe);
JLabel Leer4 = new JLabel("Zinssatz: " + prozenteingabe);
JLabel Leer5 = new JLabel("");
JLabel Leer6 = new JLabel("Laufzeit: " + laufzeitseingabe);
JLabel Leer7 = new JLabel("Endkapital: " + Kapital);
JLabel Leer8 = new JLabel("");
Starten = new JButton("Zinsrechner ausführen");
Beenden = new JButton ("Beenden");
Starten.addActionListener(this);
Beenden.addActionListener(this);
Panel1.setLayout(new GridLayout(5,2));
Panel1.add(Leer1);
Panel1.add(Leer2);
Panel1.add(Leer3);
Panel1.add(Starten);
Panel1.add(Leer4);
Panel1.add(Leer5);
Panel1.add(Leer6);
Panel1.add(Beenden);
Panel1.add(Leer7);
Panel1.add(Leer8);
setContentPane(Panel1);
}
public void actionPerformed (ActionEvent Ereignis){
Object Quelle = Ereignis.getSource();
if (Quelle == Beenden){
System.exit(0);
}
if (Quelle == Starten){
int Wiederholung = 0;
int ErrorOption = 0;
String eingabe = JOptionPane.showInputDialog(null, "Wieviel Geld möchten Sie anlegen?");
String prozenteingabe = JOptionPane.showInputDialog("Bei welchem Prozentsatz?");
String laufzeitseingabe = JOptionPane.showInputDialog("Wieviele Jahre soll diese Investition laufen?");
float prozent = Float.parseFloat(prozenteingabe);
float kapital = Float.parseFloat(eingabe);
int laufzeit = Integer.parseInt(laufzeitseingabe);
if (kapital <= 0){
JOptionPane.showConfirmDialog(null, "Ein Fehler ist aufgetreten (Fehler 301)! Kein Kapital angegeben!","Error",JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);
ErrorOption++;}
if (prozent <= 0){
JOptionPane.showConfirmDialog(null, "Ein Fehler ist aufgetreten (Fehler 302)! Kein gültiger Prozentsatz eingegeben!","Error",JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);
ErrorOption++;}
if (laufzeit < 1){
JOptionPane.showConfirmDialog(null, "Ein Fehler ist aufgetreten (Fehler 303)! Keine gültige Laufzeit angegeben!","Error",JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);
ErrorOption++;}
while (Wiederholung < laufzeit)
{
float zinsen = kapital * prozent / 100;
kapital = kapital + zinsen;
Wiederholung++;
}
if (ErrorOption < 1)
JOptionPane.showMessageDialog(null, "In " + laufzeit + " Jahren haben Sie " + kapital + " Euro auf ihrem Konto.", "", JOptionPane.PLAIN_MESSAGE);
}
}
public static void main(String[] args){
Fenster Zinsrechner = new Fenster();
Zinsrechner.setSize(500,250);
Zinsrechner.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Zinsrechner.setVisible(true);
Zinsrechner.setLocationRelativeTo(null);
}
}