//Titel:            09. Tutorial
//Version:          1,0
//Copyright:        Copyright (c) 2013
//Autor:            M. Wilhelm
//Organisation:     HS-Harz
//Beschreibung:     Beispiel JFrame mit Schaltern und Observer

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.Color;

// 1. Import 
// hier fehlt Code: zwei Imports


 // hier fehlt Code: eine Implementierung
public class Tutorial09a extends JFrame implements ActionListener {
  private static int st_fensternummer=0;

  private int fensternummer=0;

   // global fuer addActionListener
   JButton bnCreate = new JButton("create1");
   JButton bnsetBlue = new JButton("setBlue");
   JButton bnsetRed = new JButton("setRed");
   JButton bnsetGreen = new JButton("setGreen");
   JButton bnClose = new JButton("Close");

   JPanel panelBn = new JPanel();

   public Tutorial09a() {
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setGUI();
   }

   private void setGUI() {
      setSize(800, 100);
      fensternummer=++st_fensternummer;
      setTitle("Tutorial09a: "+ fensternummer);

      this.getContentPane().setLayout(new BorderLayout());

      panelBn.setLayout(new FlowLayout(FlowLayout.RIGHT));
      panelBn.add(bnCreate);
      panelBn.add(bnsetBlue);
      panelBn.add(bnsetRed);
      panelBn.add(bnsetGreen);
      panelBn.add(bnClose);

      Farbe farbe = Farbe.getInstance();
      panelBn.setBackground( farbe.color);
       // hier fehlt Code: eine Registrierung

      this.getContentPane().add(panelBn, BorderLayout.NORTH);
      
      setFonts(getContentPane(), 18);

      bnCreate.addActionListener(this);
      bnsetBlue.addActionListener(this);
      bnsetRed.addActionListener(this);
      bnsetGreen.addActionListener(this);
      bnClose.addActionListener(this);
   } // setGUI

   private void setFonts(Container cont, int size) {
      for (int i = 0; i < cont.getComponentCount(); i++) {
         Component c = cont.getComponent(i);
         if (c instanceof JPanel)
            setFonts((JPanel) c, size);
         else
            c.setFont(new Font("Arial", Font.BOLD, size));
      }
   }

   public void actionPerformed(ActionEvent e) {
      if (e.getSource() == bnCreate) {
         create_click();
      }
      if (e.getSource() == bnsetBlue) {
         setBlue_click();
      }
      if (e.getSource() == bnsetRed) {
         setRed_click();
      }
      if (e.getSource() == bnsetGreen) {
         setGreen_click();
      }

      if (e.getSource() == bnClose) {
         System.exit(0);
      }
   }

   private void create_click() {
   }

  private void setBlue_click() {
   }
   private void setRed_click() {
   }
   private void setGreen_click() {
   }


   private void getColor_click() {
   }

  
   public static void main(String[] args) {
      Tutorial09a frame = new Tutorial09a();
      frame.setVisible(true);
   }

} // Tutorial09a



// hier fehlt Code: eine Ableitung
class Farbe  {
  private static Farbe instance = new Farbe();

  private Farbe() {
    color=Color.BLUE;
  }

  public static Farbe getInstance() {
    return instance;
  }

  public Color color;

  // hier fehlt Code: eine Methode


}