import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.lang.NumberFormatException;
import java.text.DecimalFormat;

/**
  *
  * Beschreibung
  *
  * @version 1.0 vom 03.04.2012
  * @author Christine Janischek
  */

public class AKGui extends Applet {
  // Anfang Attribute
  private JLabel lbAK = new JLabel();
  private JLabel lbKaufpreis = new JLabel();
  private JLabel lbRenovierung = new JLabel();
  private JLabel lbSumme = new JLabel();
  private JTextField tfKaufpreis = new JTextField();
  private JTextField tfRenovierung = new JTextField();
  private JTextField tfAK = new JTextField();
  private JButton btBerechnen = new JButton();
  
  Investition investition1 = new Investition();
  private JButton btLoeschen = new JButton();
  private JButton btNebenkosten = new JButton();
  
  //Output formats
  DecimalFormat rate = new DecimalFormat("##.00");
  DecimalFormat euro = new DecimalFormat("###,##0.00 €");
  // Ende Attribute

  public void init() {
    Panel cp = new Panel(null);
    cp.setBounds(0, 0, 386, 236);
    add(cp);
    // Anfang Komponenten

    lbAK.setBounds(16, 16, 294, 24);
    lbAK.setText("Anschaffungskosten der Investition:");
    lbAK.setFont(new Font("MS Sans Serif", Font.PLAIN, 17));
    cp.add(lbAK);
    lbKaufpreis.setBounds(16, 64, 59, 16);
    lbKaufpreis.setText("Kaufpreis:");
    lbKaufpreis.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
    cp.add(lbKaufpreis);
    lbRenovierung.setBounds(16, 96, 159, 16);
    lbRenovierung.setText("Bau-/Renovierungskosten:");
    lbRenovierung.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
    cp.add(lbRenovierung);
    lbSumme.setBounds(16, 128, 195, 16);
    lbSumme.setText("Summe der Anschaffungskosten:");
    lbSumme.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
    cp.add(lbSumme);
    tfKaufpreis.setBounds(224, 56, 137, 24);
    tfKaufpreis.setText("tfKaufpreis");
    cp.add(tfKaufpreis);
    tfRenovierung.setBounds(224, 88, 137, 24);
    tfRenovierung.setText("tfRenovierung");
    cp.add(tfRenovierung);
    tfAK.setBounds(224, 120, 137, 24);
    tfAK.setText("tfAK");
    tfAK.setBackground(Color.YELLOW);
    cp.add(tfAK);
    btBerechnen.setBounds(16, 168, 105, 33);
    btBerechnen.setText("Berechnen");
    btBerechnen.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        btBerechnen_ActionPerformed(evt);
      }
    });
    cp.add(btBerechnen);
    btLoeschen.setBounds(128, 168, 105, 33);
    btLoeschen.setText("Löschen");
    btLoeschen.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        btLoeschen_ActionPerformed(evt);
      }
    });
    cp.add(btLoeschen);
    btNebenkosten.setBounds(240, 168, 129, 33);
    btNebenkosten.setText("Nebenkosten");
    btNebenkosten.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        btNebenkosten_ActionPerformed(evt);
      }
    });
    cp.add(btNebenkosten);
    // Ende Komponenten

  }
  // Anfang Methoden
  public void btBerechnen_ActionPerformed(ActionEvent evt) {
     investition1.setKaufpreis(Double.valueOf(tfKaufpreis.getText()));
     investition1.setRenovierung(Double.valueOf(tfRenovierung.getText()));
     tfAK.setText(String.valueOf(euro.format(investition1.berechne())));
  }

  public void btLoeschen_ActionPerformed(ActionEvent evt) {
     tfKaufpreis.setText("");
     tfRenovierung.setText("");
     tfAK.setText("");
  }

  public void btNebenkosten_ActionPerformed(ActionEvent evt) {
    // TODO hier Quelltext einfügen
  }

  // Ende Methoden

}
