* directly on the Frame. The main method is static
* so getting at the Frame is a little trickier.
*/
TwoPlotExample() {
// Instantiate the two plots.
Plot leftPlot = new Plot();
Plot rightPlot = new Plot();
// Set the size of the toplevel window.
setSize(800, 300);
// Create the left plot by calling methods.
// Note that most of these methods should be called in
// the event thread, see the Plot.java class comment.
// In this case, main() is invoking this constructor in
// the event thread.
leftPlot.setSize(350, 300);
leftPlot.setButtons(true);
leftPlot.setTitle("Left Plot");
leftPlot.setYRange(-4, 4);
leftPlot.setXRange(0, 100);
leftPlot.setXLabel("time");
leftPlot.setYLabel("value");
leftPlot.addYTick("-PI", -Math.PI);
leftPlot.addYTick("-PI/2", -Math.PI / 2);
leftPlot.addYTick("0", 0);
leftPlot.addYTick("PI/2", Math.PI / 2);
leftPlot.addYTick("PI", Math.PI);
leftPlot.setMarksStyle("none");
leftPlot.setImpulses(true);
// Call setConnected before reading in data.
leftPlot.setConnected(false, 1);
boolean first = true;
for (int i = 0; i <= 100; i++) {
leftPlot.addPoint(0, i, 5 * Math.cos((Math.PI * i) / 20), !first);
leftPlot.addPoint(1, i, 4.5 * Math.cos((Math.PI * i) / 25), !first);
leftPlot.addPoint(2, i, 4 * Math.cos((Math.PI * i) / 30), !first);
leftPlot.addPoint(3, i, 3.5 * Math.cos((Math.PI * i) / 35), !first);
leftPlot.addPoint(4, i, 3 * Math.cos((Math.PI * i) / 40), !first);
leftPlot.addPoint(5, i, 2.5 * Math.cos((Math.PI * i) / 45), !first);
leftPlot.addPoint(6, i, 2 * Math.cos((Math.PI * i) / 50), !first);
leftPlot.addPoint(7, i, 1.5 * Math.cos((Math.PI * i) / 55), !first);
leftPlot.addPoint(8, i, 1 * Math.cos((Math.PI * i) / 60), !first);
leftPlot.addPoint(9, i, 0.5 * Math.cos((Math.PI * i) / 65), !first);
first = false;
}
// Create the right plot by reading in a file.
rightPlot.setButtons(true);
leftPlot.setSize(350, 300);
File file = new File(".", "data.plt");
try {
rightPlot.clear(true);
rightPlot.read(new FileInputStream(file));
} catch (FileNotFoundException ex) {
System.err.println("File not found: " + file + " : " + ex);
} catch (IOException ex) {
System.err.println("Error reading input: " + file + " : " + ex);
}
// Override the title in the file.
rightPlot.setTitle("Right Plot");
// Layout the two plots
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
getContentPane().setLayout(gridbag);