예제 #1
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;

    currentX = leftMargin;
    currentY = topMargin;

    // Draw the links

    for (int i = 0; i < linkLines.length; i++) {
      if (weights[i].isActive()) {
        g2.setPaint(weights[i].getColor());
        g2.draw(linkLines[i]);
      }
    }

    g2.setPaint(Color.black);

    // Draw the input neurons
    g2.drawString("Inputs", (float) currentX, (float) currentY);
    currentY += titleSpace;

    for (int i = 0; i < genome.getInputs(); i++) {
      g2.drawImage(inputNeuron, (int) currentX, (int) currentY, null);
      currentY += space;
    }

    // Draw the hidden Neurons
    currentX += space;
    currentY = topMargin;
    g2.drawString("Hidden Layers", (float) currentX, (float) currentY);

    for (int i = 0; i < genome.getHiddenLayers(); i++) {
      currentY = topMargin + titleSpace;
      for (int j = 0; j < genome.getNeuronsInHiddenLayer(); j++) {
        g2.drawImage(hiddenNeuron, (int) currentX, (int) currentY, null);
        currentY += space;
      }
      currentX += space;
    }

    // Draw the output neurons
    currentY = topMargin;
    g2.drawString("Outputs", (float) currentX, (float) currentY);
    currentY += titleSpace;

    for (int i = 0; i < genome.getOutputs(); i++) {
      g2.drawImage(outputNeuron, (int) currentX, (int) currentY, null);
      currentY += space;
    }

    // Draw the links

    for (int i = 0; i < linkLines.length; i++) {
      if (weights[i].isActive()) {
        g2.setPaint(weights[i].getColor());
        g2.draw(linkLines[i]);
      }
    }
  }
예제 #2
0
  protected void paintComponent(Graphics g2) {
    super.paintComponent(g2);

    Graphics2D g = (Graphics2D) g2;
    test.draw(g2, 0, 0);
    // Shape triangle = new Polygon(new int[] {15, 20, 10}, new int[] {0, 10, 10}, 3);

    Shape square = new Rectangle2D.Double(0, 0, 30, 30);

    g.setColor(Color.white);

    g.translate(20, 20);
    // g.rotate(theta, 10, 10);
    // g.fill(star);

    // g.setColor(new Color(0, 86, 141));
    // g.fill(square);
    if (star2 != null) g.fill(star2);

    // Graphics2D g3 = (Graphics2D) g;
    // 3.fill(star);

    // g.setStroke(new BasicStroke(1));
    // g.translate(x, y);
    // g.draw(line);
    // g.draw(line2);

  }
예제 #3
0
    protected void paintComponent(Graphics g) {
      super.paintComponent(g);
      Graphics2D g2 = (Graphics2D) g;
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      int w = getWidth();
      int h = getHeight();
      int pointSize = Math.max(Math.min(w, h) / 80, 4);

      double xInc = (double) (w - 2 * PAD) / (MAX_X - 1);
      double scale = (double) (h - 2 * PAD) / MAX_Y;
      // Draw abcissa.
      int tickInc = MAX_X / 10;
      for (int i = 0; i <= MAX_X; i += tickInc) {
        int x = PAD + (int) (i * xInc);
        int y = h - PAD;
        g.drawString(Integer.toString(i), x - 5, y + 20);
        g2.draw(new Line2D.Double(x, y - 5, x, y + 5));
      }
      g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD / 2, h - PAD));
      AffineTransform orig = g2.getTransform();
      g2.rotate(-Math.PI / 2);
      g2.setColor(Color.black);
      g2.drawString("Number of comparisons", -((h + PAD) / 2), PAD / 3);
      g2.setTransform(orig);

      // Draw ordinate.
      tickInc = (h - PAD) / 10;

      for (int i = tickInc; i < h - PAD; i += tickInc) {
        int x = PAD;
        int closest_10 = ((int) (i / scale) / 10) * 10;

        int y = h - PAD - (int) (closest_10 * scale);
        if (y < PAD) break;
        String tickMark = Integer.toString(closest_10);
        int stringLen = (int) g2.getFontMetrics().getStringBounds(tickMark, g2).getWidth();
        g.drawString(tickMark, x - stringLen - 8, y + 5);
        g2.draw(new Line2D.Double(x - 5, y, x + 5, y));
      }
      g2.draw(new Line2D.Double(PAD, PAD / 2, PAD, h - PAD));
      g.drawString("Array Size", (w - PAD) / 2, h - PAD + 40);

      for (int index = 0; index < plot_data.size(); index++) {
        int[] data = plot_data.get(index);

        // Mark data points.
        g2.setPaint(plot_colors.get(index));

        for (int i = 0; i < data.length; i++) {
          double x = PAD + i * xInc;
          double y = h - PAD - scale * data[i];
          g2.fill(new Ellipse2D.Double(x - pointSize / 2, y - pointSize / 2, pointSize, pointSize));
        }

        g2.setFont(textFont);
        int stringHeight =
            (int) g2.getFontMetrics().getStringBounds(plot_names.get(index), g2).getHeight();
        g.drawString(plot_names.get(index), PAD + 20, PAD + (index + 1) * stringHeight);
      }
    }
예제 #4
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    int i, j, k;
    System.out.println("Starting painting");
    // draw sets

    if (firstTimeAround) {
      drawSet(g2);
      render();
      viewer.save("final_product_full.png");
      firstTimeAround = false;
    }
    // render();
    /* for(i=0;i<viewer.getWidth();i++){
        for(j=0;j<viewer.getHeight();j++){
            viewer.setPixel(i,j,Color3.BLACK);
        }
    }
    */

    g2.setBackground(Color.BLACK);

    //        if(newRender){
    for (i = minX; i < maxX; i++) {
      // System.out.println("line "+i);
      for (j = minY; j < maxY; j++) {

        g2.setColor(
            new Color(
                (float) viewer.getPixel(i, j).getR(),
                (float) viewer.getPixel(i, j).getG(),
                (float) viewer.getPixel(i, j).getB()));
        // g2.drawLine(i,j,1,1);
        Ellipse2D.Double node_circ = new Ellipse2D.Double(i, j, 1, 1);
        g2.fill(node_circ);

        g2.setColor(Color.BLACK);

        // if(j*scale<viewer.getHeight()){
        //       j=0;//viewer.getHeight();
        // }

      }
      // if(i*scale<viewer.getWidth()){
      //    i=0;//viewer.getWidth();
      //  }
    }

    //  g2.drawImage(viewer.1)
    newRender = false;
    // }
    System.out.println("end painting");
  }
예제 #5
0
  // draws the current snapshot
  public void paintComponent(Graphics g) {

    // System.out.println("In paint in draw");
    super.paintComponent(g);
    my_width = getSize().width;
    my_height = getSize().height;
    if (my_image != null) g.drawImage(my_image, 0, 0, my_width, my_height, this);

    setBackground(new Color(1.0f, 1.0f, 1.0f));
    //         g.setColor(Color.black);
    //         g.drawRect(0,0,my_width-1,my_height-1);

  }
예제 #6
0
파일: Arrows.java 프로젝트: rtitec/swixml2
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int w = getWidth();
    int h = getHeight();
    double theta, x, y;

    g2.setPaint(Color.blue);
    double x1 = w * 3 / 24, y1 = h * 3 / 32, x2 = w * 11 / 24, y2 = y1;
    g2.draw(new Line2D.Double(x1, y1, x2, y2));
    // draw this arrow head at point x2, y2 and measure
    // angle theta relative to same point, ie, y2 - and x2 -
    theta = Math.atan2(y2 - y1, x2 - x1);
    drawArrow(g2, theta, x2, y2);

    x1 = w * 3 / 8;
    y1 = h * 13 / 15;
    x2 = w * 2 / 3;
    y2 = y1;
    g2.draw(new Line2D.Double(x1, y1, x2, y2));
    theta = Math.atan2(y1 - y2, x1 - x2);
    drawArrow(g2, theta, x1, y1);

    g2.setPaint(Color.red);
    x1 = w * 3 / 24;
    y1 = h * 4 / 32;
    x2 = x1;
    y2 = h * 18 / 32;
    g2.draw(new Line2D.Double(x1, y1, x2, y2));
    theta = Math.atan2(y2 - y1, x2 - x1);
    drawArrow(g2, theta, x2, y2);

    g2.setPaint(Color.orange);
    x1 = w * 5 / 32;
    y1 = h * 27 / 32;
    x2 = w * 27 / 32;
    y2 = h * 5 / 32;
    g2.draw(new Line2D.Double(x1, y1, x2, y2));
    theta = Math.atan2(y2 - y1, x2 - x1);
    drawArrow(g2, theta, x2, y2);

    g2.setPaint(Color.green.darker());
    x1 = w / 2;
    y1 = h / 2;
    x2 = w * 27 / 32;
    y2 = h * 27 / 32;
    g2.draw(new Line2D.Double(x1, y1, x2, y2));
    theta = Math.atan2(y2 - y1, x2 - x1);
    drawArrow(g2, theta, x2, y2);
  }
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   int w = getWidth();
   int h = getHeight();
   // Draw ordinate.
   g2.draw(new Line2D.Double(Points, Points, Points, h - Points));
   // Draw abcissa.
   g2.draw(new Line2D.Double(Points, h - Points, w - Points, h - Points));
   // Draw labels.
   Font font = g2.getFont();
   FontRenderContext frc = g2.getFontRenderContext();
   LineMetrics lm = font.getLineMetrics("0", frc);
   float sh = lm.getAscent() + lm.getDescent();
   // Ordinate label.
   String s = "Strecke";
   float sy = Points + ((h - 2 * Points) - s.length() * sh) / 2 + lm.getAscent();
   for (int i = 0; i < s.length(); i++) {
     String letter = String.valueOf(s.charAt(i));
     float sw = (float) font.getStringBounds(letter, frc).getWidth();
     float sx = (Points - sw) / 2;
     g2.drawString(letter, sx, sy);
     sy += sh;
   }
   // Abcissa label.
   s = "Datum";
   sy = h - Points + (Points - sh) / 2 + lm.getAscent();
   float sw = (float) font.getStringBounds(s, frc).getWidth();
   float sx = (w - sw) / 2;
   g2.drawString(s, sx, sy);
   // Draw lines.
   double xInc = (double) (w - 2 * Points) / (data.length - 1);
   double scale = (double) (h - 2 * Points) / getMax();
   g2.setPaint(Color.green.darker());
   for (int i = 0; i < data.length - 1; i++) {
     double x1 = Points + i * xInc;
     double y1 = h - Points - scale * data[i];
     double x2 = Points + (i + 1) * xInc;
     double y2 = h - Points - scale * data[i + 1];
     g2.draw(new Line2D.Double(x1, y1, x2, y2));
   }
   // Mark data points.
   g2.setPaint(Color.red);
   for (int i = 0; i < data.length; i++) {
     double x = Points + i * xInc;
     double y = h - Points - scale * data[i];
     g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
   }
 }
예제 #8
0
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   Dimension d = getSize();
   Color fg3D = Color.lightGray;
   g2.setPaint(fg3D);
   g2.draw3DRect(0, 0, d.width - 1, d.height - 1, true);
   g2.draw3DRect(3, 3, d.width - 7, d.height - 7, false);
   g2.setPaint(fg);
   test.setBounds(boardGridSize * 4 + 10, boardGridSize * 5 - 20, 100, 50);
   this.add(test);
   paintBoard(g2);
 }
예제 #9
0
 /** the paintComponent -- paints the board every repaint() call. */
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   for (int i = 0; i < B_WIDTH; i++) {
     for (int j = 0; j < B_HEIGHT; j++) {
       Rectangle2D rect = new Rectangle2D.Double((i * 40) + 1, (j * 40) + 1, 38, 38);
       g2.setPaint(balls[i][j].getColor());
       g2.fill(rect);
       Ellipse2D circle = new Ellipse2D.Double();
       circle.setFrame(rect);
       g2.setPaint(balls[i][j].getcColor());
       g2.fill(circle);
     }
   }
 }
예제 #10
0
파일: LJ3MDApp.java 프로젝트: eskilj/mvp
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   if (model != null) {
     newImgBuf(); // refresh the image buffer if necessary
     // compute the real-to-screen ratio, this variable differs
     // from model.real2Screen by zoomScale
     Dimension sz = getSize();
     double real2Screen0 = model.getScaleFromSpan(realSpan, sz.width, sz.height);
     model.setMatrix(viewMatrix, real2Screen0 * zoomScale, sz.width / 2, sz.height / 2);
     imgG.setColor(Color.BLACK);
     imgG.fillRect(0, 0, sz.width, sz.height);
     model.paint(imgG);
     g.drawImage(img, 0, 0, this);
   }
 }
예제 #11
0
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2d = (Graphics2D)g;
   AffineTransform origXform = g2d.getTransform();
   AffineTransform newXform = (AffineTransform)(origXform.clone());
   //center of rotation is center of the panel
   int xRot = this.getWidth()/2;
   int yRot = this.getHeight()/2;
   newXform.rotate(Math.toRadians(currentAngle), xRot, yRot);
   g2d.setTransform(newXform);
   //draw image centered in panel
   int x = (getWidth() - image.getWidth(this))/2;
   int y = (getHeight() - image.getHeight(this))/2;
   g2d.drawImage(image, x, y, this);
   g2d.setTransform(origXform);
 }
예제 #12
0
파일: My29.java 프로젝트: Buzov/Java_lesson
  public void paintComponent(Graphics g) {
    // необходиом чтобы текст коректно отрисовывался в окне
    super.paintComponent(g);
    // рисуем текст в окне
    Graphics2D g2 = (Graphics2D) g;
    AffineTransform t = g2.getTransform();
    g.drawString("It is text", 5, 5);
    // создание шрифта
    Font f = new Font("SanasSerif", Font.ITALIC, 20);
    g2.setFont(f);
    g2.drawString("It is new text", 5, 33);
    String[] fontNames =
        GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    for (int i = 5; i < 20; i++) {
      g2.rotate(-0.05);
      g2.setColor(
          new Color(
              (int) (Math.random() * 255),
              (int) (Math.random() * 255),
              (int) (Math.random() * 255)));
      Font f1 = new Font(fontNames[i], Font.BOLD, 20);
      g2.setFont(f1);
      g2.drawString(fontNames[i], 5, 20 * i);
    }
    // текст в центре

    g2.setTransform(t); // возращение к кординатам, которые запонилив начале
    Font f2 = new Font("SanasSerif", Font.ITALIC, 20);
    g2.setFont(f2);
    String s = "It is center!";
    FontRenderContext context = g2.getFontRenderContext();
    Rectangle2D r = f2.getStringBounds(s, context);
    double x1 = (getWidth() - r.getWidth()) / 2;
    double y1 = (getHeight() - r.getHeight()) / 2;
    double ascent = -r.getY(); // узнаем высоту текста
    double y2 = y1 + ascent;
    Rectangle2D rect = new Rectangle2D.Double(x1, y1, r.getWidth(), r.getHeight());
    g2.setColor(Color.YELLOW);
    g2.fill(rect);
    g2.setColor(Color.red);
    g2.drawString(s, (int) x1, (int) y2);
    g2.setColor(Color.blue);
    g2.draw(new Line2D.Double(x1, y2, x1 + r.getWidth(), y2));

    g2.draw(rect);
  }
예제 #13
0
 @Override
 public void paintComponent(Graphics g) {
   g.setColor(Color.WHITE);
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   if (isDead) {
     g2.setColor(Color.BLACK);
     g2.setFont(new Font("Serif", Font.PLAIN, 30));
     g2.drawString("Game Over!", 300, 300);
     g2.drawString("Your final score was " + score, 250, 330);
     moverTimer.stop();
     scoreTimer.stop();
   } else {
     topWall.paint(g2);
     bottomWall.paint(g2);
     bird.paint(g2);
     g2.setColor(Color.BLACK);
     g2.setFont(new Font("Serif", Font.PLAIN, 20));
     g2.drawString("Score: " + score, 50, 50);
   }
 }
예제 #14
0
    @Override
    public void paintComponent(Graphics g) {
      super.paintComponent(g);
      Graphics2D g2 = (Graphics2D) g;

      // paint ball, paddle, and brick configuration
      g2.drawImage(background.getImage(), 0, 0, null);
      bconfig.paint(g2);
      paddle.paint(g2);
      ball.paint(g2);
      g2.setColor(Color.WHITE);
      g2.setFont(new Font("Serif", Font.PLAIN, 20));
      g2.drawString("Score: " + score, 15, 20);
      if (ball.getY() > 500) {
        g2.setColor(Color.WHITE);
        g2.setFont(new Font("Serif", Font.PLAIN, 30));
        g2.drawString("Game Over!", 200, 300);
        g2.drawString("Your final score was " + score, 150, 330);
        timer.stop();
      }
    }
예제 #15
0
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   this.setBackground(Color.WHITE);
   Graphics2D g2d = (Graphics2D) g;
   RenderingHints rh =
       new RenderingHints(
           RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
   g2d.setRenderingHints(rh);
   for (int i = 0; i < strokes.size(); i++) {
     Stroke currentStroke = strokes.get(i);
     g2d.setPaint(currentStroke.getColor());
     g2d.setStroke(new BasicStroke(currentStroke.getThickness()));
     ArrayList<Point2D> currentStrokePoints = currentStroke.getPoints();
     for (int j = 1; j < currentStrokePoints.size(); j++) {
       g2d.drawLine(
           (int) (currentStrokePoints.get(j - 1).getX() * this.getSize().getWidth()),
           (int) (currentStrokePoints.get(j - 1).getY() * this.getSize().getHeight()),
           (int) (currentStrokePoints.get(j).getX() * this.getSize().getWidth()),
           (int) (currentStrokePoints.get(j).getY() * this.getSize().getHeight()));
     }
   }
 }
예제 #16
0
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   if (squares == null) {
     initSquares();
   }
   // Draw squares.
   g2.setPaint(Color.blue);
   int t = 0;
   for (int k = 0; k < ROW; k++) {
     for (int i = 0; i < 2; i++) {
       for (int j = 0; j < 4; j++) {
         s[t++] = squares[k][i][j];
         // squares[k][i][j].draw(g2);
         // System.out.println("K: "+k);
       }
     }
   }
   System.out.println("T: " + t);
   for (int b = 0; b < 16000; b++) s[b].draw(g2);
 }
예제 #17
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;
    RenderingHints rh = g2d.getRenderingHints();
    rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHints(rh);

    // Background.
    D = this.getSize();
    g.setColor(backgroundColor);
    g.fillRect(0, 0, D.width, D.height);
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(lineStroke);

    // Axes, bounding box.
    g.setColor(Color.gray);
    g.drawLine(inset, D.height - inset, D.width - inset, D.height - inset);
    g.drawLine(D.width - inset, inset, D.width - inset, D.height - inset);
    g.drawLine(inset, inset, inset, D.height - inset);
    g.drawLine(inset, inset, D.width - inset, inset);

    double xDelta = (maxX - minX) / numIntervals;

    // X-ticks and labels.
    for (int i = 1; i <= numIntervals; i++) {
      double xTickd = i * xDelta;
      int xTick = (int) (xTickd / (maxX - minX) * (D.width - 2 * inset));
      g.drawLine(inset + xTick, D.height - inset - 5, inset + xTick, D.height - inset + 5);
      double x = minX + i * xDelta;
      g.drawString(df.format(x), xTick + inset - 5, D.height - inset + 20);
    }

    // Y-ticks
    double yDelta = (maxY - minY) / numIntervals;
    for (int i = 0; i < numIntervals; i++) {
      int yTick = (i + 1) * (int) ((D.height - 2 * inset) / (double) numIntervals);
      g.drawLine(inset - 5, D.height - yTick - inset, inset + 5, D.height - yTick - inset);
      double y = minY + (i + 1) * yDelta;
      g.drawString(df.format(y), 1, D.height - yTick - inset);
    }

    // Zoom+move
    Font savedFont = g.getFont();
    g.setFont(plusFont);
    g.drawString("+", D.width - 25, 20);
    g.setFont(minusFont);
    g.drawString("-", D.width - 25, 50);
    drawArrow(g2d, D.width - 70, 20, D.width - 70, 0, 1.0f, lineStroke); // Up
    drawArrow(g2d, D.width - 70, 30, D.width - 70, 50, 1.0f, lineStroke); // Down
    drawArrow(g2d, D.width - 65, 25, D.width - 45, 25, 1.0f, lineStroke); // Right
    drawArrow(g2d, D.width - 75, 25, D.width - 95, 25, 1.0f, lineStroke); // Left
    g.setFont(savedFont);

    // See if standard axes are in the middle.
    g.setColor(Color.gray);
    if ((minX < 0) && (maxX > 0) && (drawMiddleAxes)) {
      // Draw y-axis
      int x = (int) ((0 - minX) / (maxX - minX) * (D.width - 2 * inset));
      g.drawLine(inset + x, D.height - inset, inset + x, inset);
    }
    if ((minY < 0) && (maxY > 0) && (drawMiddleAxes)) {
      // Draw x-axis
      int y = (int) ((0 - minY) / (maxY - minY) * (D.height - 2.0 * inset));
      g.drawLine(inset, D.height - y - inset, D.width - inset, D.height - y - inset);
    }

    // Draw the objects.
    drawObjects(g, points, lines, ovals, rectangles, images, labels, eqnLines);
    if (animationMode) {
      drawObjects(g, animPoints, animLines, animOvals, animRectangles, null, labels, eqnLines);
      // No images in animation mode.
    }

    drawScribbles(g);
  }
예제 #18
0
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int w = getWidth();
    int h = getHeight();
    double xScale = (w - 2 * PAD) / (xMax - xMin);
    double yScale = (h - 2 * PAD) / (yMax - yMin);
    if (firstTime) System.out.printf("xScale = %.1f  yScale = %.1f%n", xScale, yScale);
    Point2D.Double origin = new Point2D.Double(); // Axes origin.
    Point2D.Double offset = new Point2D.Double(); // Locate data.
    if (xMax < 0) {
      origin.x = w - PAD;
      offset.x = origin.x - xScale * xMax;
    } else if (xMin < 0) {
      origin.x = PAD - xScale * xMin;
      offset.x = origin.x;
    } else {
      origin.x = PAD;
      offset.x = PAD - xScale * xMin;
    }
    if (yMax < 0) {
      origin.y = h - PAD;
      offset.y = origin.y - yScale * yMax;
    } else if (yMin < 0) {
      origin.y = PAD - yScale * yMin;
      offset.y = origin.y;
    } else {
      origin.y = PAD;
      offset.y = PAD - yScale * yMin;
    }
    if (firstTime) {
      System.out.printf("origin = [%6.1f, %6.1f]%n", origin.x, origin.y);
      System.out.printf("offset = [%6.1f, %6.1f]%n", offset.x, offset.y);
    }

    // Draw abcissa.
    g2.draw(new Line2D.Double(PAD, origin.y, w - PAD, origin.y));
    // Draw ordinate.
    g2.draw(new Line2D.Double(origin.x, PAD, origin.x, h - PAD));
    g2.setPaint(Color.red);
    // Mark origin.
    g2.fill(new Ellipse2D.Double(origin.x - 2, origin.y - 2, 4, 4));

    // Plot data.
    g2.setPaint(Color.blue);
    for (int i = 0; i < x.length; i++) {
      double x1 = offset.x + xScale * x[i];
      double y1 = offset.y + yScale * y[i];
      if (firstTime) System.out.printf("i = %d  x1 = %6.1f  y1 = %.1f%n", i, x1, y1);
      g2.fill(new Ellipse2D.Double(x1 - 2, y1 - 2, 4, 4));
      g2.drawString(String.valueOf(i), (float) x1 + 3, (float) y1 - 3);
    }

    // Draw extreme data values.
    g2.setPaint(Color.black);
    Font font = g2.getFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = font.getLineMetrics("0", frc);
    String s = String.format("%.1f", xMin);
    float width = (float) font.getStringBounds(s, frc).getWidth();
    double x = offset.x + xScale * xMin;
    g2.drawString(s, (float) x, (float) origin.y + lm.getAscent());
    s = String.format("%.1f", xMax);
    width = (float) font.getStringBounds(s, frc).getWidth();
    x = offset.x + xScale * xMax;
    g2.drawString(s, (float) x - width, (float) origin.y + lm.getAscent());
    s = String.format("%.1f", yMin);
    width = (float) font.getStringBounds(s, frc).getWidth();
    double y = offset.y + yScale * yMin;
    g2.drawString(s, (float) origin.x + 1, (float) y + lm.getAscent());
    s = String.format("%.1f", yMax);
    width = (float) font.getStringBounds(s, frc).getWidth();
    y = offset.y + yScale * yMax;
    g2.drawString(s, (float) origin.x + 1, (float) y);
    if (firstTime) System.out.println("------------------------------");
    firstTime = false;
  }