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);
  }
  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);
    }
  }
  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);
  }
Example #4
0
 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;
  }
Example #6
0
  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;
  }