public void paintComponent(Graphics g) {
   super.paintComponent(g);
   if (uneHashtable.get(unEtat) != null) {
     g.setColor((Color) uneHashtable.get(unEtat));
     g.fillRect(100, 20, 40, 40);
   }
 }
    @Override
    protected void paintComponent(Graphics g) {
      super.paintComponent(g);

      // Display root
      displayTree(g, tree.getRoot(), getWidth() / 2, 30, getWidth() / 4);
    }
Exemple #3
0
 /** RedŽfinition de la mŽthode paintComponent() de JComponent */
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   for (Shape s : shapes) {
     s.paint(g);
   }
   notifyObservers();
 }
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D gfx = (Graphics2D) g;
    gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Clear screen
    gfx.setColor(Constants.BACKGROUND_COLOR);
    gfx.fillRect(0, 0, getWidth(), getHeight());
    // Render next frame
    grid.draw(gfx);
    // Trace path line
    if (tracing) {
      gfx.setColor(Constants.PATH_COLOR);
      gfx.setStroke(new BasicStroke(2));
      for (int i = 1; i < pathLine.size(); i++) {
        Coordinate p = pathLine.get(i - 1);
        Coordinate n = pathLine.get(i);
        gfx.drawLine(
            (Constants.TILESIZE + Constants.MARGIN) * p.x
                + (Constants.TILESIZE / 2)
                + Constants.MARGIN,
            (Constants.TILESIZE + Constants.MARGIN) * p.y
                + (Constants.TILESIZE / 2)
                + Constants.MARGIN,
            (Constants.TILESIZE + Constants.MARGIN) * n.x
                + (Constants.TILESIZE / 2)
                + Constants.MARGIN,
            (Constants.TILESIZE + Constants.MARGIN) * n.y
                + (Constants.TILESIZE / 2)
                + Constants.MARGIN);
      }
    }
  }
Exemple #5
0
    public void paintComponent(Graphics page) {
      super.paintComponent(page);

      Image icon = this.getToolkit().getImage("chess1.jpg");
      page.drawImage(icon, -40, 20, this);

      setOpaque(false);
    }
Exemple #6
0
  /** PaintComponent to draw everything. */
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    setBackground(Color.WHITE);
    // If using images, use cool dragon background
    if (useImages) g.drawImage(background, 0, 0, 310, 300, null);

    // Use light gray to not overpower the background image
    g.setColor(Color.LIGHT_GRAY);
    for (int y = 1; y < ROWS; ++y)
      g.fillRoundRect(0, cellSize * y - 4, (cellSize * COLS) - 1, 8, 8, 8);
    for (int x = 1; x < COLS; ++x)
      g.fillRoundRect(cellSize * x - 4, 0, 8, (cellSize * ROWS) - 1, 8, 8);

    // Use graphics2d for when not using the images
    Graphics2D g2d = (Graphics2D) g;
    g2d.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    for (int y = 0; y < ROWS; ++y) {
      for (int x = 0; x < COLS; ++x) {
        int x1 = x * cellSize + 16;
        int y1 = y * cellSize + 16;
        if (board[y][x] == Symbol.X) {
          // use image if set to true, otherwise use g2d
          // for thicker, better looking X's and O's
          if (useImages) g.drawImage(imageX, x1, y1, 75, 75, null);
          else {
            g2d.setColor(PURPLE);
            int x2 = (x + 1) * cellSize - 16;
            int y2 = (y + 1) * cellSize - 16;
            g2d.drawLine(x1, y1, x2, y2);
            g2d.drawLine(x2, y1, x1, y2);
          }
        } else if (board[y][x] == Symbol.O) {
          if (useImages) g.drawImage(imageO, x1, y1, 75, 75, null);
          else {
            g2d.setColor(Color.BLUE);
            g2d.drawOval(x1, y1, 70, 70);
          }
        }
      } // end for
    }

    // Set status bar based on gamestate.  If CONTINUE, show whose turn it is
    if (gameStatus == GameStatus.CONTINUE) {
      statusBar.setForeground(Color.BLACK);
      if (currentPlayer == Symbol.X) statusBar.setText("X's Turn");
      else statusBar.setText("O's Turn");
    } else if (gameStatus == GameStatus.DRAW) {
      statusBar.setForeground(Color.RED);
      statusBar.setText("Draw! Click to play again!");
    } else if (gameStatus == GameStatus.X_WIN) {
      statusBar.setForeground(Color.RED);
      statusBar.setText("X has won! Click to play again!");
    } else if (gameStatus == GameStatus.O_WIN) {
      statusBar.setForeground(Color.RED);
      statusBar.setText("O has won! Click to play again!");
    }
  }
Exemple #7
0
 /** Redefinition de la methode paintComponent() de JComponent */
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   for (Shape s : shapes) {
     s.paint(g);
   }
   for (Shape s : shapesCloneList) {
     s.paint(g);
   }
 }
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    while (true) {
      teller++;
      slaap(1000);
      label.setText("" + teller);
    }
  }
Exemple #9
0
  /* 연결선 그리기 */
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    for (Line link : links) {
      g.drawLine(link.p1.x, link.p1.y, link.p2.x, link.p2.y);
    }
    repaint();
  }
    @Override
    protected void paintComponent(Graphics g) {

      super.paintComponent(g);

      if (resourceImage != null) {

        g.drawImage(resourceImage, 1, 1, this);
      }
    }
Exemple #11
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.setColor(BACKGROUND);
    g.fillRect(0, 0, width, height);
    g.setColor(FOREGROUND);

    for (int i = 0; i < NUMBOXES; i++) {
      g.fillRect(boxXs[i], boxYs[i], BOXWIDTH, BOXHEIGHT);
      g.drawLine(lineXs[i], lineYs[i], lineXXs[i], lineYYs[i]);
    }
  }
  /**
   * Paint a background for all groups and a round blue border and background when a cell is
   * selected.
   *
   * @param g the <tt>Graphics</tt> object used for painting
   */
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    g = g.create();
    try {
      internalPaintComponent(g);
    } finally {
      g.dispose();
    }
  }
  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");
  }
 @Override
 protected void paintComponent(Graphics g) {
   if (myFocusRequestor != null) {
     if (myFocusRequestor.isFocusOwner()) {
       myFocusRequestor = null;
     } else {
       myFocusRequestor.requestFocusInWindow();
     }
   }
   super.paintComponent(g);
 }
Exemple #15
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);

  }
Exemple #16
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    calcSizes();
    drawAxes(g);
    calcMaxes();
    calcTickIncrements();
    drawXTicks(g);
    drawYTicks(g);

    int t = 0;
    int prevX = 0, prevY1 = 0, prevY2 = 0;

    for (DataPair pair : data) {

      int h = pair.getH();
      int p = pair.getP();

      // calculate where to put the dots
      int x = xVal(t, maxT);
      int y1 = yVal(h, maxH);
      int y2 = yVal(p, maxP);

      // draw herbivore dot
      g.setColor(Color.BLUE);
      g.fillOval(x, y1, 2 * r, 2 * r);

      // draw a line connecting this dot to the last
      if (prevX != 0) {
        g.drawLine(prevX + r, prevY1 + r, x + r, y1 + r);
      }

      // draw predator dot
      g.setColor(Color.RED);
      g.fillOval(x, y2, 2 * r, 2 * r);

      // draw a line connecting this dot to the last
      if (prevX != 0) {
        g.drawLine(prevX + r, prevY2 + r, x + r, y2 + r);
      }

      // remember these dots
      prevX = x;
      prevY1 = y1;
      prevY2 = y2;

      g.setColor(Color.BLACK);

      t++;
    }
  }
 /**
  * Repaint the drawing panel
  *
  * @param g The Graphics context
  */
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   // Draw the background that will be beside the board
   g.drawImage(background, 0, 0, this);
   for (int row = 0; row < 16; row++) {
     for (int col = 0; col < 16; col++) {
       board[row][col].draw(g);
     }
   }
   int seconds = (time / 10);
   g.setColor(Color.WHITE);
   g.setFont(new Font("Century Gothic", Font.BOLD, 65));
   g.drawString("" + seconds, 1075, 205);
 } // paint component method
    @Override
    public void paintComponent(Graphics g) {
      super.paintComponent(g);

      bubbleField.draw(g);

      for (Bubble bubble : bubbeList) {

        bubble.drawBubble(g);
      }

      g.setColor(Color.WHITE);
      g.setFont(new Font("Courier New", Font.PLAIN, 16));
      g.drawString("Bubble " + bubble.toString(), 10, 20);
    }
  /**
   * Paints a customized background.
   *
   * @param g the <tt>Graphics</tt> object through which we paint
   */
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    g = g.create();

    if (!(treeNode instanceof GroupNode) && !isSelected) return;

    AntialiasingManager.activateAntialiasing(g);

    Graphics2D g2 = (Graphics2D) g;

    try {
      internalPaintComponent(g2);
    } finally {
      g.dispose();
    }
  }
Exemple #20
0
      /**
       * Draw one die including the letter centered in the middle of the die. If highlight is true,
       * we reverse the background and letter colors to highlight the die.
       */
      public void paintComponent(Graphics g) {
        super.paintComponent(g);

        int centeredXOffset, centeredYOffset;
        // Draw the blank die
        g.setColor((isHighlighted) ? FACECOLOR : DIECOLOR);
        g.fillRoundRect(0, 0, DIESIZE, DIESIZE, DIESIZE / 2, DIESIZE / 2);

        // Outline the die with black
        g.setColor(Color.black);
        g.drawRoundRect(0, 0, DIESIZE, DIESIZE, DIESIZE / 2, DIESIZE / 2);
        Graphics faceGraphics = faceLabel.getGraphics();
        faceGraphics.setColor(isHighlighted ? DIECOLOR : FACECOLOR);
        Color myColor = isHighlighted ? DIECOLOR : FACECOLOR;
        faceLabel.setForeground(myColor);
        faceLabel.setFont(FACEFONT);
        faceLabel.setText(face);
      }
  @Override
  protected void paintComponent(final Graphics g) {
    super.paintComponent(g);

    if (myToolbar != null
        && myToolbar.getParent() == this
        && myContent != null
        && myContent.getParent() == this) {
      g.setColor(UIUtil.getBorderSeparatorColor());
      if (myVertical) {
        final int y = (int) myToolbar.getBounds().getMaxY();
        g.drawLine(0, y, getWidth(), y);
      } else {
        int x = (int) myToolbar.getBounds().getMaxX();
        g.drawLine(x, 0, x, getHeight());
      }
    }
  }
  public void paintComponent(Graphics g) {
    setSize(xSize, ySize);
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;

    if (PedigreeExplorer.thickLines) {
      // turn this off so they don't look blurry when exported
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    } else {
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    }
    g2.setColor(Color.black);

    if (PedigreeExplorer.thickLines) {
      g2.setStroke(new BasicStroke(2));
    } else {
      g2.setStroke(new BasicStroke(1));
    }

    if (sex == male) {
      if (PedigreeExplorer.thickLines) {
        g2.drawRect(1, 1, symbolSize - 2, symbolSize - 2);
      } else {
        g2.drawRect(0, 0, symbolSize, symbolSize);
      }

      if (affection == affected) {
        g2.fillRect(0, 0, symbolSize, symbolSize);
      }
    }

    if (sex == female) {
      if (PedigreeExplorer.thickLines) {
        g2.drawArc(1, 1, symbolSize - 2, symbolSize - 2, 0, 360);
      } else {
        g2.drawArc(0, 0, symbolSize, symbolSize, 0, 360);
      }

      if (affection == affected) {
        g2.fillArc(0, 0, symbolSize, symbolSize, 0, 360);
      }
    }
  }
    public void paintComponent(Graphics g) {
      super.paintComponent(g);
      if (placer != null && index >= 0) {
        Dimension dim = placer.getModel().getSizeOf(index);

        ImageIcon icon, scaled_icon;

        // XXX: Come up with a cleaner way to do this.
        if (((ConfigElement) placer.getModel().getElement(index))
            .getDefinition()
            .getToken()
            .equals(SURFACE_VIEWPORT_TYPE)) {
          icon = surfaceIcon;
          scaled_icon = scaledSurfaceIcon;
        } else {
          icon = simIcon;
          scaled_icon = scaledSimIcon;
        }

        // Check if we need to update the scaled image
        Image img = scaled_icon.getImage();
        if ((scaled_icon.getIconWidth() != dim.width)
            || (scaled_icon.getIconHeight() != dim.height)) {
          img = icon.getImage().getScaledInstance(dim.width, dim.height, Image.SCALE_DEFAULT);
          scaled_icon.setImage(img);
        }

        // Sanity check in case our scale failed
        if (img != null) {
          g.drawImage(img, 0, 0, null);
        }

        // Highlight the window nicely
        if (selected) {
          g.setColor(getBackground());
        } else {
          g.setColor(Color.white);
        }

        g.drawRect(0, 0, dim.width - 1, dim.height - 1);
        g.fillRect(0, 0, dim.width, 3);
      }
    }
Exemple #24
0
  @Override
  /** Draw the clock */
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    // Initialize clock parameters
    int clockRadius = (int) (Math.min(getWidth(), getHeight()) * 0.8 * 0.5);
    int xCenter = getWidth() / 2;
    int yCenter = getHeight() / 2;

    // Draw circle
    g.setColor(Color.black);
    g.drawOval(xCenter - clockRadius, yCenter - clockRadius, 2 * clockRadius, 2 * clockRadius);
    g.drawString("12", xCenter - 5, yCenter - clockRadius + 12);
    g.drawString("9", xCenter - clockRadius + 3, yCenter + 5);
    g.drawString("3", xCenter + clockRadius - 10, yCenter + 3);
    g.drawString("6", xCenter - 3, yCenter + clockRadius - 3);

    // Draw second hand
    int sLength = (int) (clockRadius * 0.8);
    int xSecond = (int) (xCenter + sLength * Math.sin(second * (2 * Math.PI / 60)));
    int ySecond = (int) (yCenter - sLength * Math.cos(second * (2 * Math.PI / 60)));
    g.setColor(Color.red);
    g.drawLine(xCenter, yCenter, xSecond, ySecond);

    // Draw minute hand
    int mLength = (int) (clockRadius * 0.65);
    int xMinute = (int) (xCenter + mLength * Math.sin(minute * (2 * Math.PI / 60)));
    int yMinute = (int) (yCenter - mLength * Math.cos(minute * (2 * Math.PI / 60)));
    g.setColor(Color.blue);
    g.drawLine(xCenter, yCenter, xMinute, yMinute);

    // Draw hour hand
    int hLength = (int) (clockRadius * 0.5);
    int xHour =
        (int) (xCenter + hLength * Math.sin((hour % 12 + minute / 60.0) * (2 * Math.PI / 12)));
    int yHour =
        (int) (yCenter - hLength * Math.cos((hour % 12 + minute / 60.0) * (2 * Math.PI / 12)));
    g.setColor(Color.green);
    g.drawLine(xCenter, yCenter, xHour, yHour);
  }
 @Override
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   g.setColor(new Color(0xe0fffd));
   g.fillRect(getX(), getY() - ContributionManagerDialog.TAB_HEIGHT - 2, getWidth(), 2);
 }
Exemple #26
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);
  }
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   if (img != null) {
     g.drawImage(img, 0, 0, null);
   }
 }
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    // g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);

    Graphics2D canvas = (Graphics2D) g;

    if (panelBackground != null) {
      canvas.drawImage(panelBackground, 0, 0, getPanelWidth(), getPanelHeight(), null);
    }

    if (dalekDamageImage != null) {
      // int w = 100;
      // int h = (int)  (dalekImage.getHeight(null) * w / dalekImage.getWidth(null)  );

      int h = 200;
      // int w = dalekDamageImage.scaleWidth(h);

      int w = h * dalekDamageImage.getWidth(null) / dalekDamageImage.getHeight(null);

      BufferedImage thumbImage = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
      Graphics2D graphics2D = thumbImage.createGraphics();
      graphics2D.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      graphics2D.drawImage(dalekDamageImage, 0, 0, w, h, null);

      canvas.drawImage(thumbImage, getPanelWidth() / 2 - (w / 2), getPanelHeight() - h - 16, null);

      //	g.drawImage(thumbImage,getPanelWidth()/2 - (w/2), 32 ,null);

    }
    if (dalekTacticalImage != null) {

      // int h = 400;
      // int w = dalekTacticalImage.scaleWidth(h);

      BufferedImage thumbImage =
          new BufferedImage(
              dalekTacticalImage.getWidth(),
              dalekTacticalImage.getHeight(),
              BufferedImage.TYPE_4BYTE_ABGR);
      Graphics2D graphics2D = thumbImage.createGraphics();
      graphics2D.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      graphics2D.drawImage(dalekTacticalImage, 0, 0, null);

      // g.drawImage(thumbImage,getPanelWidth()/2 - (w/2), getPanelHeight() - h - 16 ,null);

      canvas.drawImage(thumbImage, 0, 32, null);

      /*
      Iterator<WeaponUI> it = dalekTacticalImage.iterator();
      int y = 32;
      while (it.hasNext()) {
      	g.drawImage(it.next(),0, y ,null);
      	y += 40; // really want height of WeaponUI.
      }
       */

    }

    // Move to Buffered Image
    if (this.getEngineRun() > 0) {
      this.drawEngineAt(
          canvas, 16, 256, this.getEngineWalk(), this.getEngineRun(), this.getEngineCurrent());
    }
    if (this.name != null) {
      canvas.setFont(techFont);
      canvas.drawString(this.name, 16, 24);
    }
  }
Exemple #29
0
 @Override
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   for (GeometricObject obj : objects) obj.paintMeTo(g);
 }
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    // allerlei uit begin hoofdstuk 8

    // p 199 : som
    int som = 0; // niet vergeten !!
    for (int getal = 1; getal <= 50; getal++) {
      som += getal;
    }
    g.drawString("Het  totaal is gelijk aan :" + som, 10, 150);

    // p 200 : faculteit
    int faculteit = 1; // niet nul !
    int laatste = 10;
    for (int i = 2; i <= laatste; i++) {
      faculteit *= i;
    }
    g.drawString("Faculteit van 10 is : " + faculteit, 10, 200);

    // p 200 random
    double t1, t2;
    t1 = Math.random(); // levert 0.000 .. 0.999
    t2 = Math.random();
    g.drawString("t1 = " + t1, 10, 250);
    g.drawString("t2 = " + t2, 10, 300);

    // p 201 dobbelsteen korte methode, formule op p 202 !
    int worp = (int) (6 * Math.random() + 1);
    g.drawString("dobbelsteen worp = " + worp, 10, 350);

    // p 203 char en typecasting
    char ch = 'A';
    int code = (int) ch; // is hier optie
    code++; // of test eens code += 32; // HOOFDLETTER > kleine letter
    ch = (char) code; // eig enkel hier typecasting vereist
    ch++; // je kan de char variabele ook direct verhogen
    g.drawString("eindwaarde char =  " + ch, 10, 400);
    int posX = 10;
    // of er zelfs een for lus mee schrijven
    for (ch = 'A'; ch <= 'Z'; ch++) {
      g.drawString("*" + ch, posX, 425);
      posX += 12;
    }

    // p 229 grootste zoeken
    double[] winstArray = {22.3, -6.27, 31.44, 123.2, 17.84, 119.6};

    double max = winstArray[0]; // neem eerste element
    // overloop de andere (vanaf index 1)
    for (int i = 1; i < winstArray.length; i++) {
      if (winstArray[i] > max) max = winstArray[i];
    }
    g.drawString("Grootste winst is : " + max, 10, 450);

    // en zoek de tweede grootste ?

    // deze manier lukt niet, waarom ?
    max = winstArray[0]; // neem eerste element
    double oldmax = max;
    // overloop de andere (vanaf index 1)
    for (int i = 1; i < winstArray.length; i++) {
      if (winstArray[i] > max) {
        oldmax = max; // schuif deze waarde door
        max = winstArray[i]; // onthoud nieuw grootste
      }
    }
    g.drawString("Tweede grootste winst is : " + oldmax, 10, 500);

    // dan maar zo ... maar op voorwaarde dat je de array MAG wijzigen !
    int len = winstArray.length;

    // of maak anders eerst een kopie :
    double[] wAcopy = new double[len];
    System.arraycopy(winstArray, 0, wAcopy, 0, len);
    // array sorteren
    Arrays.sort(wAcopy);
    g.drawString(
        "grootste = " + wAcopy[len - 1] + " , tweede grootste : " + wAcopy[len - 2], 10, 540);

    // of nog anders, maar ook met wijzigen van de array :
    // zoek grootste en vervang het door iets heel kleins en zoek dan weer het grootste
    double[] wAcopy2 = new double[len];
    System.arraycopy(winstArray, 0, wAcopy2, 0, len);
    int index = 0;
    max = wAcopy2[0]; // neem eerste element
    // overloop de andere (vanaf index 1)
    for (int i = 1; i < len; i++) {
      if (wAcopy2[i] > max) {
        max = wAcopy2[i];
        index = i;
      }
    }
    // overschrijf grootste
    wAcopy2[index] = -999999;
    // en nu opnieuw grootste zoeken

    max = wAcopy2[0]; // neem eerste element
    // overloop de andere (vanaf index 1)
    for (int i = 1; i < len; i++) {
      if (wAcopy2[i] > max) {
        max = wAcopy2[i];
        index = i;
      }
    }
    // nu is max het tweede grootste element
    g.drawString("tweede grootste (derde methode) = " + max, 10, 570);

    // zoek methode toepassen (zie hieronder)
    g.drawString("Positie van getal 31.44 = " + zoek(winstArray, 31.44), 10, 600);
    g.drawString("Positie van getal 21.44 = " + zoek(winstArray, 21.44), 10, 620);
  }