Example #1
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);
        }
      }
    }
  }
 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);
     }
   }
 }
 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);
   }
 }
Example #4
0
  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()
Example #5
0
 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);
   }
 }
Example #6
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;
      }
    }
  }
Example #7
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!");
    }
  }
Example #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);
  }
 public void drawInto(Graphics g) {
   if ((g == null) || (!visible)) return;
   Rectangle r = getBounds();
   if (selected) {
     g.drawImage(activeImage, r.x, r.y, null);
   } else {
     g.drawImage(idleImage, r.x, r.y, null);
   }
 }
Example #10
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);
  }
Example #11
0
 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));
 }
Example #12
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);
     }
   }
 }
 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
   }
 }
 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
   }
 }
Example #15
0
 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;
   }
 }
  public void paint(Graphics g) {
    // Only create the image at the beginning -
    if ((img == null) || (prefsize.width != size().width) || (prefsize.height != size().height)) {
      prefsize.width = size().width;
      prefsize.height = size().height;

      scale = findScale();

      //      System.out.println("New scale = " + scale);
      img = createImage(size().width, size().height);
      ig = img.getGraphics();

      redrawneeded = true;
    }

    if (redrawneeded == true) {
      drawBackground(ig, Color.black);
      drawScene(ig);
      if (drawAxes == true) {
        drawAxes(ig);
      }
      redrawneeded = false;
    } else {
      ig = img.getGraphics();
    }

    g.drawImage(img, 0, 0, this);
  }
Example #17
0
  public void mouseWheelMoved(MouseWheelEvent event) {

    int zoom = event.getWheelRotation();

    mx = event.getX();
    my = event.getY();

    showStatus("Mouse rotated (" + zoom + ")");

    // zoom out
    if (zoom >= 0) {
      dbg.setColor(Color.black);
      //			dbg.drawImage (background, SIZE/2-current_size/2,
      //			        SIZE/2-current_size/2, current_size, current_size, this);
    }
    // zoom in
    else if (zoom < 0) {
      int width = building.getWidth(this);
      int height = building.getHeight(this);
      dbg.drawImage(
          building, width, height, width / 2, height / 2, width, height, width, height, this);
    }

    repaint();
    event.consume();
  }
Example #18
0
  // Scaling relative to the center of the screen
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (bufferImage == null) {
      bufferImage = createImage(getWidth(), getHeight());
      bufferg = (Graphics2D) bufferImage.getGraphics();

      updateAffineTransform();
      preSize = getSize();
    }
    bufferg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    bufferg.setTransform(new AffineTransform());
    bufferg.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
    bufferg.setColor(Color.WHITE);
    bufferg.fillRect(0, 0, getWidth(), getHeight());

    bufferg.setTransform(affineTransform);

    Graphics2D g2d = bufferg;

    if (ORIPA.doc.hasModel) {
      g2d.setStroke(Config.STROKE_CUT);
      if (Globals.modelDispMode == Constants.ModelDispMode.FILL_ALPHA) {
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
      }
      drawModel(g2d);
      g.drawImage(bufferImage, 0, 0, this);
    }
  }
Example #19
0
  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);
  }
Example #20
0
  public void render(Graphics g) {

    for (int i = 0; i < invBar.length; i++) {
      boolean isSelected = false;
      if (i == selected) {
        isSelected = true;
      }
      invBar[i].render(g, isSelected);
    }

    if (isOpen) {
      for (int i = 0; i < invBag.length; i++) {
        invBag[i].render(g, false);
      }
    }

    if (isHolding) {
      g.drawImage(
          Tile.tileset_terrain,
          Component.mse.x,
          Component.mse.y,
          Component.mse.x + Tile.tileSize,
          Component.mse.y + Tile.tileSize,
          holdingID[0] * Tile.tileSize,
          holdingID[1] * Tile.tileSize,
          holdingID[0] * Tile.tileSize + Tile.tileSize,
          holdingID[1] * Tile.tileSize + Tile.tileSize,
          null);
    }
  }
Example #21
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);
  }
Example #22
0
  /** Paint it. */
  public void paint(Graphics g) {
    Dimension d = getSize();
    if (!inited || buff == null || d.width != buffSize.width || d.height != buffSize.height) {
      buffSize.width = d.width;
      buffSize.height = d.height;
      buff = createImage(d.width + 4, d.height + 4);
      if (buff == null) return;
      buffG = buff.getGraphics();
      inited = true;
    }

    buffG.setColor(Color.lightGray);
    buffG.fillRect(0, 0, prefSize.width, prefSize.height);
    PressedRect(buffG, 0, 0, prefSize.width - 2, prefSize.height - 2);

    buffG.setColor(Color.lightGray);
    buffG.fillRect(0, 0, prefSize.width + 2, prefSize.height + 2);
    if (!gameover) if ((gameover = is_game_over())) end_game();
    for (int i = 0; i < rows; i++) {
      for (int j = 0; j < cols; j++) {
        drawBlock(buffG, i, j, status(i, j));
      }
    }
    // PressedRect(buffG,0,0,prefSize.width + 2,prefSize.height + 2);
    if (buff != null) g.drawImage(buff, 0, 0, null);
  }
Example #23
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);
    }
  }
  // Overrides the draw method in Gamecore
  public void draw(Graphics g) {
    if (loggedIn) g.drawImage(bgImage, 0, 0, null);
    // g.drawImage()

    // the layered pane contains things like popups (tooltips,
    // popup menus) and the content pane.
    screen.getLayeredPane().paintComponents(g);
  }
 public static BufferedImage copyImage(BufferedImage source) {
   BufferedImage b =
       new BufferedImage(source.getWidth(), source.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
   Graphics g = b.getGraphics();
   g.drawImage(source, 0, 0, null);
   g.dispose();
   return b;
 }
 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());
   }
 }
Example #27
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);
 }
Example #28
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);
 }
Example #29
0
  //	重写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);
      }
    }
  }
Example #30
0
    public void paintComponent(Graphics page) {
      super.paintComponent(page);

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

      setOpaque(false);
    }