public void paintComponent(Graphics g) { super.paintComponent(g); calcSizes(); drawAxes(g); calcMaxes(); calcTickIncrements(); drawXTicks(g); drawYTicks(g); int t = 0; int prevX = 0, prevY1 = 0, prevY2 = 0; for (DataPair pair : data) { int h = pair.getH(); int p = pair.getP(); // calculate where to put the dots int x = xVal(t, maxT); int y1 = yVal(h, maxH); int y2 = yVal(p, maxP); // draw herbivore dot g.setColor(Color.BLUE); g.fillOval(x, y1, 2 * r, 2 * r); // draw a line connecting this dot to the last if (prevX != 0) { g.drawLine(prevX + r, prevY1 + r, x + r, y1 + r); } // draw predator dot g.setColor(Color.RED); g.fillOval(x, y2, 2 * r, 2 * r); // draw a line connecting this dot to the last if (prevX != 0) { g.drawLine(prevX + r, prevY2 + r, x + r, y2 + r); } // remember these dots prevX = x; prevY1 = y1; prevY2 = y2; g.setColor(Color.BLACK); t++; } }
public void draw(Graphics window, int x, int y) { window.setColor(Color.CYAN); window.fillOval(x + 8, y + 11, 45 - 16, 45 - 16); window.setColor(Color.BLACK); window.fillOval(x + 14, y + 15, 5, 5); // eyes window.fillOval(x + 25, y + 15, 5, 5); // eyes imgFound = false; // health bar window.setColor(Color.RED); window.fillRect(x, y, 45, 9); window.setColor(Color.GREEN); window.fillRect(x, y, (int) ((double) currentHealth / (double) (maxHealth) * 45), 9); }
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); } }
/** * Function: drawNode Pre: Takes a graphics object g to draw on. Also takes two ints (x_size, * y_size) defining the screen size Also takes a node radius r Post: Prints out this node to the * screen appropriately */ public void drawNode(Graphics g, int x_size, int y_size, int r) { // Don't print nodes that aren't activated if (!activated) return; // First, get some stats based on the Graphics area size // In particular, the size of the Node int px = (int) (x_size * x) - r; // X & Y positions int py = (int) (y_size * y) - r; // Set the font to appropriate no matter what // int sizor; //The size for the text, based on radius g.setFont(new Font("Serif", Font.BOLD, r)); // Find the color for the text, it's used often... we'll do this later now // String textcol = getOtherTextColor(color); MOOF! UPDATE THIS LATER! // Make sure the color is correct no matter what... adjust also later! // Node insides... get this color correct later, moof! g.setColor(getMyJavaColor()); // g.setColor(Color.white); g.fillOval(px, py, r * 2, r * 2); // Node border g.setColor(getJavaColor(getOtherNodeColor(color))); g.drawOval(px, py, r * 2, r * 2); // Text inside... set up to be centered py = py + r + (int) (g.getFontMetrics().getAscent() / 2.2); px = px + r - (g.getFontMetrics().stringWidth("" + cindex) / 2); g.drawString("" + cindex, px, py); }
public void draw(Graphics window, int scale, int x, int y) { window.setColor(Color.CYAN); window.fillOval( x + 8 * scale / 45, y + 11 * scale / 45, scale - 16 * scale / 45, scale - 16 * scale / 45); window.setColor(Color.BLACK); window.fillOval( x + 14 * scale / 45, y + 15 * scale / 45, 5 * scale / 45, 5 * scale / 45); // eyes window.fillOval( x + 25 * scale / 45, y + 15 * scale / 45, 5 * scale / 45, 5 * scale / 45); // eyes imgFound = false; // health bar window.setColor(Color.RED); window.fillRect(x, y, scale - 1, 9 * scale / 45); window.setColor(Color.GREEN); window.fillRect( x, y, (int) ((double) currentHealth / (double) (maxHealth) * (scale - 1)), 9 * scale / 45); }
void circle(Graphics g, double x, double y, int st) { switch (st) { case Block.BLANK: return; case Block.RED_BEAD: switch (gst.theme) { case 0: g.setColor(Color.RED); break; case 1: g.setColor(Color.BLACK); break; case 2: g.drawImage( gold, (int) (x - bst.scale * r3 / 2 * 0.75), (int) (y - bst.scale * r3 / 2 * 0.75), (int) (bst.scale * r3 * 0.75), (int) (bst.scale * r3 * 0.75), Color.WHITE, null); return; } break; case Block.BLUE_BEAD: switch (gst.theme) { case 0: g.setColor(Color.BLUE); break; case 1: g.setColor(new Color(1, 175, 1)); break; case 2: g.drawImage( silver, (int) (x - bst.scale * r3 / 2 * 0.75), (int) (y - bst.scale * r3 / 2 * 0.75), (int) (bst.scale * r3 * 0.75), (int) (bst.scale * r3 * 0.75), Color.WHITE, null); return; } break; case Block.RED_PATH: case Block.BLUE_PATH: g.setColor(Color.GREEN); break; } g.fillOval( (int) (x - bst.scale * r3 / 2 * 0.75), (int) (y - bst.scale * r3 / 2 * 0.75), (int) (bst.scale * r3 * 0.75), (int) (bst.scale * r3 * 0.75)); }
/** * Adds pixel to queue and calls repaint() whenever we have MAX_ITEMS pixels in the queue or * when MAX_TIME msecs have elapsed (whichever comes first). The advantage compared to just * calling repaint() after adding a pixel to the queue is that repaint() can most often draw * multiple points at the same time. */ public void drawPoint(DrawCommand c) { if (c == null || gr == null) return; Color col = new Color(c.rgb); gr.setColor(col); gr.fillOval(c.x, c.y, 10, 10); repaint(); if (state != null) { synchronized (state) { state.put(new Point(c.x, c.y), col); } } }
/** * ************************************************************\ Drawing method for the molecule * editor panel * * * @param g * \************************************************************* */ public void draw(Graphics g) { double r = type.getRadius(); Color c = type.getColor(); g.setColor(c); int pixelsPerNm = DrawPanel.PIXELS_PER_NM; // In the drawPanel we map the z-coordinate to the x-coordinate int xint = (int) Math.round(pixelsPerNm * z); int yint = (int) Math.round(pixelsPerNm * y); int rint = (int) Math.round(pixelsPerNm * r); g.fillOval(xint - rint, yint - rint, 2 * rint, 2 * rint); g.setColor(Color.GRAY); g.drawOval(xint - rint, yint - rint, 2 * rint, 2 * rint); }
private void drawPageIndicator(Graphics g) // PRE: g must be initialized. // POST: Draws a page indicator above the OK button. The filled in circle represents which // page we're currently on. { int x1; // First x coordinate for drawing area. int y1; // First y coordinate for drawing area. int x2; // Second x coordinate for drawing area. int y2; // Second y coordinate for drawing area. int width; // Width of drawing area. int height; // Height of drawing area. int offset; // Offset between circles. Graphics2D g2; // Graphics2D to change brush stroke. x1 = ScaledPoint.scalerToX(0.275); x2 = ScaledPoint.scalerToX(0.325); y1 = ScaledPoint.scalerToY(0.85); y2 = ScaledPoint.scalerToY(0.89); width = (x2 - x1) / 2; height = y2 - y1; offset = ScaledPoint.scalerToX(0.005) / 2; g2 = (Graphics2D) g; g2.setColor(Color.WHITE); g2.setStroke(new BasicStroke(1)); if (currentPage == 0) // if we are on the first page { g.fillOval(x1 - offset, y1, width, height); g.drawOval(x1 + width + offset, y1, width, height); } else // if we are on the second page. { g.drawOval(x1 - offset, y1, width, height); g.fillOval(x1 + width + offset, y1, width, height); } }
void drawPoint(Graphics g, DrawObject p) { if (p == null) { return; } if ((sequencingOn) && (p.sequenceNum != currentSequenceNumDisplay)) { return; } int x = (int) ((p.x - minX) / (maxX - minX) * (D.width - 2 * inset)); int y = (int) ((p.y - minY) / (maxY - minY) * (D.height - 2.0 * inset)); if (p.diameter > 1) { int r = p.diameter / 2; g.fillOval(inset + x - r, D.height - y - inset - r, 2 * r, 2 * r); } else { g.fillRect(inset + x, D.height - y - inset, 1, 1); } }
/** Draw the entire panel from the state */ @SuppressWarnings("rawtypes") public void drawState() { // clear(); Map.Entry entry; Point pt; Color col; synchronized (state) { for (Iterator it = state.entrySet().iterator(); it.hasNext(); ) { entry = (Map.Entry) it.next(); pt = (Point) entry.getKey(); col = (Color) entry.getValue(); gr.setColor(col); gr.fillOval(pt.x, pt.y, 10, 10); } } repaint(); }
private void drawPlayers(Graphics g) { Iterator i = players.iterator(); Player p; while (i.hasNext()) { p = (Player) i.next(); if (p.isActive()) { if (p.getImmunity()) { g.setColor(Color.red.brighter()); g.drawOval(p.getX() - 30, p.getY() - 30, 60, 60); } g.setColor(Color.WHITE); g.fillOval(p.getX() - 5, p.getY() - 5, 10, 10); } p.paint(g); } }
public void update(Graphics g) { Dimension d = getSize(); int rad, angles[] = {180, 0}; Point center; if ((offscreen_ == null) || (d.width != offscreensize_.width) || (d.height != offscreensize_.height)) { offscreen_ = createImage(d.width, d.height); offscreensize_ = new Dimension(d.width, d.height); offgraphics_ = offscreen_.getGraphics(); offgraphics_.setFont(getFont()); // g.setColor (Color.lightGray); // g.draw3DRect (0, 0, d.width - 1, d.height - 1, true); // g.draw3DRect (1, 1, d.width - 3, d.height - 3, true); // g.draw3DRect (2, 2, d.width - 5, d.height - 5, true); } offgraphics_.setColor(getBackground()); offgraphics_.fillRect(0, 0, d.width, d.height); offgraphics_.setColor(BLUE); // Calculate from the dimensions, the largest square. center = new Point(d.width / 2, d.height / 2); rad = ((center.x < center.y) ? center.x : center.y); // Draw a circle of blue offgraphics_.fillOval(center.x - rad, center.y - rad, 2 * rad, 2 * rad); // Roll the horizon based on the roll angle if (roll_ != 0) roll_horizon(rad, angles); // Pitch the horizon based on the pitch angle if (pitch_ != 0) pitch_horizon(rad, angles); // Draw the resulting terrain draw_horizon(rad, center, angles); // Draw the plotted Image. g.drawImage(offscreen_, 0, 0, null); }
public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.RED); double y; int x2; int plus = 780 / _tabDonnee.size(); int y2; double puissance; for (int x = 0; x < _tabDonnee.size(); ++x) { puissance = _poids * (_tabDonnee.get(x) * _tabDonnee.get(x)) * _pasTemps; y = _tabDonnee.get(x); x2 = plus * x; y2 = 500 - (int) y; g.fillOval(x2, y2, 10, 10); g.drawString("T:" + x * _pasTemps, x2, y2); g.drawString("V:" + y, x2, y2 - 10); g.drawString("P:" + puissance, x2, y2 + 20); } }
@Override public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.black); g.fillRect(0, 0, getWidth(), getHeight()); for (Integer id : planetNames.keySet()) { String name = planetNames.get(id); Point p = planetCoordinates.get(id); PartialPlanetBlock planet = getPlanet(id, -2); g.setColor(Color.gray); int rad = 3; if (planet != null) { rad = 6; if (animatorFrame) { Color col = colors.get(planet.owner); if (col == null) col = Color.gray; g.setColor(col); } else { if (planet.owner == settings.playerNr) g.setColor(Color.green); else if (colorize.isSelected() && colors.get(planet.owner) != null) g.setColor(colors.get(planet.owner)); else if (friends.contains(planet.owner)) g.setColor(Color.YELLOW); else if (planet.owner >= 0) g.setColor(Color.red); else rad = 3; } } int x = convertX(p.x); int y = convertY(p.y); double virtualWidth = getWidth() * zoom / 100; double virtualHeight = getHeight() * zoom / 100; int xOffset = (int) (getWidth() - virtualWidth) / 2; int yOffset = (int) (getHeight() - virtualHeight) / 2; x = (int) (xOffset + x * zoom / 100.0 - mariginX * zoom / 100.0); y = (int) (yOffset + y * zoom / 100.0 - mariginY * zoom / 100.0); g.fillOval(x - rad / 2, y - rad / 2, rad, rad); if (names.isSelected()) { g.setFont(g.getFont().deriveFont((float) 10)); g.setColor(Color.gray); int stringWidth = g.getFontMetrics().stringWidth(name); g.drawString(name, x - stringWidth / 2, y + 12); } if (colorize.isSelected() || animatorFrame) { int yy = 20; g.setFont(g.getFont().deriveFont((float) 12)); for (PlayerBlock pb : GalaxyViewer.this.p.players) { if (pb == null) continue; Color col = colors.get(pb.playerNumber); if (animatorFrame && col != null) ; // Ok else if (pb.playerNumber == settings.playerNr) col = Color.green; else if (col == null) col = Color.red; g.setColor(col); String n = new String(pb.nameBytes); // Does not work n = "Player " + (pb.playerNumber + 1); g.drawString(n, 5, yy); // System.out.print(pb.playerNumber+": "); // for (int t = 0; t < pb.nameBytes.length; t++){ // System.out.print((pb.nameBytes[t]&0xff)+" "); // System.out.print((pb.nameBytes[t])+" "); // } // System.out.println(); yy += 14; } } } }