package cam.visuals.plots; // //################################################################### // Class PlotFrameTest //################################################################### // // A sample class which demonstrates the use of the // the PlotFrame class. When the user clicks the Show Plot // button, a PlotFrame is created and shown. // // Creator Marc Hoefer // // Modifications: // 10/18/98 - Chris Anderson - // Migration to Java 1.1 event model + bug fixes // // (C) UCLA 1997, 1998 // //################################################################### // import java.awt.*; public class PlotFrameTest extends Frame { public PlotFrameTest() { //{{INIT_CONTROLS setLayout(null); setVisible(false); setSize(351,220); PlotButton = new java.awt.Button(); PlotButton.setLabel("Show Plots"); PlotButton.setBounds(128,124,88,40); PlotButton.setForeground(new Color(255)); add(PlotButton); setTitle("Plot Frame Test"); setResizable(false); //}} //{{REGISTER_LISTENERS SymWindow aSymWindow = new SymWindow(); this.addWindowListener(aSymWindow); SymAction lSymAction = new SymAction(); PlotButton.addActionListener(lSymAction); //}} } //{{DECLARE_CONTROLS java.awt.Button PlotButton; //}} public PlotFrameTest(String title) { this(); setTitle(title); } public synchronized void show() { move(50, 50); super.show(); } public void createPlot() { PlotFrame PF = new PlotFrame(); PF.setPlotTitle("Damping", new Font("TimesRoman",Font.BOLD,26),Color.black); PF.setAxisLabels("Time", "Displacement", new Font("TimesRoman",Font.ITALIC,14),Color.black); int nSteps = 500; double[] x1 = new double[nSteps]; double[] y1 = new double[nSteps]; double[] y2 = new double[nSteps]; double[] y3 = new double[nSteps]; double[] y4 = new double[nSteps]; // // Create plot data // for(int i=0;i<nSteps;i++) { x1[i] = 40.0*i/(double)(nSteps-1); y1[i] = Math.exp(-x1[i]/20.0)*Math.sin(.99874922*x1[i]); y2[i] = Math.sin(.99874922*x1[i]); y3[i] = Math.exp(-x1[i]/20.0); y4[i] = -Math.exp(-x1[i]/20.0); } /* set label format */ Plot P = PF.getPlot(); P.setXlabelFormat(Plot.FIXED); P.setXlabelPrecision(3); P.setYlabelFormat(Plot.SCIENTIFIC); P.setYlabelPrecision(2); PF.addPlot(x1,y1,"Damped Oscillator"); PF.addPlot(x1,y2,"UnDamped Oscillator"); PF.addPlot(x1,y3,"Upper Envelope"); PF.addPlot(x1,y4,"Lower Envelope"); PF.show(); } class SymWindow extends java.awt.event.WindowAdapter { public void windowClosing(java.awt.event.WindowEvent event) { Object object = event.getSource(); if (object == PlotFrameTest.this) PlotFrameTest_WindowClosing(event); } } void PlotFrameTest_WindowClosing(java.awt.event.WindowEvent event) { setVisible(false); // hide the Frame dispose(); // free the system resources System.exit(0); // close the application } class SymAction implements java.awt.event.ActionListener { public void actionPerformed(java.awt.event.ActionEvent event) { Object object = event.getSource(); if (object == PlotButton) PlotButton_ActionPerformed(event); } } void PlotButton_ActionPerformed(java.awt.event.ActionEvent event) { createPlot(); } public static void main(String[] args) { (new PlotFrameTest()).show(); } }