This demo opens a Full Screen Exclusive Mode Window and displays one line of text and two images on an otherwise entirely blank (black) screen.
javac HelloPsychophysicist.java
java HelloPsychophysicist
HelloPsychophysicist
import java.awt.image.BufferedImage; import java.io.IOException; import javax.imageio.ImageIO; import psychWithJava.FullScreen;
import psychWithJava.*;
Declare a public class and create a main method The name of the public class must be the same as the first part (the part before .java) of the file name
public class HelloPsychophysicist extends FullScreen implements Runnable { public static void main(String[] args) {
HelloPsychophysicist fs = new HelloPsychophysicist();
fs.setNBuffers(2);
Thread experiment = new Thread(fs); experiment.start();
public void run()
public void run(){ try{ \\your methods for animation } catch(){ \\catch the exceptions, that is, if something goes wrong } finally { \\in the end clean up and return the resources used closeScreen(); }
Above 7 steps are going to be nearly identical in all demos, except the names of files and corresponding public classes. If you use an IDE, such as Eclipse, it will assist you with most of the steps. For instance you won't need to remember which classes to import. IDEs usually determine your import needs and place them in the beginning of your file. They will also warn you that you should have a public method called run() since your class inherits from Runnable interface. They will assist for catching the Exceptions, as well.
try{ displayText("Hello Psychophysicist (pure Java)"); updateScreen(); Thread.sleep(2000);
catch (InterruptedException e) { Thread.currentThread().interrupt(); }
blankScreen(); hideCursor();
BufferedImage bi1 = ImageIO.read( HelloPsychophysicist.class.getResource("psychophysik.png")); displayImage(bi1); updateScreen();
BufferedImage bi1 = ImageIO.read(new File("psychophysik.png"));
catch (IOException e) { System.err.println("Image File not found"); e.printStackTrace(); }
displayImage(0,0,bi2);
See the entire code of HelloPsychophysicist.java
import psychWithJava.*;
import psychWithJava.FullScreen;
fs = FullScreen();
try fs = FullScreen(); % Your animation here % .... fs.closeScreen(); catch fs.closeScreen(); rethrow(lasterror); end
fs.setNBuffers(2); fs.displayText(... 'Hello Psychophysicist (from within Matlab)'); fs.updateScreen(); pause(2); fs.blankScreen(); fs.hideCursor();
bi1 = im2java2d(imread('psychophysik.png','PNG'));
bi1 = ImageIO.read(File('psychophysik.png'));
fs.displayImage(bi1);
See the entire lising of HelloPsychophysicist.m.