RunDemos - Displays a menu of demo names and runs each as clicked.
To be runnable a class must have either method openWindows
or method runForOutput.
Method openWindows has no arguments and returns an arrays of JFrames.
The JFrames will be displaying. Sample for a single window
public static JFrame[] openWindows() {
JFrame frame = {method that inits a JFrame}
javax.swing.SwingUtilities.invokeLater(
() -> { frame.setVisible(true); }
);
return new JFrame[] {frame};
}
Method runForOutput has no arguments and returns no value.
public static void runForOutput() {
{call method(s) that output to stdout}
}
Usually the main method should just call one of the two methods
public static void main(String[] args) {
openWindows(); // OR runForOutput
}
A client generally builds a subclass of RunDemos and executes it.
The subclass calls addDemo to add buttons to the list:
package com.physpics.check.tools;
import com.physpics.tools.RunDemos;
public class DemoAllTools extends RunDemos {
public DemoAllTools() {
super();
addDemo("com.physpics.check.tools.CheckIOUtils");
addDemo("...");
}
public static void main(String[] args) {
new DemoAllTools().showMenu();
}
}
Alternatively, RunDemos can be run as a main program.
It expects a list of test programs in the current directory as file
defaultDemoNames.txt
Each line of the file is the fully qualified name
of a class to be demo'ed.