protected synchronized void paintComponent(Graphics gc) { Dimension d = getSize(); gc.clearRect(0, 0, d.width, d.height); if (tmpChar[0] == 0) return; int charWidth = fm.charWidth(tmpChar[0]); gc.drawChars(tmpChar, 0, 1, curX++, fontHeight); }
public void paint(Graphics g) { if (loadflag && (!runflag)) { g.clearRect(0, 0, 530, 330); Graphics2D g2D = (Graphics2D) g; g2D.translate(0, 50); // 设置图像左上角为当前点 g.drawImage(iImage, 0, 0, null); // 画输入图 } }
/** Clear all contents */ public void clear() { if (gr == null) return; gr.clearRect(0, 0, getSize().width, getSize().height); repaint(); if (state != null) { synchronized (state) { state.clear(); } } }
public void paint(Graphics g) { if (iImage != null) { g.clearRect(0, 0, 260, 350); g.drawImage(iImage, 5, 50, null); g.drawString("pic1", 120, 320); } }
@Override protected void paintComponent(Graphics g) { g.clearRect(0, 0, getWidth(), getHeight()); g.setColor(Color.BLACK); g.drawRect(CELL_SIZE, CELL_SIZE, maze.width * CELL_SIZE, maze.height * CELL_SIZE); drawWalls(g, maze); boolean even = true; PathCell pathIt = path.first; while (pathIt != null) { even = !even; g.setColor(even ? Color.GREEN : Color.CYAN); g.fillRect( CELL_SIZE + pathIt.node.x * CELL_SIZE + 1, CELL_SIZE + pathIt.node.y * CELL_SIZE + 1, pathIt.node.width * CELL_SIZE - 1, pathIt.node.height * CELL_SIZE - 1); MazeNode door = pathIt.doorNode; g.setColor(Color.YELLOW); if (door != null) { if (door.division == Division.VERTICAL) { g.drawLine( CELL_SIZE + door.doorX * CELL_SIZE, CELL_SIZE + door.doorY * CELL_SIZE + 1, CELL_SIZE + door.doorX * CELL_SIZE, CELL_SIZE + (door.doorY + 1) * CELL_SIZE - 1); } else { g.drawLine( CELL_SIZE + door.doorX * CELL_SIZE + 1, CELL_SIZE + door.doorY * CELL_SIZE, CELL_SIZE + (door.doorX + 1) * CELL_SIZE - 1, CELL_SIZE + door.doorY * CELL_SIZE); } } pathIt = pathIt.next; } g.setColor(Color.ORANGE); g.fillRect( CELL_SIZE + sx * CELL_SIZE + 2, CELL_SIZE + sy * CELL_SIZE + 2, CELL_SIZE - 3, CELL_SIZE - 3); g.setColor(Color.RED); g.fillRect( CELL_SIZE + dx * CELL_SIZE + 2, CELL_SIZE + dy * CELL_SIZE + 2, CELL_SIZE - 3, CELL_SIZE - 3); }
public void paint(Graphics g) { System.out.println("paint"); Graphics2D g2d = (Graphics2D) g; Point1 p1, p2; n = paintInfo.size(); if (toolFlag == 2) g2d.clearRect(0, 0, getSize().width - 100, getSize().height - 100); // 清除 for (int i = 0; i < n - 1; i++) { p1 = (Point1) paintInfo.elementAt(i); p2 = (Point1) paintInfo.elementAt(i + 1); size = new BasicStroke(p1.boarder, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); g2d.setColor(p1.col); g2d.setStroke(size); if (p1.tool == p2.tool) { switch (p1.tool) { case 0: // 画笔 Line2D line1 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); g2d.draw(line1); break; case 1: // 橡皮 g.clearRect(p1.x, p1.y, p1.boarder, p1.boarder); break; case 3: // 画直线 Line2D line2 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); g2d.draw(line2); break; case 4: // 画圆 Ellipse2D ellipse = new Ellipse2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); g2d.draw(ellipse); break; case 5: // 画矩形 Rectangle2D rect = new Rectangle2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); g2d.draw(rect); break; case 6: // 截断,跳过 i = i + 1; break; default: } // end switch } // end if } // end for }
private void displayGameOver(Graphics g) { g.clearRect(100, 100, 350, 350); g.drawString("GAME OVER", 150, 150); String textScore = score.getStringScore(); String textHighScore = score.getStringHighScore(); String newHighScore = score.newHighScore(); g.drawString("SCORE = " + textScore, 150, 250); g.drawString("HIGH SCORE = " + textHighScore, 150, 300); g.drawString(newHighScore, 150, 400); g.drawString("press a key to play again", 150, 350); g.drawString("Press q to quit the game", 150, 400); }
public void paint(Graphics g) { g.clearRect(0, 25, width, height); int[] coords = new int[2]; for (int i = 0; i < map.charMap.size(); i++) { for (int j = 0; j < map.charMap.get(i).size(); j++) { if (map.charMap.get(i).get(j) == 'p' || map.charMap.get(i).get(j) == 'k') { coords[0] = i; coords[1] = j; } } } int antx = coords[0] - 14; int anty = coords[1] - 17; gress = tk.getImage(getClass().getResource("graphics/gress.jpg")); viking = tk.getImage(getClass().getResource("graphics/vikings.jpg")); village = tk.getImage(getClass().getResource("graphics/village.gif")); marked = tk.getImage(getClass().getResource("graphics/marked.gif")); bridge = tk.getImage(getClass().getResource("graphics/bridge.gif")); vikingOnBridge = tk.getImage(getClass().getResource("graphics/vikingOnBridge.gif")); tree = tk.getImage(getClass().getResource("graphics/tree.gif")); stone = tk.getImage(getClass().getResource("graphics/stone.gif")); destroyedVillage = tk.getImage(getClass().getResource("graphics/destroyedVillage.gif")); for (int i = 25, x = antx; i < height; i += 20, x++) { for (int j = 0, y = anty; j < width; j += 20, y++) { if (map.charMap.get(x).get(y) == 'p') g.drawImage(viking, j, i, this); else if (map.charMap.get(x).get(y) == 'k') g.drawImage(vikingOnBridge, j, i, this); else if (map.charMap.get(x).get(y) == 'g') g.drawImage(gress, j, i, this); else if (map.charMap.get(x).get(y) == 'l') g.drawImage(village, j, i, this); else if (map.charMap.get(x).get(y) == 'm') g.drawImage(marked, j, i, this); else if (map.charMap.get(x).get(y) == 't') g.drawImage(tree, j, i, this); else if (map.charMap.get(x).get(y) == 's') g.drawImage(stone, j, i, this); else if (map.charMap.get(x).get(y) == 'c') g.drawImage(bridge, j, i, this); else if (map.charMap.get(x).get(y) == '0') g.drawImage(destroyedVillage, j, i, this); else if (map.charMap.get(x).get(y) == 'v') { g.setColor(Color.blue); g.fillRect(j, i, 20, 20); g.setColor(Color.WHITE); } } } }
public void paintComponent(Graphics g) { // display if (isFirst) { myWidth = getWidth(); myHeight = getHeight(); define(); isFirst = false; } g.clearRect(0, 0, getWidth(), getHeight()); room.draw(g); // draw map store.draw(g); // draw sidebar // b.draw(g); theMinion.draw(g); if (to != null) { // tower selected movement to.draw(g, xval, yval, to); } for (Tower i : tplace) { i.draw(g, i); } }
private void displayGameGrid(Graphics g) { int maxX = SnakeGame.xPixelMaxDimension; int maxY = SnakeGame.yPixelMaxDimension; int squareSize = SnakeGame.squareSize; SnakeGame.snakeFrame.setBackground(Color.BLUE); g.clearRect(0, 0, maxX, maxY); g.setColor(Color.WHITE); // Draw grid - horizontal lines for (int y = 0; y <= maxY; y += squareSize) { g.drawLine(0, y, maxX, y); } // Draw grid - vertical lines for (int x = 0; x <= maxX; x += squareSize) { g.drawLine(x, 0, x, maxY); } }
public void paint(Graphics g) { // int numDoors=0; int rX = player.getRelativeX(); int rY = player.getRelativeY(); boolean notInBuilding = true; bufferGraphics.clearRect(0, 0, dim.width, dim.width); bufferGraphics.setColor(Color.WHITE); r2.setLocation(20 + rX, 20 + rY); // Iterator<Objects> iterator1 = entities.iterator();//size is the last index, therefore it // starts at the end // while(iterator1.hasNext()){ // iterator1.next().update(rX, rY); // bufferGraphics.drawImage(iterator1.next().image, iterator1.next().blockX+rX, // iterator1.next().blockX+rY, null); // } for (int x = 0; x < buildings.size(); x++) { buildings.get(x).update(rX, rY); player.onDoor(player.r, buildings.get(x).door); player.collideOn(player.r, buildings.get(x)); if (player.inHouse(player.r, buildings.get(x).inside)) { notInBuilding = false; } // if(notInBuilding){ // bufferGraphics.drawImage(buildings.get(x).image, // buildings.get(x).blockX+rX,buildings.get(x).blockY+rY, null); // }else{ // bufferGraphics.drawImage(buildings.get(x).innerImage, // buildings.get(x).blockX+rX,buildings.get(x).blockY+rY, null); // } // bufferGraphics.fillRect(entities.get(x).bounds.x, entities.get(x).bounds.y, // entities.get(x).bounds.width, entities.get(x).bounds.height); } bufferGraphics.setFont(new Font("Arial", Font.PLAIN, 20)); // String m1 = new Boolean(player.canMove('w')).toString(); bufferGraphics.drawString(message, 0, 170); // bufferGraphics.fillRect(r2.x, r2.y, r2.width, r2.height); // player.collideOn(player.r, r2); // ***Image log1 = new ImageIcon(getClass().getResource("logTest.png")).getImage(); // ***bufferGraphics.drawImage(log1, (int)r2.getX(), (int)r2.getY(), null); // bufferGraphics.drawLine((int)player.N.getX1(), (int)player.N.getY1(), (int)player.N.getX2(), // (int)player.N.getY2()); // bufferGraphics.drawLine((int)player.E.getX1(), (int)player.E.getY1(), (int)player.E.getX2(), // (int)player.E.getY2()); // bufferGraphics.drawLine((int)player.S.getX1(), (int)player.S.getY1(), (int)player.S.getX2(), // (int)player.S.getY2()); // bufferGraphics.drawLine((int)player.W.getX1(), (int)player.W.getY1(), (int)player.W.getX2(), // (int)player.W.getY2()); // bufferGraphics.setColor(Color.RED); // bufferGraphics.drawLine((int)player.NI.getX1(), (int)player.NI.getY1(), // (int)player.NI.getX2(), (int)player.NI.getY2()); // bufferGraphics.drawLine((int)player.EI.getX1(), (int)player.EI.getY1(), // (int)player.EI.getX2(), (int)player.EI.getY2()); // bufferGraphics.drawLine((int)player.SI.getX1(), (int)player.SI.getY1(), // (int)player.SI.getX2(), (int)player.SI.getY2()); // bufferGraphics.drawLine((int)player.WI.getX1(), (int)player.WI.getY1(), // (int)player.WI.getX2(), (int)player.WI.getY2()); if (notInBuilding) { Image thebg = new ImageIcon(getClass().getResource("grassbackingdev.png")).getImage(); bufferGraphics.drawImage(thebg, 0 + rX, 0 + rY, null); } player.update(); int setX = Math.abs(player.relativeX); int setY = Math.abs(player.relativeY); if (player.relativeX > 0) { setX = -setX; } if (player.relativeY > 0) { setY = -setY; } if (notInBuilding) { for (int x = 0; x < entities.size(); x++) { entities.get(x).update(rX, rY); bufferGraphics.drawImage( entities.get(x).image, entities.get(x).blockX + rX, entities.get(x).blockY + rY, null); player.collideOn(player.r, entities.get(x)); if (entities.get(x).health <= 0) { if (entities.get(x).material == "Wood") wood += entities.get(x).matsReturn; if (entities.get(x).material == "Stone") stone += entities.get(x).matsReturn; entities.remove(x); } // bufferGraphics.fillRect(entities.get(x).bounds.x, entities.get(x).bounds.y, // entities.get(x).bounds.width, entities.get(x).bounds.height); } } for (int x = 0; x < buildings.size(); x++) { if (notInBuilding) { bufferGraphics.drawImage( buildings.get(x).image, buildings.get(x).blockX + rX, buildings.get(x).blockY + rY, null); } else { bufferGraphics.drawImage( buildings.get(x).innerImage, buildings.get(x).blockX + rX, buildings.get(x).blockY + rY, null); } } if (notInBuilding) { for (int x = 0; x < npcArray.size(); x++) { for (int e = 0; e < entities.size(); e++) { npcArray.get(x).detectEntities(entities.get(e)); if (entities.get(e).health <= 0) { entities.remove(e); } } npcArray.get(x).update(rX, rY, setX + 92, setY + 82); bufferGraphics.drawImage( npcArray.get(x).graphic, npcArray.get(x).npcX + rX, npcArray.get(x).npcY + rY, null); if (npcArray.get(x).isDead()) { npcArray.remove(x); } else if (npcArray.get(x).hitBox.intersects(player.r)) { player.health -= 25; npcArray.remove(x); } } } for (int x = 0; x < playerAttack.size(); x++) { playerAttack.get(x).update(rX, rY); bufferGraphics.drawImage( playerAttack.get(x).graphic, playerAttack.get(x).currentX + rX, playerAttack.get(x).currentY + rY, null); for (int y = 0; y < npcArray.size(); y++) { if (playerAttack.get(x).hitBox.intersects(npcArray.get(y).hitBox)) { npcArray.get(y).health -= 25; playerAttack.get(x).hasHit = true; } } if (playerAttack.get(x).isDead()) { playerAttack.remove(x); } } player.notOnDoor = true; if (player.moving) { bufferGraphics.drawImage( player.getImage().getImage(), player.getCharx(), player.getChary(), null); // TODO } else { bufferGraphics.drawImage(player.getIdle(), player.getCharx(), player.getChary(), null); } if (Ghosting) { if (player.face == 1) { bufferGraphics.drawImage(player.getResource(resource), 104, 87, null); // EAST } if (player.face == 2) { bufferGraphics.drawImage(player.getResource(resource), 94, 106, null); // SOUTH*94,106 } if (player.face == 3) { bufferGraphics.drawImage(player.getResource(resource), 84, 87, null); // WEST84,87 } if (player.face == 4) { bufferGraphics.drawImage(player.getResource(resource), 94, 75, null); // NORTH94,75 } } if (player.health <= 0) { bufferGraphics.drawString("You are dead", 10, 90); stop(); } bufferGraphics.setFont(new Font("Arial", Font.PLAIN, 9)); bufferGraphics.setColor(new Color(160, 82, 45)); bufferGraphics.fillRect(0, 2, 8, 8); bufferGraphics.setColor(new Color(105, 105, 105)); bufferGraphics.fillRect(0, 12, 8, 8); bufferGraphics.drawImage(statusBar, 0, 22, null); bufferGraphics.setColor(Color.WHITE); bufferGraphics.drawString(String.format("%d", wood), 18, 10); bufferGraphics.drawString(String.format("%d", stone), 18, 20); bufferGraphics.drawString(String.format("%d", player.health), 18, 30); // bufferGraphics.fillRect((int)player.r.getX(), (int)player.r.getY(), // (int)player.r.getWidth(),(int)player.r.getHeight()); // bufferGraphics.fillRect(player.r.x, player.r.x, player.r.width, player.r.height); g.drawImage(offScreen, 0, 0, this); // if(drawConsole){ // message = String.format("wood: %d", wood); // } }
public void paint(Graphics g) // function that puts everything on the screen { Graphics2D scene = (Graphics2D) g; // Not really sure what this is. Blame Victor // use scene to draw the background scene.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.clearRect(0, 0, SCREENWIDTH, SCREENHEIGHT); // Clears the screen Font q = new Font( "Source Sans Pro", Font.PLAIN, 40); // Makes the font we use for options and story text g.setFont(q); // Sets the default font g.setColor(Color.white); if (state == 1) // Story text { drawTag(g); g.drawImage(textBox, 0, 0, null); // draw the story boxes Font n = new Font("Source Sans Pro", Font.BOLD, 48); // Makes the font for the names g.setFont(n); // Sets the name font scene.drawString(nameC, 53, 435); // Draws the current name g.setFont(q); // sets the quote font fm = g.getFontMetrics(); ArrayList<String> lines = new ArrayList<String>(); String line = ""; for (int i = 0; i < quoteC.length(); i++) { line += quoteC.charAt(i); if (fm.stringWidth(line) > 1180) { String lineCopy = line; line = line.substring(0, lineCopy.lastIndexOf(' ')); i -= lineCopy.length() - lineCopy.lastIndexOf(' ') - 1; lines.add(line); line = ""; } } lines.add(line); for (int i = 0; i < lines.size(); i++) { scene.drawString(lines.get(i), 40, 535 + 65 * i); } } else if (state == 2) // Draws the options { scene.drawImage(bg, screenShakeX, screenShakeY, null); scene.drawImage(obox, screenShakeX, screenShakeY, null); // options thing scene.drawString(options.get(0), 220, 255); scene.drawString(options.get(1), 220, 375); scene.drawString(options.get(2), 220, 495); } else if (state == 3) // Game is over { scene.drawImage(oldbg, screenShakeX, screenShakeY, null); float opacity = fadeCounter / FADETIMELIMIT; if (opacity > 1.0f) opacity = 1.0f; scene.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity)); scene.drawImage(bg, screenShakeX, screenShakeY, null); // draws the background image scene.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); scene.drawString("The end", 40, 520); // End screen } }
private void displayGameWon(Graphics g) { // TODO Replace this with something really special! g.clearRect(100, 100, 350, 350); g.drawString("YOU WON SNAKE!!!", 150, 150); }
public void update(Graphics g) { if (img == null) g.clearRect(0, 0, getSize().width, getSize().height); paintComponent(g); }
@Override protected void paintComponent(Graphics g) { g.clearRect(0, 0, getWidth(), getHeight()); if (bgY == 0) // if that checks when to restart the background bgY = -519; g.drawImage(background, 0, bgY++, this); // Draw the space ship, shots and objects if (Main.state == Main.STATE.GAME) { if (playerMove == 0) { g.drawImage(player, playerX, playerY, 40, 40, this); } if (playerMove == 1) { g.drawImage(playerRight, playerX, playerY, 40, 40, this); } if (playerMove == 2) { g.drawImage(playerLeft, playerX, playerY, 40, 40, this); } if (drops != null) { for (int[] cosordinates : drops) { g.setColor(Color.RED); if (coordinates[2] == 0 && Main.freezeOver) { g.drawImage(meteor, coordinates[0], coordinates[1], 30, 50, this); } if (coordinates[2] == 0 && !Main.freezeOver) { g.drawImage(iceMeteor, coordinates[0], coordinates[1], 30, 50, this); } if (coordinates[2] == 1) { g.drawImage(heart, coordinates[0], coordinates[1], 25, 25, this); } if (coordinates[2] == 2) { g.drawImage(ice, coordinates[0], coordinates[1], 25, 25, this); } if (coordinates[2] == 3) { g.drawImage(comet, coordinates[0], coordinates[1], 30, 50, this); } } } if (shots != null) { for (int[] coordinates : shots) { g.drawImage(shot, coordinates[0], coordinates[1], 10, 25, this); } } g.setColor(Color.WHITE); g.drawString("Score: " + Main.score, 235, 13); g.drawString("Lives: ", 10, 13); for (int i = 1; i <= lives; i++) { g.drawImage(heart, 20 * i, 13, 20, 20, this); } if (Main.score / 1500 > levels && Main.levelTimer < 500) { g.drawImage(level, 80, 215, this); Sound.playSound("res/sounds/level.wav", false, -5.0f); GameObjects.bonus = 40; Main.levelTimer += 10; } else if (Main.score / 1500 > levels) { if (Main.freezeOver) { Main.speed = levels / 2 + 5; levels = Main.score / 1000 + 2; Main.levelTimer = 0; } } } else if (Main.state == Main.STATE.GAMEOVER) { g.drawImage(end, 80, 205, this); g.setColor(Color.WHITE); g.drawString("Score: " + Main.score, 120, 245); g.drawString("Press [Esc] to return to Main Menu", 60, 310); } else if (Main.state == Main.STATE.MENU) { Font fnt = new Font("arial", Font.BOLD, 34); g.setFont(fnt); g.setColor(Color.white); g.drawImage(logo, 30, 35, this); fnt = new Font("arial", Font.BOLD, 23); g.setFont(fnt); if (option == 0) { g.setColor(new Color(173, 255, 47)); g.drawString("START", Main.fieldHeight / 2 - 135, 220); g.setColor(Color.WHITE); g.drawString("HIGHSCORES", Main.fieldHeight / 2 - 170, 270); g.drawString("QUIT", Main.fieldHeight / 2 - 120, 320); } if (option == 1) { g.drawString("START", Main.fieldHeight / 2 - 135, 220); g.setColor(new Color(173, 255, 47)); g.drawString("HIGHSCORES", Main.fieldHeight / 2 - 170, 270); g.setColor(Color.WHITE); g.drawString("QUIT", Main.fieldHeight / 2 - 120, 320); } if (option == 2) { g.drawString("START", Main.fieldHeight / 2 - 135, 220); g.drawString("HIGHSCORES", Main.fieldHeight / 2 - 170, 270); g.setColor(new Color(173, 255, 47)); g.drawString("QUIT", Main.fieldHeight / 2 - 120, 320); g.setColor(Color.WHITE); } } else if (Main.state == Main.STATE.HIGHSCORES) { Font fnt = new Font("arial", Font.BOLD, 24); g.setFont(fnt); g.setColor(Color.white); g.drawString("Highest score: " + Main.highestScore, Main.fieldWidth / 2 - 100, 100); } }
/** * Paint the drawing surface on the applet. * * @param g A graphics object */ public void paint(Graphics g) { buffG.clearRect(0, 0, getWidth(), getHeight()); canvas.paint(buffG); g.drawImage(buff, 0, 0, this); }