import java.awt.*; import java.awt.geom.*; import java.awt.event.*; import java.awt.image.BufferedImage; import java.io.*; import javax.swing.*; public class Graphing extends JApplet { String[] labels = new String[7]; int[] MC_counter = new int[2]; float[][] coords = new float[1001][3]; BufferedImage bimg; public void init() { setBackground(Color.white); } public void drawDemo(String[] labels, int[] MC_counter, float[][] coords, Graphics2D g2) { int i = 0; /* Set the font for the pane */ Font font_f = new Font("monospaced",Font.PLAIN,12); /* Begin by drawing the outlines of the graph */ g2.setColor(Color.black); BasicStroke pen = new BasicStroke(2.0F, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); g2.setStroke(pen); Rectangle2D.Float rc = new Rectangle2D.Float(100F,50F,650F,450F); g2.draw(rc); /* Create the tick marks spaced along the x-axis */ BasicStroke pen2 = new BasicStroke(1.0F, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); g2.setStroke(pen2); Line2D.Float ln1 = new Line2D.Float(165F,500F,165F,495F); g2.draw(ln1); Line2D.Float ln2 = new Line2D.Float(230F,500F,230F,495F); g2.draw(ln2); Line2D.Float ln3 = new Line2D.Float(295F,500F,295F,495F); g2.draw(ln3); Line2D.Float ln4 = new Line2D.Float(360F,500F,360F,495F); g2.draw(ln4); Line2D.Float ln5 = new Line2D.Float(425F,500F,425F,495F); g2.draw(ln5); Line2D.Float ln6 = new Line2D.Float(490F,500F,490F,495F); g2.draw(ln6); Line2D.Float ln7 = new Line2D.Float(555F,500F,555F,495F); g2.draw(ln7); Line2D.Float ln8 = new Line2D.Float(620F,500F,620F,495F); g2.draw(ln8); Line2D.Float ln9 = new Line2D.Float(685F,500F,685F,495F); g2.draw(ln9); /* Create the tick marks along the y-axis */ Line2D.Float ln10 = new Line2D.Float(100F,130F,105F,130F); g2.draw(ln10); Line2D.Float ln11 = new Line2D.Float(100F,210F,105F,210F); g2.draw(ln11); Line2D.Float ln12 = new Line2D.Float(100F,290F,105F,290F); g2.draw(ln12); Line2D.Float ln13 = new Line2D.Float(100F,370F,105F,370F); g2.draw(ln13); /* Draw the labels for each axis */ g2.drawString(labels[0], 325F, 25F); g2.drawString(labels[1], 425F, 525F); g2.drawString(labels[2], 740F, 515F); g2.drawString(labels[3], 90F, 515F); g2.drawString(labels[4], 50F, 250F); g2.drawString(labels[5], 50F, 50F); g2.drawString(labels[6], 50F, 500F); /* Create a red polygon representing solutions where optical RMS is greater than two times nominal */ g2.setColor(Color.red); for (i=1;i<=MC_counter[1];i++) { if (coords[i][0] >= 2.0) { g2.fill3DRect((int)(coords[i][1] - 2),(int)(coords[i][2] - 2), 3, 3, false); } } /* Create a green polygon representing solutions where optical RMS is between one and two times nominal */ g2.setColor(Color.green); for (i=1;i<=MC_counter[1];i++) { if ((coords[i][0] >= 1.0) && (coords[i][0] < 2.0)) { g2.fill3DRect((int)(coords[i][1] - 2),(int)(coords[i][2] - 2), 3, 3, false); } } /* Create a blue polygon representing solutions where optical RMS is between zero and one times nominal */ g2.setColor(Color.blue); for (i=1;i<=MC_counter[1];i++) { if (coords[i][0] < 1.0) { g2.fill3DRect((int)(coords[i][1] - 2),(int)(coords[i][2] - 2), 3, 3, false); } } } public void readfile(String[] labels, int[] MC_counter, float[][] coords) { int i = 0; double temp = 0; String line = " "; /* Read the coordinates and labels from disk */ try { /* Read instance variables from disk */ FileReader file = new FileReader("graphing_data"); BufferedReader buff = new BufferedReader(file); /* Read the labels for the x and y axes */ for (i=0;i<=6;i++) { labels[i] = buff.readLine(); } /* Read the number of solutions to be graphed */ line = buff.readLine(); MC_counter[1] = Integer.valueOf(line).intValue(); /* Read the coordinates of each solution to be graphed */ for (i=1;i<=MC_counter[1];i++) { line = buff.readLine(); temp = Double.valueOf(line).doubleValue(); coords[i][0] = (float)temp; line = buff.readLine(); temp = Double.valueOf(line).doubleValue(); coords[i][1] = (float)temp; line = buff.readLine(); temp = Double.valueOf(line).doubleValue(); coords[i][2] = (float)temp; } buff.close(); } catch (FileNotFoundException exceptFNF) { System.out.println("Error -- " + exceptFNF.toString()); } catch (NullPointerException exceptNP) { System.out.println("Error -- " + exceptNP.toString()); } catch (EOFException exceptEOF) { System.out.println("Error -- " + exceptEOF.toString()); } catch (IOException exceptIO) { System.out.println("Error -- " + exceptIO.toString()); } } public Graphics2D createGraphics2D() { Graphics2D g2 = null; bimg = (BufferedImage) createImage(800, 600); g2 = bimg.createGraphics(); g2.setBackground(getBackground()); g2.clearRect(0, 0, 800, 600); return g2; } public void paint(Graphics g) { Dimension d = getSize(); Graphics2D g2 = createGraphics2D(); readfile(labels, MC_counter, coords); drawDemo(labels, MC_counter, coords, g2); g2.dispose(); g.drawImage(bimg, 0, 0, this); } public static void run() { final Graphing demo = new Graphing(); demo.init(); Frame f = new Frame("Comet/Asteroid Orbit Determination and Ephemeris Software"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} }); f.add(demo); f.pack(); f.setSize(new Dimension(800,600)); f.show(); } public static void main(String argv[]) { final Graphing demo = new Graphing(); demo.init(); Frame f = new Frame("Comet/Asteroid Orbit Determination and Ephemeris Software"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} }); f.add(demo); f.pack(); f.setSize(new Dimension(800,600)); f.show(); } }