/*
 * HPWindow.java
 * 
 * Copyright (C) 2005-2008 Huseyin Boyaci. All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version. This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. 
 * 
 * See the GNU General Public License version 2 for more details 
 * (a copy is included in the LICENSE file that accompanied this code) 
 * (also available at http://www.gnu.org) You should have received a copy of 
 * the GNU General Public License along with this program; if not, write to 
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
 * Boston, MA 02111-1307, USA.
 * 
 */

import javax.imageio.ImageIO;
import javax.swing.JFrame;

import psychWithJava.NormalWindow;

import java.awt.image.BufferedImage;
import java.io.IOException;

// 1. HPWindow extends NormalWindow, instead of FullScreen
public class HPWindow extends NormalWindow implements Runnable {

  // 2. unlike in FullScreen, which was a JFrame itself,
  // here we need our own JFrame to show stuff 
  static JFrame mainFrame;
  
  public static void main(String[] args) {

    HPWindow nw = new HPWindow();
    nw.setNBuffers(2);
     
    // 3. The only addition is from here .................
    // create a window with the title "HPWindow"
    mainFrame = new JFrame("HPWindow");
    // what shall we do if the user clicks the close button?
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // the location and size of the window: x,y,width,height
    mainFrame.setBounds(0,0,900,600);
    // put our experiment inside the JFrame
    mainFrame.add(nw);
    // show it all
    mainFrame.setVisible(true);
    // for everything you can do with a JFrame see
    // http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html
    // ....................................... up to here
    
    Thread hpnw = new Thread(nw);
    hpnw.start();
  }
  
  public void run(){
    try {
      blankScreen();
      displayText("Hello Psychophysicist (Normal Window)");
      updateScreen();
      Thread.sleep(2000);
      blankScreen();
      hideCursor();
      BufferedImage bi1 = ImageIO.read(
          HPWindow.class.getResource("psychophysik.png"));
      displayImage(bi1);
      updateScreen();
      Thread.sleep(2000);
      blankScreen();
      BufferedImage bi2 = ImageIO.read(
          HPWindow.class.getResource("fechner.png"));
      displayImage(0,0,bi2);
      updateScreen();
      Thread.sleep(2000);
    } catch (IOException e) {
      System.err.println("File not found");
      e.printStackTrace();
    } catch (InterruptedException e) {      
      Thread.currentThread().interrupt();
    }
    finally {
      closeScreen();
    }
  }
}