package Übungen.TaschenrechnerGUI;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class View extends JFrame {
	// Fenster Eigenschaften:
	final int WIDTH = 500;
	final int HEIGHT = 500;
	
	// Fenster Elemente:
	JTextField eingabe = new JTextField();
	JLabel ergebnisse = new JLabel();
	JLabel error = new JLabel();
	
	 JButton button1 = new JButton("1");
     JButton button2 = new JButton("2");
     JButton button3 = new JButton("3");
     JButton button4 = new JButton("4");
	 JButton button5 = new JButton("5");
     JButton button6 = new JButton("6");
     JButton button7 = new JButton("7");
     JButton button8 = new JButton("8");
     JButton button9 = new JButton("9");
     JButton button0 = new JButton("0");
     JButton plus = new JButton("+");
     JButton minus = new JButton("-");
     JButton multi = new JButton("x");
     JButton divid = new JButton("÷");
     JButton punkt = new JButton(".");
     JButton berechnen = new JButton("=");
     JButton clear = new JButton("C");
     JButton back = new JButton("←");
     
     int buttonWidth = 60;
     int buttonheight = 30;
   
     
	public View() {
		this.setTitle("Taschenrechner");
		this.setSize(WIDTH, HEIGHT);
		this.setResizable(false);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
		this.setLayout(null);
		
		ergebnisse.setBounds(40, 60, 300, 40);
		error.setBounds(40, 60, 100, 30);
		eingabe.setBounds(40, 100, buttonWidth * 6 + 20, 40);
		button1.setBounds(40,150,buttonWidth,buttonheight);
		button2.setBounds(120,150,buttonWidth,buttonheight);
		button3.setBounds(200,150,buttonWidth,buttonheight);
		button4.setBounds(40,190,buttonWidth,buttonheight);
		button5.setBounds(120,190,buttonWidth,buttonheight);
		button6.setBounds(200,190,buttonWidth,buttonheight);
		button7.setBounds(40,230,buttonWidth,buttonheight);
		button8.setBounds(120,230,buttonWidth,buttonheight);
		button9.setBounds(200,230,buttonWidth,buttonheight);
		button0.setBounds(40,270,buttonWidth*2 + 20,buttonheight);
		punkt.setBounds(200, 270, buttonWidth, buttonheight);
		
		plus.setBounds(280, 150, buttonWidth, buttonheight);
		plus.setBackground(Color.GRAY);
		plus.setForeground(Color.WHITE);
		minus.setBounds(280, 190, buttonWidth, buttonheight);
		minus.setBackground(Color.GRAY);
		minus.setForeground(Color.WHITE);
		multi.setBounds(280, 230, buttonWidth, buttonheight);
		multi.setBackground(Color.GRAY);
		multi.setForeground(Color.WHITE);
		divid.setBounds(280, 270, buttonWidth, buttonheight);
		divid.setBackground(Color.GRAY);
		divid.setForeground(Color.WHITE);
		
		
		
		clear.setBackground(Color.RED);
		clear.setForeground(Color.white);
		clear.setBounds(360,150 , buttonWidth, buttonheight);
		
		back.setBackground(Color.ORANGE);
		back.setForeground(Color.white);
		back.setBounds(360,190, buttonWidth, buttonheight);
		
		berechnen.setBackground(Color.GRAY);
		berechnen.setForeground(Color.WHITE);
		berechnen.setBounds(360, 230, buttonWidth, buttonheight* 2 + 10);
		
		this.add(clear);
		this.add(error);
		this.add(ergebnisse);
		this.add(eingabe);
		this.add(button1);
		this.add(button2);
		this.add(button3);
		this.add(button4);
		this.add(button5);
		this.add(button6);
		this.add(button7);
		this.add(button8);
		this.add(button9);
		this.add(button0);
		this.add(punkt);
		this.add(plus);
		this.add(minus);
		this.add(multi);
		this.add(divid);
		this.add(berechnen);
		this.add(back);
		
	}
	
	public void updateErgebnisse(String  erg) {
		ergebnisse.setText(erg);
	}
	
	public void showError(String err) {
		ergebnisse.setText(err);
	}
	
	public void setEingabe(String auswahl) {
		eingabe.setText(auswahl);
	}
	
	
	
	
	public void setAction(ActionListener actionListener) {
		button1.addActionListener(actionListener);
        button2.addActionListener(actionListener);
        button3.addActionListener(actionListener);
        button4.addActionListener(actionListener);
        button5.addActionListener(actionListener);
        button6.addActionListener(actionListener);
        button7.addActionListener(actionListener);
        button8.addActionListener(actionListener);
        button9.addActionListener(actionListener);
        button0.addActionListener(actionListener);
        punkt.addActionListener(actionListener);
        plus.addActionListener(actionListener);
        minus.addActionListener(actionListener);
        divid.addActionListener(actionListener);
        multi.addActionListener(actionListener);
        eingabe.addActionListener(actionListener);
        berechnen.addActionListener(actionListener);
        clear.addActionListener(actionListener);
        back.addActionListener(actionListener);
	}

	
}
