/** 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!"); } }
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(); }
public void paint(Graphics g) { // image=tool.getImage(imageName); int h = image2.getHeight(this) / 2; int w = image2.getWidth(this) / 2; g.drawImage(image2, 150, 100, this); // g.drawImage(this.image2, 150+w+30, 100,w,h,this); // g.drawString(imageName, 170, 50); }
public void paintComponent(Graphics g) { if (paint) { try { Rectangle vis = getVisibleRect(); File fi = ImageLoader.getFile("images/inventoryback.png"); BufferedImage bg = ImageIO.read(fi.toURL()); g.drawImage(bg, vis.x, vis.y, null); } catch (Exception e) { } } }
public void drawTileNumC(int tileNum, int x, int y, Color c, Graphics g) { BufferedImage coloredTile = tiles[tileNum]; for (int i = 0; i < this.tW; i++) { for (int j = 0; j < this.tH; j++) { Color originalColor = new Color(coloredTile.getRGB(i, j), true); Color nc = new Color(c.getRed(), c.getGreen(), c.getBlue(), originalColor.getAlpha()); coloredTile.setRGB(i, j, nc.getRGB()); } } g.drawImage(tiles[tileNum], x, y, null); }
// 重写JPanel的paint方法,实现绘画 public void paint(Graphics g) { // 将绘制五子棋棋盘 g.drawImage(table, 0, 0, null); // 绘制选中点的红框 if (selectedX >= 0 && selectedY >= 0) g.drawImage(selected, selectedX * RATE + X_OFFSET, selectedY * RATE + Y_OFFSET, null); // 遍历数组,绘制棋子。 for (int i = 0; i < BOARD_SIZE; i++) { for (int j = 0; j < BOARD_SIZE; j++) { // 绘制黑棋 if (board[i][j].equals("●")) { g.drawImage(black, i * RATE + X_OFFSET, j * RATE + Y_OFFSET, null); } // 绘制白棋 if (board[i][j].equals("○")) { g.drawImage(black, i * RATE + X_OFFSET, j * RATE + Y_OFFSET, null); } } } }
@Override public void paintComponent(Graphics g) { g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); int w = bufferedImage.getWidth(this); int h = bufferedImage.getHeight(this); if (mode == Flip.NONE) { g.drawImage(bufferedImage, 0, 0, w, h, this); } else if (mode == Flip.VERTICAL) { AffineTransform at = AffineTransform.getScaleInstance(1d, -1d); at.translate(0, -h); Graphics2D g2 = (Graphics2D) g.create(); g2.drawImage(bufferedImage, at, this); g2.dispose(); } else if (mode == Flip.HORIZONTAL) { AffineTransform at = AffineTransform.getScaleInstance(-1d, 1d); at.translate(-w, 0); AffineTransformOp atOp = new AffineTransformOp(at, null); g.drawImage(atOp.filter(bufferedImage, null), 0, 0, w, h, this); } }
@Override public void paint(Graphics g) { LabyrintinLataus lab = peli.getLabyrintti(); for (int i = 0; i < lab.getKoko(); i++) { for (int j = 0; j < lab.getKoko(); j++) { if (lab.getRuutu(i, j).equals("seinä")) { g.drawImage(walltile, 20 * i, 20 * j, this); } else if (lab.getRuutu(i, j).equals("tyhjä")) { // piirretään floor tile // kohtaan 20*i,20*j // tai ehkä taustaväri toimii lattiana emt. } // muita tyyppejä lisätään...? } } g.drawImage(kohde, peli.getKohde().getX() * 20, peli.getKohde().getY() * 20, this); for (Haamu h : peli.getHaamut()) { String algo = h.getAlgo(); if (algo.equals("Astar")) { g.drawImage(astarHaamu, 20 * h.getX(), 20 * h.getY(), this); } else if (algo.equals("Random")) { g.drawImage(randomHaamu, 20 * h.getX(), 20 * h.getY(), this); } else if (algo.equals("Greedy")) { g.drawImage(greedyHaamu, 20 * h.getX(), 20 * h.getY(), this); } else if (algo.equals("Dijkstra")) { g.drawImage(dijkstraHaamu, 20 * h.getX(), 20 * h.getY(), this); } } this.setSize(20 * lab.getKoko(), 20 * lab.getKoko()); }
/** * Draw character in game window * * @param g Graphics * @param Dx X Displacement * @param Dy Y Displacement * @param G Growth factor */ public void Draw(Graphics g, int Dx, int Dy, double G) { // Draw blood if (ISDEAD) { g.drawImage( imgBLOOD, (int) (X + Dx - 25), (int) (Y + Dy - 15), (int) (W * GROWTHFACTOR + 35), (int) (H * GROWTHFACTOR + 35), null); } // Quest Givers if (CLASS != "Player") { for (int i = 0; i < QUEST_LIST.size(); i++) { if (QUEST_LIST.elementAt(i).STATUS == 0) { g.drawImage(imgQStart, (int) (X + Dx + 5), (int) (Y + Dy - 30), (int) W, 35, null); } else if (QUEST_LIST.elementAt(i).STATUS == 2) { g.drawImage(imgQEnd, (int) (X + Dx), (int) (Y + Dy - 30), (int) W + 5, 35, null); } } } // Draw character g.drawImage( imgCHARAC, (int) (X + Dx), (int) (Y + Dy), (int) (X + Dx + W * G), (int) (Y + Dy + H * G), (int) (W * FX), (int) (H * FY), (int) (W * FX + W), (int) (H * FY + H), null); GROWTHFACTOR = G; }
public void drawArrow(Graphics myBuffer, int time, Arrow arrow) { int x; int y = (int) ((arrow.startTime - time) * scaling); if (arrow instanceof LeftArrow) { x = 0; myBuffer.drawImage(leftArrowImg, x, y, null); } else if (arrow instanceof RightArrow) { x = 150; myBuffer.drawImage(rightArrowImg, x, y, null); } else if (arrow instanceof UpArrow) { x = 300; myBuffer.drawImage(upArrowImg, x, y, null); } else { x = 450; myBuffer.drawImage(downArrowImg, x, y, null); } // myBuffer.setColor(Color.black); // myBuffer.drawLine(0,0,x,y); // Image img = Toolkit.getDefaultToolkit().getImage("arrowB down.png"); myBuffer.finalize(); }
/** Scales an image. To be used for tiles. Probably not the most efficient scaling method. */ public static Image scaleImage(Image orig, int scale) { Image result; if (scale != 1) { int width = orig.getWidth(null); int height = orig.getHeight(null); // Scale cropped image to proper size result = new BufferedImage(width * scale, height * scale, BufferedImage.TYPE_INT_ARGB); Graphics g = ((BufferedImage) result).createGraphics(); g.drawImage(orig, 0, 0, width * scale, height * scale, 0, 0, width - 1, height - 1, null); g.dispose(); } else { return orig; } return result; }
public void paintComponent(Graphics g) { g.drawImage(image2, 0, 0, null); }
public void paintComponent(Graphics g) { g.drawImage(myImage, 0, 0, getWidth(), getHeight(), null); }
public void drawChar(Graphics g) { g.drawImage(character, x, y, xSize, ySize, null); // System.out.println(yLoc); }
@Override public void paintComponent(Graphics g) { g.drawImage(back, 0, 0, null); super.paintComponent(g); }
public void paint(Graphics g) { g.drawImage(myImage, 0, 0, this); }
public void paintComponent(Graphics g) { // 清屏 super.paintComponents(g); g.drawImage(im, 0, 0, this.getWidth(), this.getHeight(), this); }