/* * chapter Demos: HPWindow.java * * displays the text "Hello Psychophysicist (Normal Window)" and two images * in a normal window * */ import javax.imageio.ImageIO; import javax.swing.JFrame; import java.awt.image.BufferedImage; import java.io.IOException; import psychWithJava.NormalWindow; // HPWindow extends NormalWindow, instead of FullScreen public class HPWindow extends NormalWindow implements Runnable { static JFrame mainFrame; static final int XO = 100; static final int YO = 100; static final int W = 612; static final int H = 612; public static void main(String[] args) { HPWindow nw = new HPWindow(); // The only addition/change is here: mainFrame = new JFrame(); mainFrame.setBounds(XO,YO,W,H); mainFrame.add(nw); mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // Next two lines are optional mainFrame.setResizable(false); mainFrame.setTitle("Hello Psychophysicist"); // you must set it visible mainFrame.setVisible(true); // up to here Thread hpnw = new Thread(nw); hpnw.start(); } public void run(){ try { 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) {} finally { // and replace this //fs.closeScreen(); mainFrame.dispose(); } } }