protected synchronized void paintComponent(Graphics gc) {
   Dimension d = getSize();
   gc.clearRect(0, 0, d.width, d.height);
   if (tmpChar[0] == 0) return;
   int charWidth = fm.charWidth(tmpChar[0]);
   gc.drawChars(tmpChar, 0, 1, curX++, fontHeight);
 }
 @Override
 public void drawChars(
     @NotNull Graphics g,
     @NotNull char[] data,
     int start,
     int end,
     int x,
     int y,
     Color color,
     FontInfo fontInfo) {
   g.setFont(fontInfo.getFont());
   g.setColor(color);
   g.drawChars(data, start, end - start, x, y);
 }
示例#3
0
文件: HexEdit.java 项目: khyuna/hyun
 @Override
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   int addr = startAddress;
   if (addr > SICXE.MAX_ADDR) return;
   int y = getInsets().top + lineHeight;
   int rows = (getHeight() - getInsets().top - getInsets().bottom) / lineHeight;
   for (int row = 0; row < rows; row++) {
     // address
     int x = getInsets().left + COL_ADDR * charWidth;
     g.setColor(Colors.fg);
     g.drawString(Conversion.addrToHex(addr), x, y);
     // hex and chr
     int x1 = getInsets().left + COL_HEX * charWidth;
     int x2 = getInsets().left + COL_CHR * charWidth;
     for (int col = 0; col < 16; col++) {
       // cursor background
       if (addr == cursorAddress) {
         // hex part
         g.setColor(Colors.bg(true, focusOnHex && isFocusOwner()));
         g.fillRect(x1 - 2, y - lineHeight + 3, 2 * charWidth + 4, lineHeight);
         // chr part
         g.setColor(Colors.bg(true, !focusOnHex && isFocusOwner()));
         g.fillRect(x2 - 1, y - lineHeight + 3, charWidth + 2, lineHeight);
       }
       // contents
       // hex part
       g.setColor(Colors.fg(addr == cursorAddress, focusOnHex && isFocusOwner()));
       int b = get(addr);
       if (b < 0) return;
       char[] ch = {'.'};
       if (b >= 0x20 && b < 0x7E) ch[0] = (char) b;
       g.drawString(Conversion.byteToHex(b), x1, y);
       x1 += 3 * charWidth;
       // chr part
       g.setColor(Colors.fg(addr == cursorAddress, !focusOnHex && isFocusOwner()));
       g.drawChars(ch, 0, 1, x2, y);
       x2 += charWidth;
       if (++addr > SICXE.MAX_ADDR) return;
     }
     y += lineHeight;
   }
 }
示例#4
0
  /** Consults the model to paint the game matrix. If model is null, draws a default text. */
  @Override
  public void paintComponent(final Graphics g) {
    // Check if we have a running game
    super.paintComponent(g);
    g.setColor(this.getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());

    if (this.model != null) {

      // Draw all tiles by going over them x-wise and y-wise.
      for (int i = 0; i < this.modelSize.width; i++) {
        for (int j = 0; j < this.modelSize.height; j++) {
          GameTile tile = this.model.getGameboardState(i, j);
          tile.draw(g, i * this.tileSize.width, j * this.tileSize.height, this.tileSize);
        }
      }
    } else {
      g.setFont(new Font("Sans", Font.BOLD, 24));
      g.setColor(Color.BLACK);
      final char[] message = "No model chosen.".toCharArray();
      g.drawChars(message, 0, message.length, 50, 50);
    }
  }
  // -----------------------------------------------------------------
  //  Draws a snowman.
  // -----------------------------------------------------------------
  public void paintComponent(Graphics page) {
    super.paintComponent(page);
    final int MID = 170;
    final int TOP = 50;

    // constants for snow body
    final int head = 40;
    final int UP_T[] = {70, 50};
    final int LOW_T[] = {100, 60};

    // coordinates for shadow hat polygon
    final int hatX[] = {MID - 70, MID - 50, MID - 65, MID - 85};
    final int hatY[] = {TOP + 168, TOP + 173, TOP + 193, TOP + 188};

    // coordinates for sun rays
    final int ray1X[] = {250, 255, -100, -110};
    final int ray1Y[] = {5, 15, 95, 45};

    final int ray2X[] = {260, 280, 170, -130};
    final int ray2Y[] = {30, 45, 360, 220};

    final char name[] = {'E', '.', 'Z', '.'};

    setBackground(Color.blue);

    page.setColor(Color.yellow);
    page.fillOval(260, -40, 80, 80); // sun

    page.fillPolygon(ray1X, ray1Y, 4); // upper sun ray
    page.fillPolygon(ray2X, ray2Y, 4); // lower sun ray

    // ground changed to white
    page.setColor(Color.white);
    page.fillRect(0, 175, 300, 50); // ground

    // shadow body added
    page.setColor(Color.lightGray);
    page.fillOval(MID - 60, TOP + 120, LOW_T[0], LOW_T[1] / 2); // lower torso shadow
    page.fillOval(MID - 65, TOP + 140, UP_T[0], UP_T[1] / 2); // upper torso shadow
    page.fillOval(MID - 70, TOP + 155, head, head / 2); // head shadow

    page.drawLine(MID - 75, TOP + 165, MID - 45, TOP + 180); // hat brim shadow
    page.drawLine(MID - 75, TOP + 166, MID - 45, TOP + 181); // thicker brim shadow
    page.fillPolygon(hatX, hatY, 4); // had shadow

    page.setColor(Color.white);
    page.fillOval(MID - 20, TOP, 40, 40); // head
    page.fillOval(MID - 35, TOP + 35, UP_T[0], UP_T[1]); // upper torso
    page.fillOval(MID - 50, TOP + 80, LOW_T[0], LOW_T[1]); // lower torso

    page.setColor(Color.red);
    page.fillOval(MID - 5, TOP + 45, 10, 10); // 1st button
    page.fillOval(MID - 5, TOP + 65, 10, 10); // 2nd button

    page.setColor(Color.black);
    page.fillOval(MID - 10, TOP + 10, 5, 5); // left eye
    page.fillOval(MID + 5, TOP + 10, 5, 5); // right eye

    page.drawArc(MID - 10, TOP + 25, 20, 10, 10, 160); // frown, was smile

    page.drawLine(MID - 25, TOP + 60, MID - 50, TOP + 40); // left arm
    page.drawLine(MID + 25, TOP + 60, MID + 55, TOP + 60); // right arm

    page.drawLine(MID - 20, TOP + 5, MID + 20, TOP + 5); // brim of hat
    page.drawLine(MID - 20, TOP + 4, MID + 20, TOP + 4); // thicker brim
    page.fillRect(MID - 15, TOP - 20, 30, 25); // top of hat

    page.setColor(Color.white);
    page.drawChars(name, 0, 4, 10, 20); // display name
  }