@Override public void paintComponent(Graphics g) { super.paintComponent(g); setBackground(CANVAS_BACKGROUND); g.setColor(LINE_COLOR); g.fillOval(x, y, size, size); // draw the ball }
// färger, se sid 43 i boken // grafiska metoder, sid 248 i boken public void paintComponent(Graphics g) { // för att vara säker på att // "super"-klassen gör sitt // anropar vi den metoden, innan // vi skriver eller ritar super.paintComponent(g); g.drawLine(185, 10, 195, 40); // x1,y1 till x2,y2 g.drawLine(200, 10, 200, 40); g.drawLine(215, 10, 205, 40); g.setColor(Color.white); g.fillOval(50, 30, 300, 150); // x,y,b,h (x,y för ö v h) g.setColor(Color.red); g.drawArc(100, 100, 200, 50, 180, 180); // x,y,b,h,s,l g.setColor(Color.yellow); g.fillRect(200, 100, 30, 30); g.fill3DRect(150, 50, 30, 50, true); // true upphöjd figur g.fill3DRect(250, 50, 30, 50, true); // skriv ut en textsträng, samt ange läget i avståndet från // övre vänstra hörnet i x-led åt höger och i y-led neråt g.drawString("** Tjenare kompis !! **", 20, 20); f = new Font("Arial", Font.BOLD, 30); setBackground(Color.cyan); g.setFont(f); g.setColor(new Color(255, 175, 175)); g.drawString("YEEEEEEEES!!", 100, 250); }
@Override // TODO Auto-generated method stub public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; // Draws the two initial two YinYang symbols on the frame g2.setColor(color1); if (timeLeft < 6000) { g2.rotate(degrees, yin1X + (yin1Width / 2), yin1Y + (yin1Height / 2)); } g2.fill(new MyYinYang(yin1X, yin1Y, yin1Width, yin1Height)); if (timeLeft < 6000) { g2.rotate(-degrees, yin1X + (yin1Width / 2), yin1Y + (yin1Height / 2)); } g2.setColor(color2); if (timeLeft < 6000) { g2.rotate(degrees, yin2X + (yin2Width / 2), yin2Y + (yin2Height / 2)); } g2.fill(new MyYinYang(yin2X, yin2Y, yin2Width, yin2Height)); if (timeLeft < 6000) { g2.rotate(-degrees, yin2X + (yin2Width / 2), yin2Y + (yin2Height / 2)); } // Alters and prints the text on the screen g2.setColor(Color.BLACK); g2.setFont(font); g2.drawString("Score", 700, 25); g2.drawString(Integer.toString(points), 700, 75); g2.drawString("Misses", 800, 25); g2.drawString(Integer.toString(misses), 800, 75); g2.drawString("Time Left", 700, 110); timeDisplay = timeLeft / 100.0; g2.drawString(timeDisplay.toString(), 700, 160); }
public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(kleur); g.fillRoundRect(5, 5, 70, 70, 10, 10); g.setColor(Color.black); if (waarde == 1) { g.fillOval(34, 34, 10, 10); } else if (waarde == 2) { g.fillOval(10, 10, 10, 10); g.fillOval(60, 60, 10, 10); } else if (waarde == 3) { g.fillOval(10, 10, 10, 10); g.fillOval(34, 34, 10, 10); g.fillOval(60, 60, 10, 10); } else if (waarde == 4) { g.fillOval(10, 10, 10, 10); g.fillOval(10, 60, 10, 10); g.fillOval(60, 10, 10, 10); g.fillOval(60, 60, 10, 10); } else if (waarde == 5) { g.fillOval(10, 10, 10, 10); g.fillOval(10, 60, 10, 10); g.fillOval(60, 10, 10, 10); g.fillOval(60, 60, 10, 10); g.fillOval(34, 34, 10, 10); } else if (waarde == 6) { g.fillOval(10, 10, 10, 10); g.fillOval(10, 60, 10, 10); g.fillOval(60, 10, 10, 10); g.fillOval(60, 60, 10, 10); g.fillOval(10, 34, 10, 10); g.fillOval(60, 34, 10, 10); } else ; // meer waarden zijn er niet }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); // Display root displayTree(g, tree.getRoot(), getWidth() / 2, 30, getWidth() / 4); }
protected void paintComponent(Graphics g2) { super.paintComponent(g2); Graphics2D g = (Graphics2D) g2; test.draw(g2, 0, 0); // Shape triangle = new Polygon(new int[] {15, 20, 10}, new int[] {0, 10, 10}, 3); Shape square = new Rectangle2D.Double(0, 0, 30, 30); g.setColor(Color.white); g.translate(20, 20); // g.rotate(theta, 10, 10); // g.fill(star); // g.setColor(new Color(0, 86, 141)); // g.fill(square); if (star2 != null) g.fill(star2); // Graphics2D g3 = (Graphics2D) g; // 3.fill(star); // g.setStroke(new BasicStroke(1)); // g.translate(x, y); // g.draw(line); // g.draw(line2); }
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); } }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; this.quadriller(g2d); this.placerPostes(g2d); this.tracerVisualisations(g2d); }
public void paintComponent(Graphics g) { super.paintComponent(g); this.setBackground(Color.black); // Nested for loop to draw all rows and columns for (int x = 0; x < num.tileRow; x++) { for (int y = 0; y < num.tileCol; y++) { if (land.xTile[x][y].isDiscovered) { g.setColor(land.xTile[x][y].locColor); } else { g.setColor(Color.black); } g.fillRect( (land.xTile[x][y].xPos + num.xOff) * num.zoom, (land.xTile[x][y].yPos + num.yOff) * num.zoom, num.tileSq * num.zoom, num.tileSq * num.zoom); } } // Code to draw and animate player g.setColor(Color.red); g.fillRect( num.tileSq * num.zoom * num.tileSq, num.tileSq * num.zoom * num.tileSq, num.tileSq * num.zoom, num.tileSq * num.zoom); g.setColor(Color.white); g.fillRect(num.tileCol * 5 - 50, 0, 150, num.tileRow * 5 + 15); g.setColor(Color.black); g.fillRect(num.tileCol * 5 - 50, 0, 10, num.tileRow * 5 + 15); }
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); } }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D gfx = (Graphics2D) g; gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Clear screen gfx.setColor(Constants.BACKGROUND_COLOR); gfx.fillRect(0, 0, getWidth(), getHeight()); // Render next frame grid.draw(gfx); // Trace path line if (tracing) { gfx.setColor(Constants.PATH_COLOR); gfx.setStroke(new BasicStroke(2)); for (int i = 1; i < pathLine.size(); i++) { Coordinate p = pathLine.get(i - 1); Coordinate n = pathLine.get(i); gfx.drawLine( (Constants.TILESIZE + Constants.MARGIN) * p.x + (Constants.TILESIZE / 2) + Constants.MARGIN, (Constants.TILESIZE + Constants.MARGIN) * p.y + (Constants.TILESIZE / 2) + Constants.MARGIN, (Constants.TILESIZE + Constants.MARGIN) * n.x + (Constants.TILESIZE / 2) + Constants.MARGIN, (Constants.TILESIZE + Constants.MARGIN) * n.y + (Constants.TILESIZE / 2) + Constants.MARGIN); } } }
public void paintComponent(Graphics page) { super.paintComponent(page); Image icon = this.getToolkit().getImage("chess1.jpg"); page.drawImage(icon, -40, 20, this); setOpaque(false); }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (UIUtil.isUnderDarcula() && false) { // todo[kb] fix DarculaTextBorder g.setColor(myTextField.getBackground()); g.fillRect(2, 3, getWidth(), getHeight() - 5); } }
// paints the player, items, and rooms public void paintComponent(Graphics g) { super.paintComponent(g); Environment Layout = new Environment(); Layout.drawRoom(mapX, mapY, g); Player PlayerSprite = new Player(); PlayerSprite.drawPlayer(x, y, g); Layout.items(x, y, g, getItem); }
/** Paint the node preview widget */ public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.gray); g.drawRect(0, 0, this.getBounds().width - 1, this.getBounds().height - 1); if (this.node != null) this.node.paint(g); }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); for (int x = 0; x < 255; x++) { g.setColor(new Color(x, 0, 255 - x)); g.fillRect(x, 10, 1, 100); } }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.RED); g2d.fill(ball); // System.out.println("Calling fill()"); }
/** 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!"); } }
// documentation inherited public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; // center the tile display if we are bigger than we need to be g.translate(_tx, _ty); // // paint coordinates in the grid that contains our tiles // for (int yy = 0; yy < _height; yy++) { // for (int xx = 0; xx < _width; xx++) { // int cx = xx*TILE_WIDTH, cy = yy*TILE_HEIGHT; // g.drawRect(cx, cy, TILE_WIDTH, TILE_HEIGHT); // String coord = (xx-_origX) + "/" + (yy-_origY); // g.drawString(coord, cx+TILE_WIDTH/2, cy+TILE_HEIGHT/2); // } // } // iterate over our tiles, painting each of them for (AtlantiTile tile : _tiles) { tile.paint(g2, _origX, _origY); } // if we have a placing tile, draw that one as well if (_placingTile != null && _validPlacement) { // if the current position is valid, draw the placing tile _placingTile.paint(g2, _origX, _origY); // draw a green rectangle around the placing tile g.setColor(Color.blue); int sx = (_placingTile.x + _origX) * TILE_WIDTH; int sy = (_placingTile.y + _origY) * TILE_HEIGHT; g.drawRect(sx, sy, TILE_WIDTH - 1, TILE_HEIGHT - 1); } // if we have a recently placed tile, draw that one as well if (_placedTile != null) { // draw the tile _placedTile.paint(g2, _origX, _origY); // draw a white rectangle around the placed tile g.setColor(Color.white); int sx = (_placedTile.x + _origX) * TILE_WIDTH; int sy = (_placedTile.y + _origY) * TILE_HEIGHT; g.drawRect(sx, sy, TILE_WIDTH - 1, TILE_HEIGHT - 1); } // draw a white rectangle around the last placed if (_lastPlacedTile != null) { g.setColor(Color.white); int sx = (_lastPlacedTile.x + _origX) * TILE_WIDTH; int sy = (_lastPlacedTile.y + _origY) * TILE_HEIGHT; g.drawRect(sx, sy, TILE_WIDTH - 1, TILE_HEIGHT - 1); } // undo our translations g.translate(-_tx, -_ty); }
// ------------------------------------------------------------------------------- // Create Background Image // ------------------------------------------------------------------------------- public void paintComponent(Graphics g) { /*Create image icon to get image*/ ImageIcon icon = new ImageIcon(getClass().getResource(imageFile)); Image image = icon.getImage(); /*Draw image on the panel*/ super.paintComponent(g); if (image != null) g.drawImage(image, 0, 0, getWidth(), getHeight(), this); }
public void paintComponent(Graphics g) { super.paintComponent(g); while (true) { teller++; slaap(1000); label.setText("" + teller); } }
@Override public void paintComponent(Graphics g) { if (selected) { g.setColor(selColor); g.fillRoundRect(0, 0, getWidth(), getHeight(), getWidth() / 10, getHeight() / 10); label.setForeground(Color.YELLOW); } else label.setForeground(Color.WHITE); super.paintComponent(g); }
/* 연결선 그리기 */ @Override protected void paintComponent(Graphics g) { super.paintComponent(g); for (Line link : links) { g.drawLine(link.p1.x, link.p1.y, link.p2.x, link.p2.y); } repaint(); }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = ((Graphics2D) g); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); g2d.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); g2d.setRenderingHint( RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED); g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE); g2d.setColor(Color.BLACK); g2d.fillRect(0, 0, getWidth(), getHeight()); if (bufferedImage != null) { synchronized (LOCKER) { g2d.drawImage(bufferedImage, transformCells, null); } } // draw struct preview if (structurePreview != null) { Composite composite = g2d.getComposite(); g2d.setComposite(compositeStructPreview); g2d.drawImage(structurePreview, previewTransform, null); g2d.setComposite(composite); } // draw grid if (transformCells.getScaleX() > SHOW_GRID_MIN_SCALE) { Composite composite = g2d.getComposite(); g2d.setComposite(compositeGrid); g2d.drawImage(bufferedImageGrid, transformGrid, null); g2d.setComposite(composite); } // draw border for preview if (structurePreview != null && Math.abs(transformCells.getScaleX()) >= 0.95) { Shape shape = new Rectangle(0, 0, structurePreview.getWidth(), structurePreview.getHeight()); shape = previewTransform.createTransformedShape(shape); g2d.setColor(Color.RED); g2d.draw(shape); } // draw border double x = transformCells.getTranslateX(); double y = transformCells.getTranslateY(); g2d.setColor(BORDER_COLOR); g2d.setStroke(new BasicStroke(BORDER_WIDTH)); g2d.drawRect( round(x - BORDER_WIDTH), round(y - BORDER_WIDTH), round(getAutomatonWidth() * transformCells.getScaleX() + 2 * BORDER_WIDTH), round(getAutomatonHeight() * transformCells.getScaleY() + 2 * BORDER_WIDTH)); }
protected void paintComponent(Graphics g) { super.paintComponent(g); // Select three points in proportion to the panel size Point p1 = new Point(getWidth() / 2, 10); Point p2 = new Point(10, getHeight() - 10); Point p3 = new Point(getWidth() - 10, getHeight() - 10); displayTriangles(g, order, p1, p2, p3); }
// Repaint the message at the new location public void paintComponent(Graphics page) { // use paintComponent method of its parent class // to have all graphics properties super.paintComponent(page); // change the page color and font page.setColor(Color.cyan); page.setFont(new Font("TimesRoman", Font.PLAIN, 24)); page.drawString(message.getText(), (int) (location.getX()), (int) (location.getY())); }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; int i, j, k; System.out.println("Starting painting"); // draw sets if (firstTimeAround) { drawSet(g2); render(); viewer.save("final_product_full.png"); firstTimeAround = false; } // render(); /* for(i=0;i<viewer.getWidth();i++){ for(j=0;j<viewer.getHeight();j++){ viewer.setPixel(i,j,Color3.BLACK); } } */ g2.setBackground(Color.BLACK); // if(newRender){ for (i = minX; i < maxX; i++) { // System.out.println("line "+i); for (j = minY; j < maxY; j++) { g2.setColor( new Color( (float) viewer.getPixel(i, j).getR(), (float) viewer.getPixel(i, j).getG(), (float) viewer.getPixel(i, j).getB())); // g2.drawLine(i,j,1,1); Ellipse2D.Double node_circ = new Ellipse2D.Double(i, j, 1, 1); g2.fill(node_circ); g2.setColor(Color.BLACK); // if(j*scale<viewer.getHeight()){ // j=0;//viewer.getHeight(); // } } // if(i*scale<viewer.getWidth()){ // i=0;//viewer.getWidth(); // } } // g2.drawImage(viewer.1) newRender = false; // } System.out.println("end painting"); }
public void paintComponent(Graphics g) { super.paintComponent(g); for (int i = 0; i < box.length; i++) { for (int j = 0; j < box[0].length; j++) { box[i][j].drawBackGroundSquare(g); box[i][j].drawSpecialSquare(g); } } drawSpecialLines(g); }
public void paintComponent(Graphics g) { // paintComponent super.paintComponent(g); // refresh screen (paint background) Font f = new Font("Helvetica", Font.BOLD, 40); g.setFont(f); g.drawString("DON'T ABUSE", 40, 130); g.drawString("SUBSTANCES", 40, 180); f = new Font("Helvetica", Font.BOLD, 50); g.setFont(f); g.drawString("KIDS", 120, 240); }
// draws the current snapshot public void paintComponent(Graphics g) { // System.out.println("In paint in draw"); super.paintComponent(g); my_width = getSize().width; my_height = getSize().height; if (my_image != null) g.drawImage(my_image, 0, 0, my_width, my_height, this); setBackground(new Color(1.0f, 1.0f, 1.0f)); // g.setColor(Color.black); // g.drawRect(0,0,my_width-1,my_height-1); }