// 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); } } }
/** 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!"); } }
/** * @param icol * @param iRow */ public void DrawOrange(int icol, int iRow) { if (iMaze[iRow][icol] == ORANGE) if (Global.affectiveState == 1 || Global.affectiveState == 3 || Global.affectiveState == 6 || Global.affectiveState == 7) graphics.drawImage(imageOrange, icol * 16, iRow * 16, applet); else graphics.drawImage(imageBlank, icol * 16, iRow * 16, applet); }
/** * @param icol * @param iRow */ public void DrawMelon(int icol, int iRow) { if (iMaze[iRow][icol] == MELON) if (Global.affectiveState == 1 || Global.affectiveState == 3 || Global.affectiveState == 6 || Global.affectiveState == 7) graphics.drawImage(imageMelon, icol * 16, iRow * 16, applet); else graphics.drawImage(imageBlank, icol * 16, iRow * 16, applet); }
/** * @param icol * @param iRow */ public void DrawOneUp(int icol, int iRow) // <----------------------------One-up { if (iMaze[iRow][icol] == ONE_UP) if (Global.affectiveState == 1 || Global.affectiveState == 3 || Global.affectiveState == 6 || Global.affectiveState == 7) graphics.drawImage(imageOneUp, icol * 16, iRow * 16, applet); else graphics.drawImage(imageBlank, icol * 16, iRow * 16, applet); }
void drawGrape() { int i, j; for (i = 0; i < HEIGHT; i++) for (j = 0; j < WIDTH; j++) { if (iMaze[i][j] == GRAPE) if (Global.affectiveState == 1 || Global.affectiveState == 3 || Global.affectiveState == 6 || Global.affectiveState == 7) graphics.drawImage(imageGrape, j * 16, i * 16, applet); else graphics.drawImage(imageBlank, j * 16, i * 16, applet); } }
void drawOneUp() // <--------------------------One-up { int i, j; for (i = 0; i < HEIGHT; i++) for (j = 0; j < WIDTH; j++) { if (iMaze[i][j] == ONE_UP) if (Global.affectiveState == 1 || Global.affectiveState == 3 || Global.affectiveState == 6 || Global.affectiveState == 7) graphics.drawImage(imageOneUp, j * 16, i * 16, applet); else graphics.drawImage(imageBlank, j * 16, i * 16, applet); } }
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 } }
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); }
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); }
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); }
public static Image createThumbnail(Image image, int width, int height) { int sourceWidth = image.getWidth(); int sourceHeight = image.getHeight(); if ((width > sourceWidth) && (height > sourceHeight)) { return image; } int thumbWidth = width; int thumbHeight = thumbWidth * sourceHeight / sourceWidth; if (thumbHeight > height) { thumbHeight = height; thumbWidth = thumbHeight * sourceWidth / sourceHeight; } // #sijapp cond.if modules_ANDROID is "true"# Image scaled = image.scale(thumbWidth, thumbHeight); if (null != scaled) return scaled; // #sijapp cond.end# Image thumb = Image.createImage(thumbWidth, thumbHeight); Graphics g = thumb.getGraphics(); for (int y = 0; y < thumbHeight; ++y) { for (int x = 0; x < thumbWidth; ++x) { g.setClip(x, y, 1, 1); int dx = x * sourceWidth / thumbWidth; int dy = y * sourceHeight / thumbHeight; g.drawImage(image, x - dx, y - dy, Graphics.LEFT | Graphics.TOP); } } return thumb; }
@Override public void paint(Graphics g) { setBackground(Color.white); g.drawImage(image, 0, 0, null); }
public void draw(Graphics g, ImagesLoader imLoad) { for (int i = 0; i < pickupList.size(); i++) { Pickup p = pickupList.get(i); BufferedImage img = imLoad.getImage(p.type); g.drawImage(img, (int) p.x, (int) p.y, null); } // end for } // end draw
public void drawStar(Graphics g) { // draws the stars for (Star i : starList) { g.drawImage( i.getPics().get(i.getCounter()), i.getX(), i.getY(), i.getWidth(), i.getHeight(), null); i.count(); } }
public void paintComponent(Graphics page) { super.paintComponent(page); Image icon = this.getToolkit().getImage("chess1.jpg"); page.drawImage(icon, -40, 20, this); setOpaque(false); }
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()); } }
public void moveLayerOne( Graphics g) { // drawing the background, we have to make this into percentage afterwards g.drawImage( gameBckgrnd, 0, (((int) (backy * 0.1)) % 23080) - 23080, this); // makes it continues and i have an extra image on top just to be safe }
// 重写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); } } }
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); }
protected void paintImage( Component c, Graphics g, int x, int y, int imageW, int imageH, Image image, Object[] args) { boolean isVertical = ((Boolean) args[1]).booleanValue(); // Render to the screen g.translate(x, y); if (isVertical) { for (int counter = 0; counter < w; counter += IMAGE_SIZE) { int tileSize = Math.min(IMAGE_SIZE, w - counter); g.drawImage(image, counter, 0, counter + tileSize, h, 0, 0, tileSize, h, null); } } else { for (int counter = 0; counter < h; counter += IMAGE_SIZE) { int tileSize = Math.min(IMAGE_SIZE, h - counter); g.drawImage(image, 0, counter, w, counter + tileSize, 0, 0, w, tileSize, null); } } g.translate(-x, -y); }
void drawDots() // on the offscreen { int i, j; for (i = 0; i < HEIGHT; i++) for (j = 0; j < WIDTH; j++) { if (iMaze[i][j] == DOT) graphics.drawImage(imageDot, j * 16 + 7, i * 16 + 7, applet); } }
// ------------------------------------------------------------------------------------------------------------------------------------------------------- // Drawing public void drawCoin(Graphics g) { // draws the coins for (Coin i : coinList) { g.drawImage( i.getPics().get(i.getCounter()), i.getX(), i.getY(), i.getWidth(), i.getHeight(), null); i.count(); i.setDirection(); } }
public void displayScore2( Graphics g, int cx, int cy, int sx1, int sy1, int sx2, int sy2, int sx3, int sy3) { g.setFont(scoreFont); g.setColor(Color.WHITE); g.drawImage(new ImageIcon("InGameMenu/coin.png").getImage(), cx, cy, this); g.drawString("" + coins, sx1, sy1); g.drawString("Score: " + score, sx2, sy2); g.drawString("Height: " + height + " m", sx3, sy3); }
/** * 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))); }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (resourceImage != null) { g.drawImage(resourceImage, 1, 1, this); } }
public void paint(final Graphics g) { final Image image; if (rabbit.isMove() && rabbit.getState() == RabbitState.STOP) { image = changeImage(); } else { image = images.get(0); } final Position pos = rabbit.getPosition(); g.drawImage(image, pos.getX(), pos.getY(), rabbit.getWidth(), rabbit.getHeight(), this); }