private void drawStoreName(Graphics g) // PRE: g must be initialized. // POST: Draws the store name along with a rounded border at the top of the window. { int rectWidth; // The width of the drawing area. int rectHeight; // The height of the drawing area. String storeName; // The name of the store. Font font; // The font to be used. rectWidth = nameLocation[1].getScaledX() - nameLocation[0].getScaledX(); rectHeight = nameLocation[1].getScaledY() - nameLocation[0].getScaledY(); switch (store) // set message based on store value. { case 0: storeName = "Raneac's Crucible"; break; case 1: storeName = "The Iron Maiden"; break; case 2: storeName = "The Grand Bazaar"; break; default: storeName = "Miko's Wares"; } font = Drawing.getFont(storeName, rectWidth, rectHeight, FONTNAME, FONTSTYLE); g.setFont(font); g.setColor(Color.WHITE); g.drawString( storeName, nameLocation[0].getScaledX(), (int) (nameLocation[1].getScaledY() * .98)); Drawing.drawRoundedRect(g, nameLocation, Color.WHITE); }
public void paint(Graphics g) { g.setColor(Color.red); g.setFont(new Font("Arial", Font.BOLD, 25)); g.drawString("Registrar nueva venta", 60, 60); }
private void drawItem(Graphics g, int item, Item currentItem) { Font font; // The font to be used. int x1; // The first x coordinate of drawing area. int y1; // The first y coordinate of drawing area. int x2; // The second x coordinate of drawing area. int y2; // The second y coordinate of drawing area. int width; // Width of drawing area. int height; // Height of drawing area. int iconX; // x coordinate of the icon. int iconY; // y coordinate of the icon. int iconLength; // Length of the icon. int itemNameX; // The x coordinate of the item name. int itemNameLength; // The length of the item name. int itemPriceX; // The x coordinate of the item price. int itemPriceWidth; // The width of the item price. x1 = itemPositions[item][0].getScaledX(); x2 = itemPositions[item][1].getScaledX(); y1 = itemPositions[item][0].getScaledY(); y2 = itemPositions[item][1].getScaledY(); width = x2 - x1; height = y2 - y1; iconX = x1 + (int) (width * .01); iconY = y1 + (int) (height * .1); iconLength = (int) (height * .8); Drawing.drawImage(g, iconX, iconY, iconLength, iconLength, currentItem.getItemPath()); itemNameX = iconX + (int) (iconLength * 1.5); itemNameLength = (int) (width * 0.6); font = Drawing.getFont( currentItem.getItemName(), itemNameLength, (int) (iconLength * 0.8), FONTNAME, FONTSTYLE); g.setFont(font); g.setColor(Color.WHITE); g.drawString(currentItem.getItemName(), itemNameX, iconY + (int) (iconLength * 0.9)); itemPriceX = x1 + (int) (width * 0.8); itemPriceWidth = (int) (width * 0.15); font = Drawing.getFont( Integer.toString(currentItem.getPrice()), itemPriceWidth, iconLength, FONTNAME, FONTSTYLE); g.setFont(font); g.setColor(Color.WHITE); g.drawString( Integer.toString(currentItem.getPrice()), itemPriceX, iconY + (int) (iconLength * .9)); return; }
public int print(Graphics g, PageFormat pf, int pageIndex) { Font f1 = new Font("SERIF", Font.PLAIN, 8); FontMetrics metric = g.getFontMetrics(f1); int lineHeight = metric.getHeight(); if (pageBreak == null) { initLines(); int s = (numLines % 3); if (s > 0) numLines = numLines + (3 - s); numLines /= 3; int linesPerPage = (int) (pf.getImageableHeight() / lineHeight); int numBreaks = (numLines / linesPerPage); pageBreak = new int[numBreaks]; for (int b = 0; b < numBreaks; b++) { pageBreak[b] = (b + 1) * linesPerPage; } } if (pageIndex > pageBreak.length) { return NO_SUCH_PAGE; } Graphics2D g2d = (Graphics2D) g; g2d.translate(pf.getImageableX(), pf.getImageableY()); int y = 0; g.setFont(new Font("SERIF", Font.PLAIN, 9)); int start = 0; if (pageIndex == 0) start = 0; else start = pageBreak[pageIndex - 1]; int end = 0; if (pageIndex == pageBreak.length) end = numLines; else end = pageBreak[pageIndex]; if (chk % 2 == 1 && (end - start) != lineHeight) { for (int line = start; line < end && i < x; line += 9) { y += (2 * lineHeight); g.drawString("" + textLines[i][0], 30, y); g.drawString(textLines[i][1], 30, y + lineHeight); g.drawString(textLines[i][2], 30, y + 2 * lineHeight); g.drawString(textLines[i][3], 30, y + 3 * lineHeight); g.drawString(textLines[i][4], 30, y + 4 * lineHeight); g.drawString(textLines[i][5], 30, y + 5 * lineHeight); g.drawString(textLines[i][6], 30, y + 6 * lineHeight); if ((i + 1) < x) { g.drawString(textLines[i + 1][0], 225, y); g.drawString(textLines[i + 1][1], 225, y + lineHeight); g.drawString(textLines[i + 1][2], 225, y + 2 * lineHeight); g.drawString(textLines[i + 1][3], 225, y + 3 * lineHeight); g.drawString(textLines[i + 1][4], 225, y + 4 * lineHeight); g.drawString(textLines[i + 1][5], 225, y + 5 * lineHeight); g.drawString(textLines[i + 1][6], 225, y + 6 * lineHeight); } if ((i + 2) < x) { g.drawString(textLines[i + 2][0], 415, y); g.drawString(textLines[i + 2][1], 415, y + lineHeight); g.drawString(textLines[i + 2][2], 415, y + 2 * lineHeight); g.drawString(textLines[i + 2][3], 415, y + 3 * lineHeight); g.drawString(textLines[i + 2][4], 415, y + 4 * lineHeight); g.drawString(textLines[i + 2][5], 415, y + 5 * lineHeight); g.drawString(textLines[i + 2][6], 415, y + 6 * lineHeight); } y += 7 * lineHeight; i += 3; } } else { for (int line = start; line < end && i < x; line += 8) {} } chk++; return PAGE_EXISTS; }