Ejemplo n.º 1
0
  public void paint(Graphics g) {
    if (!gameComplete) {
      if (!initialPaintComplete) {
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, MaxX, MaxY);
        initialPaintComplete = true;
      }

      Graphics blockGraphics = blockBuffer.getGraphics();
      Graphics padGraphics = padBuffer.getGraphics();
      Graphics ballGraphics = ballBuffer.getGraphics();
      Graphics ballPreviousGraphics = ballBufferPrevious.getGraphics();

      ballPreviousGraphics.setColor(Color.WHITE);
      ballPreviousGraphics.fillRect(0, 0, ballDiameter, ballDiameter);
      g.drawImage(ballBufferPrevious, ballPreviousX, ballPreviousY, null);

      ballGraphics.setColor(Color.BLUE);
      ballGraphics.fillOval(0, 0, ballDiameter, ballDiameter); // whole line white
      g.drawImage(ballBuffer, ballX, ballY, null);

      ballGraphics.setColor(Color.RED);
      ballGraphics.fillOval(4, 4, ballDiameter - 8, ballDiameter - 8); // whole line white
      g.drawImage(ballBuffer, ballX, ballY, null);

      padGraphics.setColor(Color.WHITE);
      padGraphics.fillRect(0, 0, MaxX, blockHeight); // whole line white
      padGraphics.setColor(Color.BLACK);
      padLeft = padx - padLength / 2;

      if (padLeft >= 0 && padx + padLength / 2 < MaxX) {
        padGraphics.fillRoundRect(padLeft, 0, padLength, padHeight, padHeight, padHeight);
      }
      if (padLeft < 0) {
        padGraphics.fillRoundRect(0, 0, padLength, padHeight, padHeight, padHeight);
      } else if (padx + padLength / 2 >= MaxX) {
        padGraphics.fillRoundRect(MaxX - padLength, 0, padLength, padHeight, padHeight, padHeight);
      }
      g.drawImage(padBuffer, 0, padTop, null);
      // g.drawString(msg, 50, 50);
      // Drawing Blocks

      Iterator<Entry<String, Color>> it = blockMap.entrySet().iterator();
      blockGraphics.setColor(Color.WHITE);
      blockGraphics.fillRect(0, 0, blockSetWidth, blockSetHeight); // whole line white
      while (it.hasNext()) {
        Map.Entry<String, Color> pairs = (Map.Entry<String, Color>) it.next();
        String coordinate = pairs.getKey();
        blockGraphics.setColor(pairs.getValue());
        blockGraphics.fillRect(
            new Pair(coordinate).first, new Pair(coordinate).second, blockLength, blockHeight);
      }
      if (repaintBlocks) {
        g.drawImage(blockBuffer, blockStartX, blockStartY, null);
        if (--count < 0) repaintBlocks = false;
      }
    }
  }
Ejemplo n.º 2
0
    public void paintComponent(Graphics page) {
      super.paintComponent(page);

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

      setOpaque(false);
    }
Ejemplo n.º 3
0
 public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
   g.setColor(Color.white);
   g.fillRect(0, 0, c.getWidth(), c.getHeight());
   if (getImageObserver() == null) {
     g.drawImage(
         getImage(),
         c.getWidth() / 2 - getIconWidth() / 2,
         c.getHeight() / 2 - getIconHeight() / 2,
         c);
   } else {
     g.drawImage(
         getImage(),
         c.getWidth() / 2 - getIconWidth() / 2,
         c.getHeight() / 2 - getIconHeight() / 2,
         getImageObserver());
   }
 }
Ejemplo n.º 4
0
 public void paint(Graphics g) {
   g.setColor(this.getBackground());
   g.fillRect(0, 0, this.width, this.height);
   g.setColor(this.getForeground());
   g.drawImage(this.imLogo, 10, 40, this);
   g.setFont(this.fontTitle);
   g.drawString(this.appName, 70, 65);
   g.setFont(this.fontText);
   int startY = 130;
   int l = 6;
   for (int i = 0; i < textLines.length; ++i) {
     g.drawString(this.textLines[i], 10, startY);
     startY += 20;
   }
   if (str != null) g.drawString(str, 10, startY);
   g.drawImage(this.imHelp, 50, startY + 30, this);
 }
Ejemplo n.º 5
0
 private void scaleImage() {
   Image img =
       back.getScaledInstance(scx(back.getWidth()), scy(back.getHeight()), Image.SCALE_SMOOTH);
   back =
       new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
   Graphics g = back.getGraphics();
   g.drawImage(img, 0, 0, null);
   g.dispose();
 }
Ejemplo n.º 6
0
 /**
  * Turn a (possibly) translucent or indexed image into a display-compatible bitmask image using
  * the given alpha threshold and render-to-background colour, or display-compatible translucent
  * image. The alpha values in the image are set to either 0 (below threshold) or 255 (above
  * threshold). The render-to-background colour bg_col is used to determine how the pixels
  * overlapping transparent pixels should be rendered. The fast algorithm just sets the colour
  * behind the transparent pixels in the image (for bitmask source images); the slow algorithm
  * actually renders the image to a background of bg_col (for translucent sources).
  *
  * @param thresh alpha threshold between 0 and 255
  * @param fast use fast algorithm (only set bg_col behind transp. pixels)
  * @param bitmask true=use bitmask, false=use translucent
  */
 public JGImage toDisplayCompatible(int thresh, JGColor bg_col, boolean fast, boolean bitmask) {
   Color bgcol = new Color(bg_col.r, bg_col.g, bg_col.b);
   int bgcol_rgb = (bgcol.getRed() << 16) | (bgcol.getGreen() << 8) | bgcol.getBlue();
   JGPoint size = getSize();
   int[] buffer = getPixels();
   // render image to bg depending on bgcol
   BufferedImage img_bg;
   if (bitmask) {
     img_bg = createCompatibleImage(size.x, size.y, Transparency.BITMASK);
   } else {
     img_bg = createCompatibleImage(size.x, size.y, Transparency.TRANSLUCENT);
   }
   int[] bg_buf;
   if (!fast) {
     Graphics g = img_bg.getGraphics();
     g.setColor(bgcol);
     // the docs say I could use bgcol in the drawImage as an
     // equivalent to the following two lines, but this
     // doesn't handle translucency properly and is _slower_
     g.fillRect(0, 0, size.x, size.y);
     g.drawImage(img, 0, 0, null);
     bg_buf = new JREImage(img_bg).getPixels();
   } else {
     bg_buf = buffer;
   }
   // g.dispose();
   // ColorModel rgb_bitmask = ColorModel.getRGBdefault();
   // rgb_bitmask = new PackedColorModel(
   //		rgb_bitmask.getColorSpace(),25,0xff0000,0x00ff00,0x0000ff,
   //		0x1000000, false, Transparency.BITMASK, DataBuffer.TYPE_INT);
   //		ColorSpace space, int bits, int rmask, int gmask, int bmask, int amask, boolean
   // isAlphaPremultiplied, int trans, int transferType)
   int[] thrsbuf = new int[size.x * size.y];
   for (int y = 0; y < size.y; y++) {
     for (int x = 0; x < size.x; x++) {
       if (((buffer[y * size.x + x] >> 24) & 0xff) >= thresh) {
         thrsbuf[y * size.x + x] = bg_buf[y * size.x + x] | (0xff << 24);
       } else {
         // explicitly set the colour of the transparent pixel.
         // This makes a difference when scaling!
         // thrsbuf[y*size.x+x]=bg_buf[y*size.x+x]&~(0xff<<24);
         thrsbuf[y * size.x + x] = bgcol_rgb;
       }
     }
   }
   return new JREImage(
       output_comp.createImage(
           new MemoryImageSource(
               size.x,
               size.y,
               // rgb_bitmask,
               img_bg.getColorModel(), // display compatible bitmask
               bitmask ? thrsbuf : bg_buf,
               0,
               size.x)));
 }
Ejemplo n.º 7
0
 public void squish(Graphics g, ImageIcon icon, int x, int y, double scale) {
   if (isVisible()) {
     g.drawImage(
         icon.getImage(),
         x,
         y,
         (int) (icon.getIconWidth() * scale),
         (int) (icon.getIconHeight() * scale),
         this);
   }
 }
  /** Paint it. */
  public void paint(Graphics g) {
    Dimension d = getSize();
    g.setColor(Color.black);
    int xoff = d.width / 3;
    int yoff = d.height / 3;
    g.drawLine(xoff, 0, xoff, d.height);
    g.drawLine(2 * xoff, 0, 2 * xoff, d.height);
    g.drawLine(0, yoff, d.width, yoff);
    g.drawLine(0, 2 * yoff, d.width, 2 * yoff);

    int i = 0;
    for (int r = 0; r < 3; r++) {
      for (int c = 0; c < 3; c++, i++) {
        if ((white & (1 << i)) != 0) {
          g.drawImage(notImage, c * xoff + 1, r * yoff + 1, this);
        } else if ((black & (1 << i)) != 0) {
          g.drawImage(crossImage, c * xoff + 1, r * yoff + 1, this);
        }
      }
    }
  }
Ejemplo n.º 9
0
  /** Paints the image on the window. */
  public void paint(Graphics g) {
    g.drawImage(image, 0, 0, this);

    // Notify method splash that the window has been painted.
    // Note: To improve performance we do not enter the synchronized block unless we have to.
    if (!paintCalled) {
      paintCalled = true;
      synchronized (this) {
        notifyAll();
      }
    }
  }
Ejemplo n.º 10
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);

  }
Ejemplo n.º 11
0
Archivo: set.java Proyecto: wcyuan/Set
    public void draw(Graphics g, ImageObserver ob) {
      if (!todraw) {
        g.setColor(bgcolor);
        g.drawRect(x, y, w + 2 * border, h + 2 * border);
        g.fillRect(x, y, w + 2 * border, h + 2 * border);
        return;
      }

      if (selected) g.setColor(selected_color);
      else g.setColor(unselected_color);

      g.drawRect(x, y, w + 2 * border, h + 2 * border);
      g.fillRect(x, y, w + 2 * border, h + 2 * border);
      g.drawImage(image[im], x + border, y + border, ob);

      // g.setColor(Color.black);
      // g.drawString("" + im,x+5,y+5);
    }
Ejemplo n.º 12
0
  private synchronized void render(Graphics g) {
    if (level != null) {
      int xScroll = (int) (player.pos.x - screen.w / 2);
      int yScroll = (int) (player.pos.y - (screen.h - 24) / 2);
      soundPlayer.setListenerPosition((float) player.pos.x, (float) player.pos.y);
      level.render(screen, xScroll, yScroll);
    }
    if (!menuStack.isEmpty()) {
      menuStack.peek().render(screen);
    }

    Font.draw(screen, "FPS: " + fps, 10, 10);
    // for (int p = 0; p < players.length; p++) {
    // if (players[p] != null) {
    // String msg = "P" + (p + 1) + ": " + players[p].getScore();
    // Font.draw(screen, msg, 320, screen.h - 24 + p * 8);
    // }
    // }
    if (player != null && menuStack.size() == 0) {
      Font.draw(screen, player.health + " / 10", 340, screen.h - 19);
      Font.draw(screen, "" + player.score, 340, screen.h - 33);
    }

    g.setColor(Color.BLACK);

    g.fillRect(0, 0, getWidth(), getHeight());
    g.translate((getWidth() - GAME_WIDTH * SCALE) / 2, (getHeight() - GAME_HEIGHT * SCALE) / 2);
    g.clipRect(0, 0, GAME_WIDTH * SCALE, GAME_HEIGHT * SCALE);

    if (!menuStack.isEmpty() || level != null) {

      // render mouse
      renderMouse(screen, mouseButtons);

      g.drawImage(screen.image, 0, 0, GAME_WIDTH * SCALE, GAME_HEIGHT * SCALE, null);
    }

    // String msg = "FPS: " + fps;
    // g.setColor(Color.LIGHT_GRAY);
    // g.drawString(msg, 11, 11);
    // g.setColor(Color.WHITE);
    // g.drawString(msg, 10, 10);

  }
Ejemplo n.º 13
0
  public static java.awt.image.BufferedImage loadBufferedImageFromResources(
      Component c, String filename) {

    try {
      Misc m = new Misc();
      java.awt.Image img = loadImageFromResources(filename);
      MediaTracker mt = new MediaTracker(c);
      mt.addImage(img, 0);
      mt.waitForID(0);
      int width = img.getWidth(null);
      int height = img.getHeight(null);
      BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
      Graphics gg = bi.getGraphics();
      gg.drawImage(img, 0, 0, null);
      gg.dispose();
      return bi;
    } catch (Exception ex) {
      System.out.println(ex.toString());
    }
    return null;
  }
Ejemplo n.º 14
0
 private final void showpercent(String s, int i, int j) {
   Graphics g = getGraphics();
   Font font = new Font("Helvetica", 1, 13);
   FontMetrics fontmetrics = getFontMetrics(font);
   Font font1 = new Font("Helvetica", 0, 13);
   FontMetrics fontmetrics1 = getFontMetrics(font1);
   if (all || !img && mt.checkAll(true)) {
     all = false;
     if (img || mt.checkAll(true)) {
       g.drawImage(loading, 0, 0, this);
       img = true;
     } else {
       g.setColor(Color.black);
       g.fillRect(0, 0, 512, 344);
     }
     g.setColor(Color.white);
     g.setFont(font);
     String s1 = "RuneScape has been updated!";
     g.drawString(s1, 256 - fontmetrics.stringWidth(s1) / 2, 125);
     s1 = "Please wait - Fetching new files...";
     g.drawString(s1, 256 - fontmetrics.stringWidth(s1) / 2, 140);
     g.setFont(font1);
     s1 = "This may take a few minutes, but only";
     g.drawString(s1, 256 - fontmetrics1.stringWidth(s1) / 2, 165);
     s1 = "needs to be done when the game is updated.";
     g.drawString(s1, 256 - fontmetrics1.stringWidth(s1) / 2, 180);
   }
   Color color = new Color(140, 17, 17);
   g.setColor(color);
   g.drawRect(104, 190, 304, 34);
   g.fillRect(106, 192, j * 3, 30);
   g.setColor(Color.black);
   g.fillRect(106 + j * 3, 192, 300 - j * 3, 30);
   String s2 = "Loading " + s + " - " + i + "%";
   g.setFont(font);
   g.setColor(Color.white);
   g.drawString(s2, 256 - fontmetrics.stringWidth(s2) / 2, 212);
 }
Ejemplo n.º 15
0
  /**
   * Paints the image.
   *
   * @param g the rendering surface to use
   * @param a the allocated region to render into
   * @see View#paint
   */
  public void paint(Graphics g, Shape a) {
    Color oldColor = g.getColor();
    fBounds = a.getBounds();
    int border = getBorder();
    int x = fBounds.x + border + getSpace(X_AXIS);
    int y = fBounds.y + border + getSpace(Y_AXIS);
    int width = fWidth;
    int height = fHeight;
    int sel = getSelectionState();

    // Make sure my Component is in the right place:
    /*
    if( fComponent == null ) {
    fComponent = new Component() { };
    fComponent.addMouseListener(this);
    fComponent.addMouseMotionListener(this);
    fComponent.setCursor(Cursor.getDefaultCursor());	// use arrow cursor
    fContainer.add(fComponent);
    }
    fComponent.setBounds(x,y,width,height);
    */
    // If no pixels yet, draw gray outline and icon:
    if (!hasPixels(this)) {
      g.setColor(Color.lightGray);
      g.drawRect(x, y, width - 1, height - 1);
      g.setColor(oldColor);
      loadIcons();
      Icon icon = fImage == null ? sMissingImageIcon : sPendingImageIcon;
      if (icon != null) icon.paintIcon(getContainer(), g, x, y);
    }

    // Draw image:
    if (fImage != null) {
      g.drawImage(fImage, x, y, width, height, this);
      // Use the following instead of g.drawImage when
      // BufferedImageGraphics2D.setXORMode is fixed (4158822).

      //  Use Xor mode when selected/highlighted.
      // ! Could darken image instead, but it would be more expensive.
      /*
      if( sel > 0 )
      g.setXORMode(Color.white);
      g.drawImage(fImage,x, y,
      width,height,this);
      if( sel > 0 )
      g.setPaintMode();
      */
    }

    // If selected exactly, we need a black border & grow-box:
    Color bc = getBorderColor();
    if (sel == 2) {
      // Make sure there's room for a border:
      int delta = 2 - border;
      if (delta > 0) {
        x += delta;
        y += delta;
        width -= delta << 1;
        height -= delta << 1;
        border = 2;
      }
      bc = null;
      g.setColor(Color.black);
      // Draw grow box:
      g.fillRect(x + width - 5, y + height - 5, 5, 5);
    }

    // Draw border:
    if (border > 0) {
      if (bc != null) g.setColor(bc);
      // Draw a thick rectangle:
      for (int i = 1; i <= border; i++)
        g.drawRect(x - i, y - i, width - 1 + i + i, height - 1 + i + i);
      g.setColor(oldColor);
    }
  }
Ejemplo n.º 16
0
 public final void paint(Graphics g) {
   all = true;
   if (inner != null) inner.paint(g);
   if (forcems) g.drawImage(fms, 0, 0, this);
 }
Ejemplo n.º 17
0
 public void paint(Graphics g) {
   if (image != null) {
     g.drawImage(image, 0, 0, getSize().width, getSize().height, this);
   }
 }
Ejemplo n.º 18
0
 @Override
 public void paintComponent(Graphics g) {
   g.drawImage(back, 0, 0, null);
   super.paintComponent(g);
 }
 protected void endDraw(Graphics g) {
   g.drawImage(frontImage, 0, 0, null);
 }
Ejemplo n.º 20
0
  public void paint(Graphics g) {

    g.drawImage(im1, 0, 0, this);
  }