Beispiel #1
0
 public void actionPerformed(ActionEvent e) {
   if (!datapanel.isInitialized()) {
     return;
   }
   datapanel.refreshData();
   panel.setDisplayPlot(true);
   panel.update(panel.getGraphics());
   frame.setSize(700, 600);
   frame.setVisible(true);
   frame.pack();
 }
Beispiel #2
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;
    g2d.setPaint(Color.black);
    g2d.setStroke(new BasicStroke());
    g2d.setFont(new Font("Century Schoolbook", Font.PLAIN, 12));
    if (d.isInitialized() && display_plot) {
      d.refreshData();
      Float xLower = d.getXLower();
      Float xUpper = d.getXUpper();
      Float xInterval = d.getXInterval();
      Float yLower = d.getYLower();
      Float yUpper = d.getYUpper();
      Float yInterval = d.getYInterval();
      Float dx = xUpper - xLower;
      Float dy = yUpper - yLower;

      drawCenteredString(g2d, d.getTitle(), 250, 25, (float) 0.);
      drawCenteredString(g2d, d.getXTitle(), 250, 475, (float) 0.);
      drawCenteredString(g2d, d.getYTitle(), 25, 250, (float) -Math.PI / 2);
      drawCenteredString(g2d, xLower.toString(), 50, 475, (float) 0);
      drawCenteredString(g2d, xUpper.toString(), 450, 475, (float) 0);
      drawCenteredString(g2d, yLower.toString(), 25, 450, (float) 0);
      drawCenteredString(g2d, yUpper.toString(), 25, 50, (float) 0);

      g2d.setPaint(Color.gray);
      for (Float x = new Float(50); x <= 450; x += 400 * xInterval / dx)
        g2d.draw(new Line2D.Float(x, 450, x, 50));
      for (Float y = new Float(50); y <= 450; y += 400 * yInterval / dy)
        g2d.draw(new Line2D.Float(45, y, 450, y));

      g2d.setPaint(Color.red);
      Float diam = new Float(8);
      int num_points = d.getNumberOfPoints();
      for (int i = 0; i < num_points; i++) {
        Float ex = 400 * (d.getPoint(i).x - xLower) / dx + 50;
        ex -= diam / 2;
        Float ey = -400 * (d.getPoint(i).y - yLower) / dy + 450;
        ey -= diam / 2;
        g2d.fill(new Ellipse2D.Float(ex, ey, diam, diam));
      }
    }
  }
 public void update() {
   setModel();
   super.update();
 }