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

/**
  *
  * description
  *
  * @version 1.0 from 06.10.2018
  * @author 
  */

public class HighscoreGUI extends JFrame {
  // Anfang Attribute
  private JButton bZeichnen = new JButton();
  private PictureViewer imagePanel1 = new PictureViewer();

  private JButton bWastutes = new JButton();
  private Highscore bild;
  private Picture b;
  private Timer timer1 = new Timer(1000, null);
  // Ende Attribute

  public HighscoreGUI (String title) {
    super (title);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    int frameWidth = 768; 
    int frameHeight = 551;
    setSize(frameWidth, frameHeight);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (d.width - getSize().width) / 2;
    int y = (d.height - getSize().height) / 2;
    setLocation(x, y);
    Container cp = getContentPane();
    cp.setLayout(null);
    // Anfang Komponenten
    bZeichnen.setBounds(24, 456, 209, 33);
    bZeichnen.setText("Balkendiagramm zeichnen");
    bZeichnen.setMargin(new Insets(2, 2, 2, 2));
    bZeichnen.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent evt) { 
        bZeichnen_ActionPerformed(evt);
      }
    });
    cp.add(bZeichnen);
    imagePanel1.setBounds(24, 16, 705, 409);
    cp.add(imagePanel1);

    bWastutes.setBounds(280, 456, 201, 33);
    bWastutes.setText("Was tut diese Methode?");
    bWastutes.setMargin(new Insets(2, 2, 2, 2));
    bWastutes.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent evt) { 
        bWastutes_ActionPerformed(evt);
      }
    });
    cp.add(bWastutes);
    timer1.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent evt) { 
        timer1_ActionPerformed(evt);
      }
    });
    b = new Picture(700,800);
     imagePanel1.setImage(b);
    b.setObserver(imagePanel1);
    timer1.setRepeats(true);
    timer1.setInitialDelay(0);
    timer1.setDelay(100);
    timer1.start();
    addWindowListener(new WindowAdapter() { 
      public void windowClosed(WindowEvent evt) { 
        BalkendiagrammGUI_WindowClosed(evt);
      }
    });
    // Ende Komponenten
    setResizable(false);
    setVisible(true);
  }

  // Anfang Methoden
  public void bZeichnen_ActionPerformed(ActionEvent evt) {
    bild = new Highscore();
    imagePanel1.setImage(bild);
    bild.setObserver(imagePanel1);
    imagePanel1.getVerticalScrollBar().setValue(10);
    imagePanel1.getVerticalScrollBar().setValue(0);
    imagePanel1.getViewport().repaint();
  } // end of bZeichnen_ActionPerformed

  public void bWastutes_ActionPerformed(ActionEvent evt) {
   new Thread( new Runnable() {
  @Override public void run() {
    bild.wastutes();
  }
} ).start();
  } // end of bWastutes_ActionPerformed

  public void timer1_ActionPerformed(ActionEvent evt) {
    imagePanel1.getViewport().repaint();

  } // end of timer1_ActionPerformed

  public void BalkendiagrammGUI_WindowClosed(WindowEvent evt) {
    timer1.stop();
    
  } // end of BalkendiagrammGUI_WindowClosed

  // Ende Methoden

  public static void main(String[] args) {
    new HighscoreGUI("HighscoreGUI");
  }
}

