private void drawYTicks(Graphics g) { int hPos = 0; int pPos = 0; for (int i = 0; i < yTicks; i++) { int drawPos = yVal(hPos, maxH) + r; if (hPos % hInc == 0) { // draw line g.setColor(Color.BLACK); g.drawLine(padding - 10, drawPos, padding, drawPos); // draw tick values for herbivores g.setColor(Color.BLUE); g.drawString("" + hPos, padding - 50, drawPos + r); // draw tick values for predators g.setColor(Color.RED); g.drawString("" + pPos, padding - 50, drawPos + r + 20); } hPos += hInc; pPos += pInc; } }
/** * 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); }
void displayCharacterMap(Graphics g) { if (currentChars != null) { g.setColor(0xffffff); g.fillRect(0, getHeight() - inputHeight - 2, getWidth(), inputHeight + 2); g.setColor(0x000000); g.drawLine(0, getHeight() - inputHeight - 2, getWidth(), getHeight() - inputHeight - 2); for (int i = 0; i < currentChars.length; i++) { char ch = currentChars[i]; if (isUppercase) { ch = String.valueOf(currentChars[i]).toUpperCase().charAt(0); } // TODO: if i*12 > getWidth() ? g.drawChar(ch, i * 12, getHeight() - inputHeight, Graphics.LEFT | Graphics.TOP); if (currentChars[currentKeyStep] == currentChars[i]) { g.drawRect( i * 12 - 2, getHeight() - inputHeight - 2, inputFont.charWidth(ch) + 4, inputHeight + 4); } } } }
private void draw_horizon(int rad, Point center, int[] angles) { // Draw an arc int arc_angle = ((angles[0] > angles[1]) ? (360 - angles[0]) + angles[1] : (angles[1] - angles[0])); Polygon remainder = new Polygon(); offgraphics_.setColor(GREEN); offgraphics_.fillArc(center.x - rad, center.y - rad, 2 * rad, 2 * rad, angles[0], arc_angle); if (pitch_ != 0) { if ((pitch_ > 0 && Math.abs(roll_) < 90) || (pitch_ < 0 && Math.abs(roll_) >= 90)) offgraphics_.setColor(BLUE); int cover_angle = (angles[0] + arc_angle / 2 + ((arc_angle < 180) ? 180 : 0)) % 360; // System.out.println (points[0] + " " + points[1]); // System.out.println (accepted_point); remainder.addPoint( center.x + polar_to_rect_x(rad, cover_angle), center.y - polar_to_rect_y(rad, cover_angle)); remainder.addPoint( center.x + polar_to_rect_x(rad, angles[0]), center.y - polar_to_rect_y(rad, angles[0])); remainder.addPoint( center.x + polar_to_rect_x(rad, angles[1]), center.y - polar_to_rect_y(rad, angles[1])); offgraphics_.fillPolygon(remainder); // offgraphics_.setColor (getBackground ()); // offgraphics_.drawPolygon (remainder); } }
// draws the button, based on the type of button (ImageIcon, Image, or String) public void draw(Graphics g) { if (visible) { // if its image/imageicon, draw it g.setColor(new Color(50, 200, 50)); g.fillRect(x - 1, y - 1, width + 2, height + 2); if (mode.equals("Image") || mode.equals("ImageIcon")) { if (enabled) { g.drawImage(image, x, y, null); } else { g.drawImage(BWimage, x, y, null); } // if its string, draw the string } else { g.setFont(new Font("Arial", Font.PLAIN, 20)); if (enabled) { g.setColor(Color.black); g.drawString(message, x + 20, y + 20); } else { g.setColor(new Color(255, 255, 255)); g.fillRect(x - 1, y - 1, width + 2, height + 2); g.setColor(Color.black); g.drawString(message, x + 20, y + 20); } } } }
/** Affichage du logo */ protected void drawLogo(Graphics g) { int x = 5; int y = 2; g.setColor(getBackground()); g.fillRect(0, 0, W, H); // Remplissage fillBG(g, x, y, Color.white); // Dessin drawGrid( g, x, y, !isAvailable() ? Aladin.MYGRAY : isActive() ? Aladin.GREEN : isMouseIn() ? Color.blue : Color.black); // Label g.setColor(isAvailable() ? Color.black : Aladin.MYGRAY); g.setFont(Aladin.SPLAIN); g.drawString(LABEL, W / 2 - g.getFontMetrics().stringWidth(LABEL) / 2, H - 2); }
private void drawSquare(Graphics g, int x, int y, Tetrominoes shape) { int squareWidth = (int) getSize().getWidth() / model.getWidth(); int squareHeight = (int) getSize().getHeight() / model.getHeight(); Color colors[] = { new Color(0, 0, 0), new Color(204, 102, 102), new Color(102, 204, 102), new Color(102, 102, 204), new Color(204, 204, 102), new Color(204, 102, 204), new Color(102, 204, 204), new Color(218, 170, 0) }; Color color = colors[shape.ordinal()]; g.setColor(color); g.fillRect(x + 1, y + 1, squareWidth - 2, squareHeight - 2); g.setColor(color.brighter()); g.drawLine(x, y + squareHeight - 1, x, y); g.drawLine(x, y, x + squareWidth - 1, y); g.setColor(color.darker()); g.drawLine(x + 1, y + squareHeight - 1, x + squareWidth - 1, y + squareHeight - 1); g.drawLine(x + squareWidth - 1, y + squareHeight - 1, x + squareWidth - 1, y + 1); }
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 paint(Graphics g) { super.paint(g); Dimension size = getSize(); double w = size.getWidth() - 50; double h = size.getHeight() + 20; try { readFile(); } catch (IOException e) { System.err.println("IO issue"); } barWidth = ((int) (w / numBars)) - 20; pos = 5; int xPos[] = {pos, pos, pos, pos}; int yPos[] = {pos, pos, pos, pos}; maxVal = maxValue(values); double barH, ratio; for (int i = 0; i < numBars - 1; i++) { Color col[] = new Color[numBars]; for (int j = 0; j < numBars - 1; j++) { col[j] = new Color((int) (Math.random() * 0x1000000)); } ratio = (double) values[i] / (double) maxVal; barH = ((h) * ratio) - 10; xPos[0] = pos; xPos[2] = pos + barWidth; xPos[1] = xPos[0]; xPos[3] = xPos[2]; yPos[0] = (int) h; yPos[1] = (int) barH; yPos[2] = yPos[1]; yPos[3] = yPos[0]; System.out.println( "xPos:" + xPos[1] + " yPos:" + yPos[0] + " h:" + h + " barH:" + barH + " ratio:" + ratio + " pos:" + pos); int stringPtsY[] = { ((i + 1) * 20) + 180, ((i + 1) * 20) + 200, ((i + 1) * 20) + 200, ((i + 1) * 20) + 180 }; int stringPtsX[] = {600, 600, 580, 580}; g.setColor(col[i]); g.fillPolygon(xPos, yPos, xPos.length); g.fillPolygon(stringPtsX, stringPtsY, 4); g.setColor(Color.black); g.drawString(labels[i], 610, ((i + 1) * 20) + 195); pos = pos + barWidth + 10; } }
void displayStatus(Graphics g) { if (statusString != null) { g.setColor(0xffffff); g.fillRect(0, getHeight() - inputHeight - 2, getWidth(), inputHeight + 2); g.setColor(0x000000); g.drawLine(0, getHeight() - inputHeight - 2, getWidth(), getHeight() - inputHeight - 2); g.drawString(statusString, 0, getHeight() - inputHeight - 2, Graphics.LEFT | Graphics.TOP); } }
/** * Paint method for applet. * * @param g the Graphics object for this applet */ public void paint(Graphics g) { // simple text displayed on applet g.setColor(c); g.fillRect(0, 0, 200, 100); g.setColor(Color.black); g.drawString("Sample Applet", 20, 20); g.setColor(Color.blue); g.drawString("created by BlueJ", 20, 40); }
public void drawBox(Graphics g, int x, int y, String str, Color fg, Color bg, Font font) { g.setColor(bg); g.fillRect(x, y, horizSpace, vertSpace); g.setColor(Color.black); g.drawRect(x, y, horizSpace, vertSpace); g.setColor(fg); g.setFont(font); g.drawString(str, x + 2, y + vertSpace - 4); }
/** * Draws a visualization tooltip. * * @param g graphics reference * @param tt tooltip label * @param x horizontal position * @param y vertical position * @param w width * @param c color color depth */ public static void drawTooltip( final Graphics g, final String tt, final int x, final int y, final int w, final int c) { final int tw = width(g, tt); final int th = g.getFontMetrics().getHeight(); final int xx = Math.min(w - tw - 8, x); g.setColor(color(c)); g.fillRect(xx - 1, y - th, tw + 4, th); g.setColor(BACK); g.drawString(tt, xx, y - 4); }
// Border public void drawSpecialLines(Graphics g) { for (int i = 0; i < 11; i++) { if (i % 2 == 0) { g.setColor(new Color(51, 51, 51)); } else { g.setColor(new Color(255, 193, 37)); } g.drawRect(0 + i, 0 + i, this.getWidth() - i * 2, this.getHeight() - i * 2); } }
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)); }
void displayCurrentCommand(Graphics g) { g.setColor(0xffffff); g.fillRect(0, getHeight() - inputHeight - 2, getWidth(), inputHeight + 2); g.setColor(0x000000); g.drawLine(0, getHeight() - inputHeight - 2, getWidth(), getHeight() - inputHeight - 2); g.drawString( "Ctrl" + " + " + currentCharCommand, 0, getHeight() - inputHeight, Graphics.LEFT | Graphics.TOP); }
// Borders for decoration public void drawSpecialLines(Graphics g) { for (int i = 0; i < 11; i++) { if (i % 2 == 0) { g.setColor(new Color(51, 51, 51)); } else { g.setColor(new Color(255, 193, 37)); } g.drawRect( 0 + i, 0 + i, box.length * Square.SIZE - i * 2, box[0].length * Square.SIZE - i * 2); } }
public void drawNotOK(Graphics g, int widthX, int heightX) { int pixelsPerNm = DrawPanel.PIXELS_PER_NM; int xint = (int) Math.round(pixelsPerNm * z); int yint = (int) Math.round(pixelsPerNm * y); int rint = (int) Math.round(pixelsPerNm * type.getRadius()); g.setColor(Color.white); g.fillRect(xint - rint, yint + rint - heightX, widthX, heightX); g.setColor(Color.black); g.drawRect(xint - rint, yint + rint - heightX, widthX, heightX); g.drawString("X", xint - rint, yint + rint); }
public void paint(Graphics g) { super.paint(g); if (!isEditing) return; Dimension psize = getPreferredSize(); if (isFocused) g.setColor(Color.yellow); else g.setColor(Color.green); g.drawLine(0, 0, psize.width, 0); g.drawLine(0, 0, 0, psize.height); g.drawLine(0, psize.height - 1, psize.width - 1, psize.height - 1); g.drawLine(psize.width - 1, 0, psize.width - 1, psize.height - 1); }
public void paint(Graphics g) { if (comp != null) { width = comp.getWidth() / 6; height = comp.getHeight() * 2 / 3; } g.setColor(bgColor); g.fillRect(x, y, width, height); g.setColor(fgColor); g.setFont(font); g.drawString(strTray, x / 2 + width / 2, y + height + 10); super.paint(g); }
void displayCursor(Graphics g) { int x = getCursorX(); int y = getCursorY(); if (x >= 0 && x <= vectorLines.elementAt(y).toString().length()) { if (isSelected(x, y)) { g.setColor(0xffffff); } else { g.setColor(0x000000); } g.drawLine(caretLeft, (y) * inputHeight, caretLeft, (y + 1) * inputHeight); } }
/** * ************************************************************\ 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); }
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 static DrawingPanel background(String meaning) { DrawingPanel panel = new DrawingPanel(780, 560); Graphics g = panel.getGraphics(); panel.setBackground(Color.white); g.setColor(Color.LIGHT_GRAY); g.fillRect(0, 0, 781, bannerHeight); g.fillRect(0, 530, 781, bannerHeight); g.setColor(Color.black); g.drawString(meaning, 0, 16); for (int i = startYear; i <= 2010; i += 10) { g.drawString("" + i, (decadeWidth / 10) * (i - startYear), 552); } return panel; }
void displayScrollBar(Graphics g) { int x = getCursorX(); int y = getCursorY(); g.setColor(0xffffff); g.fillRect(getWidth() - 5, 0, 5, getHeight()); g.setColor(0x000000); g.drawLine(getWidth() - 5, 0, getWidth() - 5, getHeight()); int hScrollMin = inputHeight; int yScroll = (((linesOnScreen - 1) * y) * inputHeight) / getLinesCount(); g.fillRect(getWidth() - 5, yScroll, 5, hScrollMin); }
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); }
/** * Draws a colored cell. * * @param g graphics reference * @param xs horizontal start position * @param xe horizontal end position * @param ys vertical start position * @param ye vertical end position * @param focus highlighting flag */ public static void drawCell( final Graphics g, final int xs, final int xe, final int ys, final int ye, final boolean focus) { g.setColor(gray); g.drawRect(xs, ys, xe - xs - 1, ye - ys - 1); g.setColor(BACK); g.drawRect(xs + 1, ys + 1, xe - xs - 3, ye - ys - 3); g.setColor(focus ? lgray : BACK); g.fillRect(xs + 1, ys + 1, xe - xs - 2, ye - ys - 2); }
private void drawBalance(Graphics g) // POST: Draws the balance of the current player { Font font; // Font used to draw balance String message; // Message for balance Color oldColor; // Sets for color int x1; // Upper-left x coordinate int y1; // Upper-left y coordinate int x2; // Bottom-right x coordinate int y2; // Bottom-right y coordinate int width; // Width of the dialogue box int height; // Height of the dialogue box int offset; // Offset so the dialogue box is positioned int balance; // Offset so the dialogue box is positioned User player; // User value for the player player = usersArray[0]; balance = player.getBalance(); oldColor = g.getColor(); x1 = ScaledPoint.scalerToX(0.72); y1 = ScaledPoint.scalerToY(0.81); x2 = ScaledPoint.scalerToX(0.88); y2 = ScaledPoint.scalerToY(0.86); width = x2 - x1; height = y2 - y1; message = "Balance:"; font = Drawing.getFont(message, width, height, FONTNAME, FONTSTYLE); offset = (width - getFontMetrics(font).stringWidth(message)) / 2; g.setColor(Color.WHITE); g.drawString(message, x1 + offset, y2); x1 = ScaledPoint.scalerToX(0.72); y1 = ScaledPoint.scalerToY(0.865); x2 = ScaledPoint.scalerToX(0.88); y2 = ScaledPoint.scalerToY(0.915); width = x2 - x1; height = y2 - y1; message = "$" + Integer.toString(balance); font = Drawing.getFont(message, width, height, FONTNAME, FONTSTYLE); offset = (width - getFontMetrics(font).stringWidth(message)) / 2; g.drawString(message, x1 + offset, y2); g.setColor(oldColor); }
/** Dessine l'icone de la grille */ protected static void drawGrid(Graphics g, int x, int y, Color c) { g.setColor(c); for (int i = 0; i < TX.length; i++) g.drawLine(TX[i][0] + x, TX[i][2] + y, TX[i][1] + x, TX[i][2] + y); for (int i = 0; i < TY.length; i++) g.drawLine(TY[i][2] + x, TY[i][0] + y, TY[i][2] + x, TY[i][1] + y); }
// Give the string and horizontal and verical offsets so that the label is // drawn in the center. public void drawLabel(Graphics g, String label, int hoffset, int voffset) { g.setColor(Color.black); int pixelsPerNm = DrawPanel.PIXELS_PER_NM; int xint = (int) Math.round(pixelsPerNm * z); int yint = (int) Math.round(pixelsPerNm * y); g.drawString(label, xint - hoffset, yint + voffset); }