//Titel:            Dialog-Fenster
//Version:
//Copyright:		Copyright (c) 2010
//Autor:
//Organisation:
//Beschreibung:


import java.awt.*;
import javax.swing.*;
import java.awt.event.*;


public class gui_oop2 extends JFrame {

  JButton BnTest1 = new JButton("Test1");
  JButton BnTest2 = new JButton("Test2");
  JButton BnTest3 = new JButton("Test3");
  JButton BnTest4 = new JButton("Test4");
  JButton BnTest5 = new JButton("Test5");

  JTextArea editor = new JTextArea();

  public gui_oop2() {
    setSize(500, 530);
    setLocation(200,100);
    setTitle("GUI mit OOP2");
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setGUI();
  }

  private void setGUI() {

    editor.setFont( new Font("Arial", Font.BOLD,18)  );
    BnTest1.setFont( new Font("Arial", Font.BOLD,18)  );
    BnTest2.setFont( new Font("Arial", Font.BOLD,18)  );
    BnTest3.setFont( new Font("Arial", Font.BOLD,18)  );
    BnTest4.setFont( new Font("Arial", Font.BOLD,18)  );
    BnTest5.setFont( new Font("Arial", Font.BOLD,18)  );

    this.getContentPane().setLayout( new BorderLayout() );

	JPanel pnButton = new JPanel();
	//pnButton.setBackground(Color.red);
	pnButton.setLayout( new FlowLayout() );
	pnButton.add(BnTest1);
	pnButton.add(BnTest2);
	pnButton.add(BnTest3);
	pnButton.add(BnTest4);
	pnButton.add(BnTest5);

    this.getContentPane().add( pnButton, BorderLayout.NORTH );

    BnTest1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
           BnTest1_Click();
        }
    });
    BnTest2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
           BnTest2_Click();
        }
    });
    BnTest3.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
           BnTest3_Click();
        }
    });
    BnTest4.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
           BnTest4_Click();
        }
    });
    BnTest5.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
           BnTest5_Click();
        }
    });

    this.getContentPane().add( new JScrollPane(editor), BorderLayout.CENTER );

  } // setGUI

   private void editadd(Object obj) {
     editor.append("\n"+obj);
   }

    private void BnTest1_Click() {
       editor.setText("Test1");
       quadrat q=new quadrat(3);
	  editadd( "a*b: "+q.getFlaeche() );
       kreis kr=new kreis(4);
       editadd( "r*r*pi: "+kr.getFlaeche() );
    }  // BnTest1_Click

    private void BnTest2_Click() {
        editor.setText("Test2");
       quadrat q=new quadrat(3);
       kreis kr=new kreis(4);
       rechteck r = new rechteck(3,6);
       GeoObjekt [] flaechen = new GeoObjekt[3];
       flaechen[0]=q; 
       flaechen[1]=r; 
       flaechen[2]=kr; 
       double summe=0.0;
       for (GeoObjekt geo:flaechen) {
         editadd(geo);
       }
    }  // BnTest2_Click

    private void BnTest3_Click() {
        editor.setText("Test3");
    }  // BnTest3_Click

    private void BnTest4_Click() {
        editor.setText("Test4");
    }  // BnTest4_Click

    private void BnTest5_Click() {
        editor.setText("Test5");
    }  // BnTest5_Click

  public static void main(String[] args) {
    gui_oop2 frame = new gui_oop2();
    frame.setVisible(true);
 }

}  // gui_oop2


abstract class GeoObjekt {
  public abstract double getFlaeche();
}

// --------------

class rechteck extends GeoObjekt {
   public int a;
   public int b;

   public rechteck(int a, int b) {
      System.out.println("in quadrat");
	 this.a=a;
      this.b=b;
   }

   public double getFlaeche() {
	return a*b;
   }
   public String toString() {
     return "Rechteck: a: "+a+"  b: "+b;
   }
}

// --------------

class quadrat extends GeoObjekt {
   public int a;

   public quadrat(int a) {
      System.out.println("in quadrat");
	 this.a=a;
   }

   public double getFlaeche() {
	return a*a;
   }
   public String toString() {
     return "Quadrat: a: "+a;
   }
}

// --------------

class kreis extends GeoObjekt{
   public int r;

   public kreis(int r) {
      System.out.println("in kreis");
	 this.r=r;
   }

  public double getFlaeche() {
	return r*r*Math.PI;
  }
   public String toString() {
     return "Kreis: r: "+r;
   }

}




