This demo opens a normal window (as opposed to FSEM window
of the earlier version)
and displays one line
of text and two images on an otherwise entirely blank (black) background.
Most of the code is similar to the FullScreen version of
HelloPsychophysicist. The differences are highlighted below.
Above 7 steps are going to be nearly identical in all NormalWindow
implementations, 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.
Note: Unlike in FullScreen applications, you don't have to set number of
video buffers manually (See
HelloPsychophysicist for more on setting number of video
buffers in FullScreen). NormalWindow always uses double buffering
(one back, one front buffer).
See
Chapter 11: Applets, normal window applications, packaging and sharing your work.
See the entire code of HPWindow.java.
The Matlab code is to a great extend the same as the
FullScreen version of
HelloPsychophysicist. The differences are highlighted below.
See
Chapter 11: Applets, normal window applications, packaging and sharing your work.
See the entire code of HPWindow.m.
Make sure that you have installed psychWithJava
package and configured your environment.
javac HPWindow.java
java HPWindow
HPWindow
Precompiled program is in HPWindow.jar,
which is a self running jar file. You can either run it directly
from your browser or download the file on your local disk and run it with a double click.
NormalWindow
manual pages,
FullScreen version of
HelloPsychophysicist.
Pure Java version is in HPWindow.java file.
import psychWithJava.NormalWindow;
import psychWithJava.*;
public class HPWindow extends NormalWindow implements Runnable {
public static void main(String[] args) {
HPWindow nw = new HPWindow();
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);
Thread experiment = new Thread(nw);
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
mainFrame.dispose();
}
Matlab version is located at HPWindow.m file.
import javax.swing.JFrame;
import psychWithJava.NormalWindow;
nw = NormalWindow();
mainFrame = 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);
try
nw = NormalWindow();
mainFrame = JFrame()
% place nw in mainFrame etc.
% Your animation follows
mainFrame.dispose;
catch
mainFrame.dispose();
rethrow(lasterror);
end
nw.displayText(...
'Hello Psychophysicist (from within Matlab)');
nw.updateScreen();
pause(2);
nw.blankScreen();
nw.hideCursor();
Coming soon!