private Canvas createCanvas(final Graphics graphic, final Rectangle paintArea) { final int w = internalDisplaySize.getWidth(); final int h = internalDisplaySize.getHeight(); if (doubleBuffering) { if ((doubleBuffer == null) || (bufferGraphics == null) || (doubleBuffer.getWidth(null) < w) || (doubleBuffer.getHeight(null) < h)) { doubleBuffer = renderingArea.createImage(w, h); LOG.debug( "buffer sized to " + doubleBuffer.getWidth(null) + "x" + doubleBuffer.getHeight(null)); } bufferGraphics = doubleBuffer.getGraphics().create(); } else { bufferGraphics = graphic; } bufferGraphics.clearRect(paintArea.x, paintArea.y, paintArea.width, paintArea.height); bufferGraphics.clearRect(0, 0, w, h); bufferGraphics.setClip(paintArea.x, paintArea.y, paintArea.width, paintArea.height); final Canvas c = new AwtCanvas( bufferGraphics, renderingArea, paintArea.x, paintArea.y, paintArea.width, paintArea.height); // Canvas c = new Canvas(bufferGraphics, 0, 0, w, h); return c; }
/** Overrides <code>Graphics.clearRect</code>. */ public void clearRect(int x, int y, int width, int height) { DebugGraphicsInfo info = info(); if (debugLog()) { info().log(toShortString() + " Clearing rect: " + new Rectangle(x, y, width, height)); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.clearRect(x, y, width, height); debugGraphics.dispose(); } } else if (debugFlash()) { Color oldColor = getColor(); int i, count = (info.flashCount * 2) - 1; for (i = 0; i < count; i++) { graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor); graphics.clearRect(x, y, width, height); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } graphics.setColor(oldColor); } graphics.clearRect(x, y, width, height); }
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); }
/** * This component needs to be redisplayed. Copy the internal image to screen. (This method gets * called by the Swing screen painter every time it want this component displayed.) * * @param g The graphics context that can be used to draw on this component. */ public void paintComponent(Graphics g) { Dimension size = getSize(); g.clearRect(0, 0, size.width, size.height); if (panelImage != null) { g.drawImage(panelImage, 0, 0, null); } }
public void render() { // canvas bs = display.getCanvas().getBufferStrategy(); if (bs == null) { display.getCanvas().createBufferStrategy(3); return; } g = bs.getDrawGraphics(); // reset screen g.clearRect(0, 0, width, height); // draws background, player, wall try { imgBackground = ImageIO.read(new File("Background.PNG")); } catch (IOException e) { e.printStackTrace(); System.exit(1); } g.drawImage(imgBackground, 0, 0, null); g.setColor(Color.WHITE); g.setFont(new Font("Serif", Font.BOLD, 50)); // g.drawString("Score: " + getScore(), 100, 100); // displays image(buffered image) bs.show(); g.dispose(); }
public void paint2(Graphics g) { g.clearRect(0, 0, mySize.width, mySize.height); if (DEBUG) System.out.println("print"); if (focus) g.setColor(Color.black); else g.setColor(Color.gray); g.drawRect(0, 0, mySize.width - 1, mySize.height - 1); g.setClip(1, 1, mySize.width - 2, mySize.height - 2); g.setColor(Color.black); g.setFont(getFont()); fm = g.getFontMetrics(); lineAscent = fm.getAscent(); lineLeading = fm.getLeading(); lineHeight = lineAscent + fm.getDescent() + lineLeading; int y = yInset + lineAscent; String lastSubstring = ""; if (redoLines) fixLineStarts(mySize.width - xInset - xInset); for (int i = 0; i < lineCount; y += lineHeight, ++i) { // LIU: Don't display terminating ^M characters int lim = lineStarts[i + 1]; if (lim > 0 && contents.length() > 0 && contents.charAt(lim - 1) == CR) --lim; lastSubstring = contents.substring(lineStarts[i], lim); g.drawString(lastSubstring, xInset, y); } drawSelection(g, lastSubstring); lastHeight = y + yInset - lineHeight + yInset; lastWidth = mySize.width - xInset - xInset; }
public void draw() { Graphics g = environment.getScreenHandler().getCurrentGraphics(); g.clearRect( 0, 0, environment.getScreenHandler().getWidth(), environment.getScreenHandler().getHeight()); fps.update(); fps.draw(g, Color.red, 10, 10); g.setColor(Color.white); g.drawString(model.getInfoString(), 50, 10); g.setColor(Color.white); if (cheatMode) { g.setColor(Color.white); g.drawString("CHEATMODE", 80, 10); } g.setClip(cont.getOffsetX(), cont.getOffsetY(), cont.getDrawingSizeX(), cont.getDrawingSizeY()); if (model.isInitialized()) { model.getMap().draw(g, 0); model.getMyCar().draw(g, 0); CarDrawInterface cars[] = model.getOpponentCars(); for (int i = 0; i < cars.length; i++) { cars[i].draw(g, 0); } if (!model.isStarted()) { g.setColor(Color.white); g.clearRect(50, 50, 400, 150); g.drawString("Accellerate to start game", 100, 100); if (model.isMultiplayer()) { if (model.getNoOfHumanCars() > 1) { g.drawString( "Currently " + (model.getNoOfHumanCars() - 1) + " other human player(s) connected", 100, 120); } else { g.drawString("Only you and computer contolled cars are connected", 100, 120); } g.drawString("You can wait for more human players to connect", 100, 140); } } } else { g.setColor(Color.white); g.clearRect(50, 50, 400, 150); g.drawString("Loading game data, please wait...", 100, 100); } }
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); // 画输入图 } }
@Override public void paint(Graphics g) { if (state == GameState.Running) { // g.drawImage(background, bg1.getBgX(), bg1.getBgY(), this); // g.drawImage(background, bg2.getBgX(), bg2.getBgY(), this); // paintTiles(g); ArrayList projectiles = robot.getProjectiles(); for (int i = 0; i < projectiles.size(); i++) { Projectile p = (Projectile) projectiles.get(i); g.setColor(Color.BLACK); g.fillRect(p.getX(), p.getY(), 35, 2); } for (int i = 0; i < Ballon_Objects.size(); i++) { Ballon bb = Ballon_Objects.get(i); if (bb.isVisible == true) g.drawImage(ballonImage, bb.getCenterX() - 28, bb.getCenterY() - 35, this); else { Ballon_Objects.remove(i); } System.out.println("" + Ballon_Objects.size()); } for (int i = 0; i < Ballon_Bottom_Objects.size(); i++) { BallonBottom bottom = Ballon_Bottom_Objects.get(i); if (bottom.isVisible == true) g.drawImage(ballonBottomImage, bottom.getCenterX() - 10, bottom.getCenterY() + 13, this); else { Ballon_Bottom_Objects.remove(i); } System.out.println("BallonBottom:" + Ballon_Bottom_Objects.size()); } /*g.drawImage(character, robot.getCenterX() - 61, robot.getCenterY() - 63, this); */ g.drawImage(arrowRobot, robot.getCenterX() - 51, robot.getCenterY() - 50, this); g.drawImage(basket, myBasket.getCenterX() - 54, myBasket.getCenterY() - 20, this); /*g.drawImage(hanim.getImage(), hb.getCenterX() - 48, hb.getCenterY() - 48, this); g.drawImage(hanim.getImage(), hb2.getCenterX() - 48, hb2.getCenterY() - 48, this);*/ g.setFont(font); g.setColor(Color.BLACK); g.clearRect(10, 440, 90, 50); g.drawString("Basket : " + Integer.toString(basketScore / 24), 10, 440); g.drawString("Ballons: " + Integer.toString(ballonScore), 10, 470); } else if (state == GameState.Dead) { g.setColor(Color.BLACK); g.fillRect(0, 0, 800, 480); g.setColor(Color.WHITE); g.drawString("Dead", 360, 240); } }
@Override public void paint(Graphics g) { normalFont = g.getFont(); smallFont = new Font(normalFont.getName(), normalFont.getStyle(), normalFont.getSize() - 1); g.setColor(Color.DARK_GRAY); g.clearRect(0, Ybottom, totalX, 200); g.fillRect(Xleft - 5, Ytop, totalX + 10, totalY + 32); drawGraph(g); }
public void cleanCanvas(Graphics gg) { int cleanX = Constants.CANVAS_MARGIN_WIDTH + 5; int cleanY = Constants.CANVAS_MARGIN_HEIGHT + 5; gg.clearRect( cleanX, cleanY, Constants.CANVAS_WIDTH + Constants.CANVAS_MARGIN_WIDTH, Constants.CANVAS_HEIGHT - 10); }
public void paint(Graphics g) { int windowWidth = this.dimensions.width * this.scale; int windowHeight = this.dimensions.height * this.scale; g.clearRect(0, 0, windowWidth, windowHeight); for (Agent agent : this.agentList) agent.drawIt(g, this.scale); }
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); } }
public void init() { Graphics g = getGraphics(); Rectangle b = getBounds(); g.clearRect(0, 0, b.width, b.height); // last_data_pos = ((NslVariable)variable_list.elementAt(0)).last_data_pos; // data = ((NslVariable)variable_list.elementAt(0)).data; paint(g); // draw_time = -1; }
/** 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) { Graphics2D g2d = (Graphics2D) g; if (is) { if (true) { g.clearRect(0, 0, getSize().width, getSize().height); } } if (flagtool == 2) { // 清除 g.clearRect(0, 0, getSize().width, getSize().height); } for (int i = 0; i < points.size() - 1; i++) { p1 = (onePoint) points.elementAt(i); p2 = (onePoint) points.elementAt(i + 1); g2d.setColor(p1.c); // ////////////需要使用Graphics2D从Graphics类中继承下来的方法 setColor()设置当前的颜色 size = new BasicStroke(p1.border, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND); g2d.setStroke(size); if (p1.tool == p2.tool) { switch (p1.tool) { case 0: Line2D.Double line1 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); g2d.draw(line1); break; case 1: Line2D.Double line2 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); g2d.draw(line2); break; case 3: Ellipse2D.Double 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 4: Rectangle2D.Double rect = new Rectangle2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); g2d.draw(rect); break; default: } } } }
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 }
@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); }
/** repaint */ private void paintWorld(Graphics g) { g.clearRect(0, 0, getWidth(), getHeight()); g.setColor(backGround); g.fillRect(0, 0, getWidth(), getHeight()); // sort before repaint Collections.sort(renders, comparatorDeep); for (IRenderToConvas render : renders) { render.render(g); } }
public void run() { try { ball = new Ball(10, 500, 660, -1, -1, Color.white); ship = new Ship(500, 685, 120, 30, Color.cyan); wall.fillBockList(); wall.blockListUpdatepoints(); // sound.soundtrack(); margin(); while (true) { System.out.println(min); // playMusic(); try { // System.out.println("\n"); // graphDB.fillRect(0,0, width, height); graphDB.clearRect(26, 47, getWidth() - 326, getHeight() - 72); // CRASHES verifyCrashes(); // borderCrash(ball); // ship.shipCrash(ball); // wall.blockListCrashes(ball); // UPDATE ELEMENTS wall.blockListKill(ship); ball.wayCalculator(); wall.boomListUpdate(); ship.move(); ship.updateGuns(); ship.updatePoints(); // save ship points // PAINT ELEMENTS ship.paintAllGuns(graphDB); ship.paintShip(graphDB); ball.paintBall(graphDB, ball.getRadio(), ball.getXC(), ball.getYC()); wall.paintBlockList(graphDB); // --wall.painBlockMaze(graphDB); // efects wall.boomEfect(graphDB); repaint(); sleep(5); } catch (InterruptedException ex) { System.out.println("there is a error in the while.....!!!!"); } } } catch (Exception e) { System.out.println("there is a error!!!!"); } }
public void paintComponent(Graphics frontBuffer) { // Clear the back buffer backBuffer.clearRect(this.getX(), this.getY(), this.getWidth(), this.getHeight()); // Draw all objects to the back buffer in order from back-to-front paintBackground(); paintEntities(); // Draw the back buffer onto the front buffer all at once to avoid flickering from repeated draw // commands frontBuffer.drawImage(backBufferImage, this.getX(), this.getY(), this); }
private void paintSections(Graphics g) { int rmin, rmax, rh = table.getRowHeight(); MatchTableModel model = (MatchTableModel) table.getModel(); g.getClipBounds(srect); spoint.setLocation(0, srect.y); rmin = table.rowAtPoint(spoint); if (rmin < 0) rmin = 0; spoint.setLocation(0, srect.y + srect.height); rmax = table.rowAtPoint(spoint); if (rmax < 0) rmax = table.getRowCount() - 1; for (int i = rmin; i <= rmax; i++) { if (model.isRowHeader(i)) { if (model.isRowHeader2(i)) { g.clearRect(0, rh * i, table.getWidth(), rh - 1); g.drawString( model.getDescription(i), 1, rh * i + table.getFontMetrics(table.getFont()).getAscent()); } else g.clearRect(0, rh * i, table.getWidth(), rh * 2 - 1); } } }
/** * Called to recursively paint the check box for the specified item. * * @param item row number * @param g graphics object to paint. * @param bookmark to check selected value. * @return the next row number to paint. */ public int paintCheckbox(final int item, final Graphics g, final Bookmark bookmark) { int nextItem = item + 1; if (bookmark != null) { final Rectangle checkboxBounds = getCheckboxBounds(item, bookmark, getDepthMap().get(bookmark)); final int yCheckboxMidPoint = checkboxBounds.y + (checkboxBounds.height / 2); final int xCheckboxMidPoint = checkboxBounds.x + (checkboxBounds.width / 2); final Enumeration e = bookmark.elements(); if (e.hasMoreElements()) { // clear any lines crossing through the checkbox. g.clearRect( checkboxBounds.x, checkboxBounds.y, checkboxBounds.width, checkboxBounds.height); // draw box around checkbox g.drawRect(checkboxBounds.x, checkboxBounds.y, checkboxBounds.width, checkboxBounds.height); // draw dash inside checkbox g.drawLine( checkboxBounds.x + 2, yCheckboxMidPoint, (checkboxBounds.x + checkboxBounds.width) - 2, yCheckboxMidPoint); boolean drawPlus = true; do { final Bookmark child = (Bookmark) e.nextElement(); final Bookmark next = getBookmark(nextItem); if (child != next) { break; } drawPlus = false; nextItem = paintCheckbox(nextItem, g, child); } while (e.hasMoreElements()); if (drawPlus) { g.drawLine( xCheckboxMidPoint, checkboxBounds.y + 2, xCheckboxMidPoint, (checkboxBounds.y + checkboxBounds.height) - 2); } } } return nextItem; }
@Override public void paintComponent(Graphics g) { g.clearRect(0, 0, this.getWidth(), this.getHeight()); int cc = 150 / this.titleSize; for (int i = 0; i < Animation.getInstance().getTileSetsCount(); i++) { g.setColor(Color.WHITE); g.fillRect(i * viewSize.width, titleSize, viewSize.width - 1, viewSize.height - 1); g.setColor(Color.LIGHT_GRAY); for (int y = titleSize / 8; y < (titleSize + viewSize.height) / 8; y++) { for (int x = i * viewSize.width / 8; x < (i + 1) * viewSize.width / 8; x++) { if ((y + x) % 2 == 1) { g.fillRect(x * 8, y * 8, 8, 8); } } } Animation.getInstance() .getTileSet(i) .paintPreview( g, i * this.viewSize.width + 2, this.titleSize + 2, this.viewSize.width - 4); Color labelColor = Color.BLACK; if (this.selectedIndex == i) { labelColor = Color.BLUE; } for (int j = 0; j < this.titleSize; j++) { g.setColor( new Color( labelColor.getRed(), labelColor.getGreen(), labelColor.getBlue(), 105 + j * cc)); g.drawLine( i * this.viewSize.width, j + 1, i * this.viewSize.width + this.viewSize.width - this.titleSize + j, j + 1); } if (this.selectedIndex == i) { g.setColor(Color.BLUE); } else { g.setColor(Color.BLACK); } g.draw3DRect( i * (this.viewSize.width), this.titleSize, this.viewSize.width - 1, this.viewSize.height - 1, true); g.setColor(Color.WHITE); g.drawString( Animation.getInstance().getTileSet(i).getName(), i * (this.viewSize.width) + 2, this.titleSize - 2); } }
@Override public void paint(Graphics g) { g.clearRect(0, 0, 1500, 200); g.setColor(Color.BLACK); Font font2 = new Font("TimesRoman", Font.PLAIN, 15); // $NON-NLS-1$ g.setFont(font2); g.drawString(name, 1, 25); // g.fillRect(x, y, rectWidth, rectHeight); g.drawString(children, 1, 48); g.drawString(numberOfAlloc, 250, 48); g.drawString(numberOfCapture, 1, 70); g.drawString(numberOfTypes, 250, 70); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(Color.gray); Metric colorMetric = scene.getColorMetric(); Color minColor = scene.getPreferences().getMinColor(colorMetric); Color maxColor = scene.getPreferences().getMaxColor(colorMetric); this.maxSelectedValue = this.canvas.getScene().getMaxColorValue(); this.maxValue = colorMetric.getMaxValue(); if (this.maxSelectedValue >= 0 && this.maxValue > 0) { int width = maxSelectedValue * 250 / maxValue; GradientPaint gradient = new GradientPaint(x, y, minColor, x + width, y, maxColor); if (maxSelectedValue > 0) { g2.setPaint(gradient); } else { g2.setPaint(maxColor); } g2.fill(new Rectangle2D.Double(x, y, rectWidth, rectHeight)); g2.setPaint(Color.black); g2.drawLine(x, y - 3, x, y + rectHeight + 3); g2.drawLine(x + width, y - 3, x + width, y + rectHeight + 3); g2.drawLine(x + rectWidth, y - 3, x + rectWidth, y + rectHeight + 3); g2.setFont(new Font("TimesRoman", Font.PLAIN, 10)); // $NON-NLS-1$ g2.drawString("0", x - 5, 77); // $NON-NLS-1$ g2.drawString("" + maxSelectedValue, x + width - 2, 40); // $NON-NLS-1$ g2.drawString("" + maxValue, x + rectWidth, 77); // $NON-NLS-1$ } }
protected void paintComponent(Graphics g) { super.paintComponents(g); configureFormatter(); double lineDistance = getLineDistance(); Rectangle clip = g.getClipBounds(); g.clearRect(clip.x, clip.y, clip.width, clip.height); g.setColor(Color.black); if (isVertical()) { double halfLineDistance = lineDistance / 2.0d; for (double line = (double) getHeight() - (minUnit % lineDistance); line > 0; line -= lineDistance) { g.drawLine(0, (int) line, getWidth(), (int) line); } for (double line = (double) getHeight() - ((minUnit - halfLineDistance) % lineDistance); line > 0; line -= lineDistance) { int inset = 3; g.drawLine(inset, (int) line, getWidth() - inset, (int) line); } String number = null; for (double line = (double) getHeight() - (minUnit % lineDistance); line > 0; line -= lineDistance) { g.setFont(font); String newNumber = format((getHeight() - line) / getPixelsPerUnit()) + getUnitName(); if (!newNumber.equals(number)) g.drawString(newNumber, 2, (int) line - 2); number = newNumber; } } else { double halfLineDistance = lineDistance / 2.0d; for (double line = (minUnit % lineDistance); line < getWidth(); line += lineDistance) { g.drawLine((int) line, 0, (int) line, getHeight()); } for (double line = (minUnit - halfLineDistance) % lineDistance; line < getWidth(); line += lineDistance) { int inset = 3; g.drawLine((int) line, inset, (int) line, getHeight() - inset); } String number = null; for (double line = (minUnit % lineDistance); line < getWidth(); line += lineDistance) { // for (double line = unitStart; line < unitEnd; line += lineDistance) { g.setFont(font); String newNumber = format(line / getPixelsPerUnit()) + getUnitName(); if (!newNumber.equals(number)) g.drawString(newNumber, ((int) line) + 3, getHeight() - 2); number = newNumber; } } }
public void paintComponent(Graphics g) { g.clearRect(0, 0, getWidth(), getHeight()); g.setFont(new Font("TimesRoman", Font.PLAIN, 30)); if (f == Feedback.positive) { g.setColor(Color.green); g.drawString("POSITIVE", 35, 100); } else if (f == Feedback.negative) { g.setColor(Color.red); g.drawString("NEGATIVE", 25, 100); } /* else{ g.drawString("other key" , 20, 100); }*/ }
public void update(Graphics g) { Dimension newSize = getSize(); if (size.equals(newSize)) { // Erase old box g.setColor(getBackground()); g.drawRect(mx, my, (size.width / 10) - 1, (size.height / 10) - 1); } else { size = newSize; g.clearRect(0, 0, size.width, size.height); } // Calculate new position mx = (int) (Math.random() * 1000) % (size.width - (size.width / 10)); my = (int) (Math.random() * 1000) % (size.height - (size.height / 10)); paint(g); }
/** JPanel rendering method that displays all the shapes */ public void paint(Graphics g) { int top = 0; int bottom = getArrowHeight(); int center = (int) (imageWidth * ((double) getValue() / 255.0)) + arrowWidth / 2; int left = center - arrowWidth / 2; int right = center + arrowWidth / 2; Polygon p = new Polygon(); p.addPoint(left, top); p.addPoint(right, top); p.addPoint(center, bottom); g.clearRect(0, 0, imageWidth + arrowWidth, imageHeight + getArrowHeight()); g.setColor(Color.black); g.fillPolygon(p); g.drawImage(img, arrowWidth / 2, getArrowHeight(), null); }
@Override protected void paintComponent(Graphics g) { g.clearRect(0, 0, getWidth(), getHeight()); double fraction = visitTime / tau; int boxHeight = (int) (getHeight() * fraction); g.setColor(Color.lightGray); g.fillRect(0, getHeight() - boxHeight, getWidth(), boxHeight); g.setColor(Color.black); g.drawRect(0, 0, getWidth() - 1, getHeight() - 1); setOpaque(false); super.paintComponent(g); setOpaque(true); }