コード例 #1
0
    public void paintIcon(Graphics g) {
      final BufferedImage image =
          new BufferedImage(
              myIcon.getIconWidth(), myIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
      final Graphics2D gg = image.createGraphics();
      myIcon.paintIcon(this, gg, 0, 0);

      final Rectangle bounds = g.getClipBounds();
      int y = myIcon.getIconHeight() - 1;
      while (y < bounds.y + bounds.height) {
        g.drawImage(
            image,
            bounds.x,
            y,
            bounds.x + bounds.width,
            y + 1,
            0,
            myIcon.getIconHeight() - 1,
            bounds.width,
            myIcon.getIconHeight(),
            this);

        y++;
      }

      g.drawImage(image, 0, 0, this);
    }
コード例 #2
0
 public void moveLayerThree(Graphics g) {
   backy += (int) (player1.getVelocity() * 0.1);
   midy += (int) (player1.getVelocity() * 0.5);
   drawEnemy(g);
   drawCoin(g);
   drawBox(g);
   drawPoof(g);
   drawStar(g);
   drawJumper(g);
   drawSpike(g);
   drawPup(g);
   if (backy <= dieHeight) {
     // System.out.println(die);
     g.drawImage(player1.move(2), player1.getX(), player1.getY(), this);
     if (player1.animationComplete()) {
       die = true;
     }
   } else {
     if (backy <= dieHeight) {
       player1.resetCounter();
     }
     if (keys[KeyEvent.VK_RIGHT]) {
       g.drawImage(player1.move(1), player1.getX(), player1.getY(), this);
     } else if (keys[KeyEvent.VK_LEFT]) {
       g.drawImage(player1.move(-1), player1.getX(), player1.getY(), this);
     } else {
       g.drawImage(player1.move(0), player1.getX(), player1.getY(), this);
     }
   }
 }
コード例 #3
0
ファイル: JackPanel.java プロジェクト: hustbill/bounce
  private void gameRender() {
    if (dbImage == null) {
      dbImage = createImage(PWIDTH, PHEIGHT);
      if (dbImage == null) {
        System.out.println("dbImage is null");
        return;
      } else dbg = dbImage.getGraphics();
    }

    // draw a white background
    dbg.setColor(Color.white);
    dbg.fillRect(0, 0, PWIDTH, PHEIGHT);

    // draw the game elements: order is important
    ribsMan.display(dbg); // the background ribbons
    bricksMan.display(dbg); // the bricks
    jack.drawSprite(dbg); // the sprites
    fireball.drawSprite(dbg);

    if (showExplosion) // draw the explosion (in front of jack)
    dbg.drawImage(explosionPlayer.getCurrentImage(), xExpl, yExpl, null);

    reportStats(dbg);

    if (gameOver) gameOverMessage(dbg);

    if (showHelp) // draw the help at the very front (if switched on)
    dbg.drawImage(
          helpIm, (PWIDTH - helpIm.getWidth()) / 2, (PHEIGHT - helpIm.getHeight()) / 2, null);
  } // end of gameRender()
コード例 #4
0
  // draws the button, based on the type of button (ImageIcon, Image, or String)
  public void draw(Graphics g) {
    if (visible) {
      // if its image/imageicon, draw it
      g.setColor(new Color(50, 200, 50));
      g.fillRect(x - 1, y - 1, width + 2, height + 2);
      if (mode.equals("Image") || mode.equals("ImageIcon")) {
        if (enabled) {
          g.drawImage(image, x, y, null);
        } else {
          g.drawImage(BWimage, x, y, null);
        }
        // if its string, draw the string
      } else {

        g.setFont(new Font("Arial", Font.PLAIN, 20));
        if (enabled) {
          g.setColor(Color.black);
          g.drawString(message, x + 20, y + 20);
        } else {
          g.setColor(new Color(255, 255, 255));
          g.fillRect(x - 1, y - 1, width + 2, height + 2);
          g.setColor(Color.black);
          g.drawString(message, x + 20, y + 20);
        }
      }
    }
  }
コード例 #5
0
ファイル: THA.java プロジェクト: tlulu/Tetris-Platformer
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   setBackground(Color.black);
   add(l);
   add(s);
   drawSpecialLines(g);
   g.setColor(Color.white);
   g.fillOval(30, 100, 75, 75);
   g.setColor(Color.blue);
   g.fillRect(getWidth() / 2, getHeight() / 2, (int) bl, 10);
   g.fillRect(getWidth() / 2, getHeight() / 2 + 40, (int) gl, 10);
   g.fillRect(getWidth() / 2, getHeight() / 2 + 80, (int) ll, 10);
   g.fillRect(getWidth() / 2, getHeight() / 2 + 120, (int) sl, 10);
   g.drawImage(bullet.getImage(), 30, getHeight() / 2 - 10, 20, 20, null);
   g.drawImage(grenade.getImage(), 30, getHeight() / 2 + 40 - 10, 20, 20, null);
   g.drawImage(laser.getImage(), 30, getHeight() / 2 + 80 - 10, 20, 20, null);
   g.drawImage(shotgun.getImage(), 30, getHeight() / 2 + 120 - 10, 20, 20, null);
   g.setColor(Color.yellow);
   if (gunTrack == 0) {
     g.drawRect(30, getHeight() / 2 - 10, 20, 20);
   } else if (gunTrack == 1) {
     g.drawRect(30, getHeight() / 2 + 40 - 10, 20, 20);
   } else if (gunTrack == 2) {
     g.drawRect(30, getHeight() / 2 + 80 - 10, 20, 20);
   } else {
     g.drawRect(30, getHeight() / 2 + 120 - 10, 20, 20);
   }
 }
コード例 #6
0
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   if (scene == OVERWORLD) g.drawImage(background, 0, 0, this);
   if (scene == BATTLE) {
     if (battleBG == 1) g.drawImage(background, 0, -130, this);
     else g.drawImage(background, 0, 0, this);
   }
   int loop;
   for (loop = 0; loop < enemies.size(); loop++) {
     if (scene == OVERWORLD) {
       enemies.get(loop).drawEnemy(g);
     }
     if (scene == BATTLE) {
       if (enemies.get(loop).getActivity()) {
         enemies.get(loop).drawEnemy(g);
       }
     }
   }
   for (loop = 0; loop < spellsThrown.size(); loop++) {
     spellsThrown.get(loop).drawSpell(g);
   }
   player.drawPlayer(g);
   for (loop = 0; loop < enemies.size(); loop++) {
     enemies.get(loop).drawSpells(g);
   }
   if (scene == BATTLE) {
     drawMenu(g);
     if (battleWon) drawVictory(g);
     else if (battleLost) drawDefeat(g);
   }
 }
コード例 #7
0
ファイル: TicTac.java プロジェクト: Sykess/Eastwood
  /** 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!");
    }
  }
コード例 #8
0
  public void paint(Graphics gOld) {
    if (image == null || xsize != getSize().width || ysize != getSize().height) {
      xsize = getSize().width;
      ysize = getSize().height;
      image = createImage(xsize, ysize);
      g = (Graphics2D) image.getGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }
    // fill background
    g.setColor(Color.cyan);
    g.fillRect(0, 0, xsize, ysize);

    int x[] = {getX(0), getX(getWidth2()), getX(getWidth2()), getX(0), getX(0)};
    int y[] = {getY(0), getY(0), getY(getHeight2()), getY(getHeight2()), getY(0)};
    // fill border
    g.setColor(Color.black);
    g.fillPolygon(x, y, 4);
    // draw border
    g.setColor(Color.red);
    g.drawPolyline(x, y, 5);
    if (animateFirstTime) {
      gOld.drawImage(image, 0, 0, null);
      return;
    }
    if (gameOver) return;
    g.drawImage(outerSpaceImage, getX(0), getY(0), getWidth2(), getHeight2(), this);
    for (int index = 0; index < missile.length; index++) {
      if (missile[index].active) {
        g.setColor(Color.red);
        drawCircle(getX(missile[index].xPos), getYNormal(missile[index].yPos), 90, .3, 1.5);
      }
    }
    if (rocketRight) {
      drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, 2.0, 2.0);
    } else {
      drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, -2.0, 2.0);
    }
    for (int index = 0; index < numStars; index++) {
      g.setColor(Color.yellow);
      if (starActive[index])
        drawCircle(getX(starXPos[index]), getYNormal(starYPos[index]), 0, 1.5, 1.5);
    }
    g.setColor(Color.magenta);
    g.setFont(new Font("Impact", Font.BOLD, 15));
    g.drawString("Score: " + score, 10, 45);
    g.setColor(Color.magenta);
    g.setFont(new Font("Impact", Font.BOLD, 15));
    g.drawString("HighScore: " + highScore, 300, 45);
    g.setColor(Color.magenta);
    g.setFont(new Font("Impact", Font.BOLD, 15));
    g.drawString("Lives: " + rocketLife, 150, 45);
    if (rocketLife == 0) {
      g.setColor(Color.red);
      g.setFont(new Font("Impact", Font.BOLD, 60));
      g.drawString("GAME OVER", getX(getWidth2() / 6), getYNormal(getHeight2() / 2));
    }
    gOld.drawImage(image, 0, 0, null);
  }
コード例 #9
0
  public void paint(Graphics g) {
    super.paint(g);
    g.setFont(fotn);
    Random generator1 = new Random();
    height = bird.getBirdy();

    g.drawImage(Backgroundtop, 0, 0, 450, 644, null);
    g.drawImage(Bird, 100, height, 40, 30, null);

    if (firstrun == true) { // intiate threads
      pipethread[currentthreads].start();
      birdthread.start();
      firstrun = false;
    }

    for (int index = 0; index <= currentthreads; index++) {
      g.drawImage(Pipes, pipeob[index].getpipex(), pipeob[index].getpipey(), null);
    }

    g.drawImage(Backgroundbottom, 0, 644, 450, 156, null);

    g.setColor(Color.black);

    if (pipeob[currentthreads].getpipex() <= 550) {
      currentthreads++;
      pipethread[currentthreads].start();
      score++;
    }
    g.drawString("Score: " + score + "", 50, 50);

    for (int index = 0; index < currentthreads; index++) {
      if (((height < pipeob[index].getpipey() + 730) || (height > pipeob[index].getpipey() + 870))
              && ((pipeob[index].getpipex() < 100) && (pipeob[index].getpipex() + 72 > 100))
          || ((height < pipeob[index].getpipey() + 730)
                  || (height > pipeob[index].getpipey() + 870))
              && ((pipeob[index].getpipex() < 140) && (pipeob[index].getpipex() + 72 > 140))
          || ((height + 30 < pipeob[index].getpipey() + 730)
                  || (height + 30 > pipeob[index].getpipey() + 870))
              && ((pipeob[index].getpipex() < 100) && (pipeob[index].getpipex() + 72 > 100))
          || ((height + 30 < pipeob[index].getpipey() + 730)
                  || (height + 30 > pipeob[index].getpipey() + 870))
              && ((pipeob[index].getpipex() < 140) && (pipeob[index].getpipex() + 72 > 140))
          || ((height + 30 >= 644))) {
        g.drawImage(gameover, 125, 200, null);
        JOptionPane.showMessageDialog(
            null, "You Dead. \n you scored " + score, "Oh no!", JOptionPane.INFORMATION_MESSAGE);
      }
    }
    for (int counter = 0; counter <= 50000000; counter++) {
      counter++;
      counter--;
    }
    do {
      repaint();
    } while (replay = true);
  }
コード例 #10
0
ファイル: Board.java プロジェクト: ankeshs/hex
 void circle(Graphics g, double x, double y, int st) {
   switch (st) {
     case Block.BLANK:
       return;
     case Block.RED_BEAD:
       switch (gst.theme) {
         case 0:
           g.setColor(Color.RED);
           break;
         case 1:
           g.setColor(Color.BLACK);
           break;
         case 2:
           g.drawImage(
               gold,
               (int) (x - bst.scale * r3 / 2 * 0.75),
               (int) (y - bst.scale * r3 / 2 * 0.75),
               (int) (bst.scale * r3 * 0.75),
               (int) (bst.scale * r3 * 0.75),
               Color.WHITE,
               null);
           return;
       }
       break;
     case Block.BLUE_BEAD:
       switch (gst.theme) {
         case 0:
           g.setColor(Color.BLUE);
           break;
         case 1:
           g.setColor(new Color(1, 175, 1));
           break;
         case 2:
           g.drawImage(
               silver,
               (int) (x - bst.scale * r3 / 2 * 0.75),
               (int) (y - bst.scale * r3 / 2 * 0.75),
               (int) (bst.scale * r3 * 0.75),
               (int) (bst.scale * r3 * 0.75),
               Color.WHITE,
               null);
           return;
       }
       break;
     case Block.RED_PATH:
     case Block.BLUE_PATH:
       g.setColor(Color.GREEN);
       break;
   }
   g.fillOval(
       (int) (x - bst.scale * r3 / 2 * 0.75),
       (int) (y - bst.scale * r3 / 2 * 0.75),
       (int) (bst.scale * r3 * 0.75),
       (int) (bst.scale * r3 * 0.75));
 }
コード例 #11
0
 /** The field view component needs to be redisplayed. Copy the internal image to screen. */
 public void paintComponent(Graphics g) {
   if (fieldImage != null) {
     Dimension currentSize = getSize();
     if (size.equals(currentSize)) {
       g.drawImage(fieldImage, 0, 0, null);
     } else {
       // Rescale the previous image.
       g.drawImage(fieldImage, 0, 0, currentSize.width, currentSize.height, null);
     }
   }
 }
コード例 #12
0
 public void lvlClearMenu(Graphics g) {
   // Menu that shows up after a level has been cleared
   if (pause == true && lvlClear == true) {
     g.drawImage(
         new ImageIcon("InGameMenu/pauseBckgrnd.png").getImage(), 0, 0, this); // <Graphics stuff
     g.drawImage(new ImageIcon("InGameMenu/stageClearPic.png").getImage(), 100, 0, this);
     displayScore2(g, 115, 350, 185, 380, 110, 440, 110, 490); // Displays stats
     g.drawImage(
         resumeB.getPic(mx, my), resumeB.getX(), resumeB.getY(), this); // Draws resume button
     g.drawImage(
         menuB.getPic(mx, my), menuB.getX(), menuB.getY(), this); // Draws the back to menu button
   }
 }
コード例 #13
0
 public void gameOverMenu(
     Graphics g) { // CHANGE THIS TO INCLUDE HIGHSCORES AND STUFF AFTER TEXTFILES ARE MADE
   // Menu that shows up when user gets Game Over
   if (pause == true && die == true) {
     g.drawImage(
         new ImageIcon("InGameMenu/pauseBckgrnd.png").getImage(), 0, 0, this); // Graphics stuff
     g.setFont(scoreFont);
     g.setColor(Color.BLACK);
     g.drawImage(new ImageIcon("InGameMenu/GameOver.png").getImage(), 10, 200, this);
     displayScore2(g, 115, 350, 185, 385, 110, 440, 110, 490); // Shows stats
     g.drawImage(menuB.getPic(mx, my), menuB.getX(), menuB.getY(), this); // Draws menu button
   }
 }
コード例 #14
0
ファイル: GameMenu.java プロジェクト: Lixire/Ascension
 public void paintComponent(Graphics g) {
   g.drawImage(background, 0, 0, this);
   g.drawImage(start[0], 570, 320, this);
   // Buttons
   if (570 < mx && mx < 750 && 320 < my && my < 370) {
     g.drawImage(start[1], 570, 320, this);
   }
   g.drawImage(load[0], 570, 380, this);
   if (570 < mx && mx < 750 && 380 < my && my < 430) {
     g.drawImage(load[1], 570, 380, this);
   }
   // Instructions Screen
   if (drawn) {
     g.drawImage(intro, -5, -14, this);
   }
   g.drawImage(instr[0], 570, 440, this);
   if (570 < mx && mx < 750 && 440 < my && my < 490) {
     g.drawImage(instr[1], 570, 440, this);
   }
   if (getWords.getPressed() && !getWords.getCurrent().equals("")) {
     loadPlayer(getWords.getCurrent());
     getWords.setVisible(false);
     getWords = new inputBox("Load Game");
     newGame = true;
   }
 }
コード例 #15
0
ファイル: Card.java プロジェクト: agale123/Catan
  public void paint(Graphics g) {

    g.fillRect((_x), (_y), _w, _h);
    g.fillRect((_x), (_y), _w, _h);
    g.fillRect((_x), (_y), _w, _h);
    g.drawImage(images.get(mytype), (_x), (_y), _w, _h, null);
  }
コード例 #16
0
  public void paint(Graphics gg) {
    int faceSize = Math.min(getWidth() - 4, getHeight() - 4);
    if (face == null)
      face =
          new PADFaceMapped(
              Math.max(2, (getWidth() - faceSize) / 2),
              Math.max(2, (getHeight() - faceSize) / 2),
              faceSize);
    if (buffer == null) {
      im = this.createImage(getWidth(), getHeight());
      buffer = im.getGraphics();
    }
    super.paint(buffer);

    buffer.setColor(new Color(255, 255, 255, 0));
    buffer.fillRect(0, 0, im.getWidth(null), im.getHeight(null));

    face.setDimensions(
        Math.max(2, (getWidth() - faceSize) / 2),
        Math.max(2, (getHeight() - faceSize) / 2),
        faceSize);
    face.paint(buffer);

    // draw buffer to screen
    gg.drawImage(im, 0, 0, null, null);
  }
コード例 #17
0
  /**
   * The paintComponent() method copies the off-screen canvas to the screen (first creating it, if
   * necessary). If a mouse drag is is progress, then the current tool is not Tool.CURVE, then the
   * shape that the user is drawing is drawn over the off-screen canvas. (This is to avoid making
   * the shape a permanent part of the picture until after the user releases the mouse. The effect
   * is a "rubber band cursor" in which the shape changes as the user drags the mouse, but the
   * picture under the shape is not affected.)
   */
  @Override
  public void paintComponent(Graphics g) {

    /* First create the off-screen canvas, if it does not already exist. */

    if (OSC == null) {
      createOSC();
    }

    /* Copy the off-screen canvas to the panel.  Since we know that the
    image is already completely available, the fourth "ImageObserver"
    parameter to g.drawImage() can be null.  Since the canvas completely
    fills the panel, there is no need to call super.paintComponent(g). */

    g.drawImage(OSC, 0, 0, null);

    /* If the user is currently dragging the mouse to draw a line, oval,
    or rectangle, draw the shape on top the image from the off-screen
    canvas, using the current drawing color.  (This is not done if the
    user is drawing a curve or using the smudge tool.) */

    if (dragging && SHAPE_TOOLS.contains(currentTool)) {
      g.setColor(currentColor);
      putCurrentShape(g);
    }
  }
コード例 #18
0
ファイル: StartMenu.java プロジェクト: klmDF14J/DuskFire
  public void paint(Graphics g) {
    g.drawImage(Title, 450, 100, this);
    g.setFont(new Font("TimesRoman", Font.BOLD, 24));
    g.setColor(new Color(0x660033));

    setIconImage(icon);
  }
コード例 #19
0
  private void showAll(Graphics g) {
    // draw the image
    if (background != null)
      g.drawImage(background, 0, 0, background.getWidth(), background.getHeight(), null);

    VisualizeFeatures.drawScalePoints((Graphics2D) g, levelPoints, radius);
  }
コード例 #20
0
  public void paintComponent(Graphics g) {
    if (name == "" && serialport == "") {
      Map<String, String> boardPreferences = Base.getBoardPreferences();
      if (boardPreferences != null) setBoardName(boardPreferences.get("name"));
      else setBoardName("-");
      setSerialPort(Preferences.get("serial.port"));
    }
    g.setColor(background);
    Dimension size = getSize();
    g.fillRect(0, 0, size.width, size.height);

    g.setFont(font);
    g.setColor(foreground);
    int baseline = (high + g.getFontMetrics().getAscent()) / 2;
    g.drawString(text, 6, baseline);

    g.setColor(messageForeground);
    String tmp = name + " on " + serialport;

    Rectangle2D bounds = g.getFontMetrics().getStringBounds(tmp, null);

    g.drawString(tmp, size.width - (int) bounds.getWidth() - 20, baseline);

    if (Base.isMacOS()) {
      g.drawImage(resize, size.width - 20, 0, this);
    }
  }
コード例 #21
0
  public void redraw() {
    // update the title of the GUI
    if (getCustomTitle() == null) {
      int id = manager.getWindowIndex(this);
      if (id != 0) setTitle(getTitle() + " (view " + (id + 1) + ")");
      else setTitle(getTitle());
    }

    stepPanZoomAnimation();

    synchronized (imgLock) {
      // redraw the scene
      manager.preRedraw(this);
      manager.redraw(this);

      // copy the image buffer into the JLabel on the JFrame
      Graphics cg = lblCanvas.getGraphics();
      if (cg != null) cg.drawImage(img, 0, 0, null);

      // save a screenshot if one was requested
      if (saveScreenshotName != null) {
        try {
          ImageIO.write(img, "png", new java.io.File(saveScreenshotName));
        } catch (java.io.IOException e) {
          DialogHelper.displayError("Screenshot could not be saved: " + e);
        }
        saveScreenshotName = null;
      }
    }
  }
コード例 #22
0
  private BufferedImage generateFrame(GifFrame frame) {
    int width = frame.getColumns() * CELL_WIDTH;
    BufferedImage img =
        new BufferedImage(width, frame.getRows() * CELL_HEIGHT + TEXT_AREA_HEIGHT, IMAGE_TYPE_GIF);
    Graphics graphics = img.getGraphics();
    for (int row = 0; row < frame.getRows(); row++) {
      for (int col = 0; col < frame.getColumns(); col++) {
        ImageIcon icon =
            new ImageIcon(
                "site/images/" + frame.getBoard().get(row, col).getImageFilename() + ".png");
        graphics.drawImage(icon.getImage(), col * CELL_WIDTH, row * CELL_HEIGHT, null);
      }
    }

    for (BoxOverlay overlay : frame.getOverlays()) {
      graphics.setColor(overlay.getColor());
      Rectangle rect = overlay.getRectangle();
      int rect_x = rect.getLeft() * CELL_WIDTH - OVERLAY_PADDING;
      int rect_y = rect.getTop() * CELL_HEIGHT - OVERLAY_PADDING;
      int rect_width = (rect.getRight() - rect.getLeft() + 1) * CELL_WIDTH + 2 * OVERLAY_PADDING;
      int rect_height = (rect.getBottom() - rect.getTop() + 1) * CELL_HEIGHT + 2 * OVERLAY_PADDING;
      graphics.drawRect(rect_x, rect_y, rect_width, rect_height);
      graphics.drawRect(rect_x - 1, rect_y - 1, rect_width + 2, rect_height + 2);
    }

    graphics.setColor(FONT_COLOR);
    graphics.setFont(FONT);
    FontMetrics fm = graphics.getFontMetrics();
    graphics.drawString(
        frame.getText(),
        width / 2 - fm.stringWidth(frame.getText()) / 2,
        frame.getRows() * CELL_HEIGHT + TEXT_AREA_HEIGHT / 2 + fm.getHeight() / 2);

    return img;
  }
コード例 #23
0
 private void paintScreen() {
   Graphics g = this.getGraphics();
   if (g != null && bufferImage != null) {
     g.drawImage(bufferImage, 0, 0, null);
   }
   Toolkit.getDefaultToolkit().sync();
 }
コード例 #24
0
ファイル: ImagePanel.java プロジェクト: xoebus/hci-project
  @Override
  public void paintComponent(Graphics g) {
    if (image == null) {
      super.paintComponent(g);
      return;
    }

    double imageRatio = fileImage.getWidth() / (double) fileImage.getHeight();

    int newWidth;
    int newHeight;

    if (fileImage.getWidth() > this.getWidth()) {
      newWidth = this.getWidth();
      newHeight = (int) (this.getWidth() / imageRatio);
    } else if (fileImage.getHeight() > this.getHeight()) {
      newWidth = (int) (this.getWidth() * imageRatio);
      newHeight = this.getHeight();
    } else {
      newWidth = fileImage.getWidth();
      newHeight = fileImage.getHeight();
    }

    if (cacheImage == null) {
      cacheImage = fileImage.getScaledInstance(newWidth, newHeight, 0);
    }

    int horizontalBorderSize = (this.getWidth() > newWidth) ? (this.getWidth() - newWidth) / 2 : 0;
    int verticalBorderSize =
        (this.getHeight() > newHeight) ? (this.getHeight() - newHeight) / 2 : 0;

    setBound(horizontalBorderSize, verticalBorderSize, newWidth, newHeight);

    g.drawImage(cacheImage, horizontalBorderSize, verticalBorderSize, null);
  }
コード例 #25
0
ファイル: mydraw.java プロジェクト: broli/JavaTest
  public void paintComponent(Graphics g) {

    GradientPaint gradient = new GradientPaint(70, 70, Color.blue, 150, 150, Color.orange);
    Image image = new ImageIcon("a.jpg").getImage();
    Random generator = new Random();

    int x1 = generator.nextInt(200) + 1;
    int y1 = generator.nextInt(200) + 1;
    int x2 = x1 + generator.nextInt(100) + 1;
    int y2 = x1 + generator.nextInt(100) + 1;

    g.setColor(Color.blue);
    g.fillRect(70, 70, 200, 100);

    g.setColor(Color.black);
    g.fillOval(80, 80, 170, 70);

    Graphics2D g2d = (Graphics2D) g;

    g.setColor(Color.yellow);
    g2d.fill3DRect(10, 10, 100, 100, true);

    g.drawImage(image, 300, 300, this);

    g2d.setPaint(gradient);
    g2d.fillOval(x1, y1, x2, y2);
  }
コード例 #26
0
ファイル: GameCanvas.java プロジェクト: shadrx/cluedo
  private void drawWeaponTokenForRoom(
      Graphics g, Board board, Room room, double centreX, double topY, double step) {
    Weapon weapon = _weaponLocations.get(room);

    if (weapon != null) {
      Image weaponTokenImage = weapon.tokenImage();

      double weaponTokenWidth = weaponTokenImage.getWidth(null);
      double weaponTokenHeight = weaponTokenImage.getHeight(null);

      double longestSideLength = step * WeaponTokenRatio;

      // scale so that the longest side is always larger
      if (weaponTokenWidth >= weaponTokenHeight) {
        weaponTokenWidth = longestSideLength;
        double ratio = weaponTokenImage.getWidth(null) / weaponTokenWidth;
        weaponTokenHeight = weaponTokenHeight / ratio;
      } else {
        weaponTokenHeight = longestSideLength;
        double ratio = weaponTokenImage.getHeight(null) / weaponTokenHeight;
        weaponTokenWidth = weaponTokenWidth / ratio;
      }

      g.drawImage(
          weaponTokenImage,
          (int) (centreX - weaponTokenWidth / 2),
          (int) (topY),
          (int) weaponTokenWidth,
          (int) weaponTokenHeight,
          null);
    }
  }
コード例 #27
0
ファイル: TankGame3.java プロジェクト: yifei325325/TankGame
  //	重写paint方法
  public void paint(Graphics g) {
    super.paint(g);
    //		float lineWidth = 3.0f;
    //	    ((Graphics2D)g).setStroke(new BasicStroke(lineWidth));
    //		将坦克的活动区域填充为默认黑色
    g.fillRect(0, 0, 800, 600);
    this.drawTank(hero.getX(), hero.getY(), g, hero.getDirection(), 1);

    for (int i = 0; i < hero.bombs.size(); i++) {
      Bomb myBomb = hero.bombs.get(i);
      // 画出一颗子弹
      if (myBomb != null && myBomb.isLive == true) {
        //			float lineWidth = 2.0f;
        //			((Graphics2D) g).setStroke(new BasicStroke(lineWidth));//设置线条为粗线
        g.draw3DRect(myBomb.x, myBomb.y, 2, 2, true);
      }
      if (myBomb.isLive == false) {
        hero.bombs.remove(myBomb);
      }
    }
    //		画出爆炸
    for (int i = 0; i < baozhas.size(); i++) {
      BaoZha bz = baozhas.get(i);
      System.out.println("baozhas.size()= " + baozhas.size());
      if (bz.life > 5) {
        g.drawImage(image3, bz.x, bz.y, 30, 30, this);
      } else if (bz.life > 3) {
        g.drawImage(image2, bz.x, bz.y, 30, 30, this);
      } else {
        g.drawImage(image1, bz.x, bz.y, 30, 30, this);
      }
      bz.liftDown();
      if (bz.life == 0) {
        baozhas.remove(bz);
      }
    }

    //		画出敌人的坦克
    for (int i = 0; i < ets.size(); i++) {
      EnemyTank et = ets.get(i);
      if (et.isLive) {

        this.drawTank(et.getX(), et.getY(), g, et.getDirection(), 0);
      }
    }
  }
コード例 #28
0
 public void update(Graphics g) {
   if (iBuffer == null) {
     iBuffer = this.createImage(400, 670);
   }
   Graphics gOffScreen = iBuffer.getGraphics();
   paint(gOffScreen);
   g.drawImage(iBuffer, 0, 0, null);
 }
コード例 #29
0
ファイル: AppFrame.java プロジェクト: CestLaVi3/Android-Mouse
 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);
 }
コード例 #30
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());
   }
 }