Esempio n. 1
0
  public void paintComponent(Graphics g) {
    if (name == "" && serialport == "") {
      Map<String, String> boardPreferences = Base.getBoardPreferences();
      if (boardPreferences != null) setBoardName(boardPreferences.get("name"));
      else setBoardName("-");
      setSerialPort(Preferences.get("serial.port"));
    }
    g.setColor(background);
    Dimension size = getSize();
    g.fillRect(0, 0, size.width, size.height);

    g.setFont(font);
    g.setColor(foreground);
    int baseline = (high + g.getFontMetrics().getAscent()) / 2;
    g.drawString(text, 6, baseline);

    g.setColor(messageForeground);
    String tmp = name + " on " + serialport;

    Rectangle2D bounds = g.getFontMetrics().getStringBounds(tmp, null);

    g.drawString(tmp, size.width - (int) bounds.getWidth() - 20, baseline);

    if (Base.isMacOS()) {
      g.drawImage(resize, size.width - 20, 0, this);
    }
  }
Esempio n. 2
0
  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;
    }
  }
 public static void drawString(JComponent c, Graphics g, String text, int x, int y) {
   Graphics2D g2D = (Graphics2D) g;
   Object savedRenderingHint = null;
   if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
     savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
     g2D.setRenderingHint(
         RenderingHints.KEY_TEXT_ANTIALIASING,
         AbstractLookAndFeel.getTheme().getTextAntiAliasingHint());
   }
   if (getJavaVersion() >= 1.6) {
     try {
       Class swingUtilities2Class = Class.forName("sun.swing.SwingUtilities2");
       Class classParams[] = {
         JComponent.class, Graphics.class, String.class, Integer.TYPE, Integer.TYPE
       };
       Method m = swingUtilities2Class.getMethod("drawString", classParams);
       Object methodParams[] = {c, g, text, new Integer(x), new Integer(y)};
       m.invoke(null, methodParams);
     } catch (Exception ex) {
       g.drawString(text, x, y);
     }
   } else {
     g.drawString(text, x, y);
   }
   if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
     g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint);
   }
 }
Esempio n. 4
0
 // färger, se sid 43 i boken
 // grafiska metoder, sid 248 i boken
 public void paintComponent(Graphics g) { // för att vara säker på att
   // "super"-klassen gör sitt
   // anropar vi den metoden, innan
   // vi skriver eller ritar
   super.paintComponent(g);
   g.drawLine(185, 10, 195, 40); // x1,y1 till x2,y2
   g.drawLine(200, 10, 200, 40);
   g.drawLine(215, 10, 205, 40);
   g.setColor(Color.white);
   g.fillOval(50, 30, 300, 150); // x,y,b,h (x,y för ö v h)
   g.setColor(Color.red);
   g.drawArc(100, 100, 200, 50, 180, 180); // x,y,b,h,s,l
   g.setColor(Color.yellow);
   g.fillRect(200, 100, 30, 30);
   g.fill3DRect(150, 50, 30, 50, true); // true upphöjd figur
   g.fill3DRect(250, 50, 30, 50, true);
   // skriv ut en textsträng, samt ange läget i avståndet från
   // övre vänstra hörnet i x-led åt höger och i y-led neråt
   g.drawString("** Tjenare kompis !! **", 20, 20);
   f = new Font("Arial", Font.BOLD, 30);
   setBackground(Color.cyan);
   g.setFont(f);
   g.setColor(new Color(255, 175, 175));
   g.drawString("YEEEEEEEES!!", 100, 250);
 }
  public void drawVictory(Graphics g) {
    g.setColor(new Color(0, 0, 0, 200));
    g.fillRect(195, 220, 410, 110);
    g.setColor(new Color(255, 255, 255, 200));
    g.fillRect(200, 225, 400, 100);
    g.setColor(new Color(0, 0, 0, 200));
    g.setFont(new Font("Bell MT", Font.BOLD, 20));
    FontMetrics metrics = g.getFontMetrics(new Font("Bell MT", Font.BOLD, 20));
    int hgt = metrics.getHeight();

    String initialMessage;
    String followupMessage;

    if (nextWindow) {
      initialMessage = "You have gotten stronger.";
      followupMessage = player.getName() + " is now level " + player.getLevel() + "!";
    } else {
      initialMessage = "You survived!";
      followupMessage = "You and your allies gain " + totalExperience + " experience!";
    }

    // Hgt = 26
    int adv = metrics.stringWidth(initialMessage);
    g.drawString(initialMessage, getWidth() / 2 - adv / 2, 234 + hgt);
    adv = metrics.stringWidth(followupMessage);
    g.drawString(followupMessage, getWidth() / 2 - adv / 2, 269 + hgt);
  }
Esempio n. 6
0
  public void paint(Graphics graphics) {
    super.paint(graphics);
    int size = getFont().getSize();
    for (int y = 0; y < Chess.NUM_OF_ROWS; y++) {
      for (int x = 0; x < Chess.NUM_OF_COLS; x++) {
        //                System.out.println(y + " " + x);
        int sqi =
            (m_bottom == Chess.WHITE
                ? Chess.coorToSqi(x, Chess.NUM_OF_ROWS - y - 1)
                : Chess.coorToSqi(Chess.NUM_OF_COLS - x - 1, y));
        if (Chess.isWhiteSquare(sqi)) {
          graphics.setColor(m_whiteSquareColor);
          graphics.fillRect(x * size, y * size, size, size);
        } else {
          graphics.setColor(m_blackSquareColor);
          graphics.fillRect(x * size, y * size, size, size);
        }
        int stone = (sqi == m_draggedFrom ? Chess.NO_STONE : m_position.getStone(sqi));
        graphics.setColor(Chess.stoneToColor(stone) == Chess.WHITE ? m_whiteColor : m_blackColor);
        if (m_solidStones) stone = Chess.pieceToStone(Chess.stoneToPiece(stone), Chess.BLACK);
        //                graphics.drawString(getStringForStone(stone, Chess.isWhiteSquare(sqi)), x
        // * size, (y + 1) * size);
        graphics.drawString(getStringForStone(stone, true), x * size, (y + 1) * size);
      }
    }

    if (m_draggedStone != Chess.NO_STONE) {
      graphics.setColor(
          Chess.stoneToColor(m_draggedStone) == Chess.WHITE ? m_whiteColor : m_blackColor);
      graphics.drawString(
          getStringForStone(m_draggedStone, true), m_draggedX - size / 2, m_draggedY + size / 2);
    }
  }
  private void drawColorBar(Graphics g) {
    int minimum, maximum, height;

    minimum = 100;
    maximum = 500;
    height = 1;
    int finalI = 0;

    for (int i = 0; i < (maximum - minimum); i++) {
      float f = 0.75f * i / (float) (maximum - minimum);
      g.setColor(Color.getHSBColor(0.75f - f, 1.0f, 1.0f));
      g.fillRect(getWidth() - 40, height * i + 50, 20, height);
      finalI = i;
    }

    g.setColor(Color.BLACK);
    g.drawString(
        String.valueOf(this.opticalReturnPowerController.getMaxValue()),
        getWidth() - 60,
        48); // Max Value
    g.drawString(
        String.valueOf(this.opticalReturnPowerController.getMinValue()),
        getWidth() - 60,
        finalI + 63); // Min Value
  }
Esempio n. 8
0
  // 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);
        }
      }
    }
  }
Esempio n. 9
0
  /**
   * Draws the specified string.
   *
   * @param g graphics reference
   * @param s text
   * @param x x coordinate
   * @param y y coordinate
   * @param w width
   * @param fs font size
   */
  public static void chopString(
      final Graphics g, final byte[] s, final int x, final int y, final int w, final int fs) {

    if (w < 12) return;
    final int[] cw = fontWidths(g.getFont());

    int j = s.length;
    try {
      int l = 0;
      int fw = 0;
      for (int k = 0; k < j; k += l) {
        final int ww = width(g, cw, cp(s, k));
        if (fw + ww >= w - 4) {
          j = Math.max(1, k - l);
          if (k > 1) fw -= width(g, cw, cp(s, k - 1));
          g.drawString("..", x + fw, y + fs);
          break;
        }
        fw += ww;
        l = cl(s, k);
      }
    } catch (final Exception ex) {
      Util.debug(ex);
    }
    g.drawString(string(s, 0, j), x, y + fs);
  }
Esempio n. 10
0
  private void drawAxes(Graphics g) {
    g.drawLine(padding, height, width + padding, height);
    g.drawLine(padding, 0, padding, height);

    g.drawString("time", padding + width / 2, height + padding - 5);
    g.drawString("pop", 5, height / 2);
  }
Esempio n. 11
0
    public void paintComponent(Graphics g) {
      g.setColor(new Color(96, 96, 96));
      image.paintIcon(this, g, 1, 1);

      FontMetrics fm = g.getFontMetrics();

      String[] args = {jEdit.getVersion()};
      String version = jEdit.getProperty("about.version", args);
      g.drawString(version, (getWidth() - fm.stringWidth(version)) / 2, getHeight() - 5);

      g = g.create((getWidth() - maxWidth) / 2, TOP, maxWidth, getHeight() - TOP - BOTTOM);

      int height = fm.getHeight();
      int firstLine = scrollPosition / height;

      int firstLineOffset = height - scrollPosition % height;
      int lines = (getHeight() - TOP - BOTTOM) / height;

      int y = firstLineOffset;

      for (int i = 0; i <= lines; i++) {
        if (i + firstLine >= 0 && i + firstLine < text.size()) {
          String line = (String) text.get(i + firstLine);
          g.drawString(line, (maxWidth - fm.stringWidth(line)) / 2, y);
        }
        y += fm.getHeight();
      }
    }
Esempio n. 12
0
    protected void paintComponent(Graphics g) {
      super.paintComponent(g);
      Graphics2D g2 = (Graphics2D) g;
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      int w = getWidth();
      int h = getHeight();
      int pointSize = Math.max(Math.min(w, h) / 80, 4);

      double xInc = (double) (w - 2 * PAD) / (MAX_X - 1);
      double scale = (double) (h - 2 * PAD) / MAX_Y;
      // Draw abcissa.
      int tickInc = MAX_X / 10;
      for (int i = 0; i <= MAX_X; i += tickInc) {
        int x = PAD + (int) (i * xInc);
        int y = h - PAD;
        g.drawString(Integer.toString(i), x - 5, y + 20);
        g2.draw(new Line2D.Double(x, y - 5, x, y + 5));
      }
      g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD / 2, h - PAD));
      AffineTransform orig = g2.getTransform();
      g2.rotate(-Math.PI / 2);
      g2.setColor(Color.black);
      g2.drawString("Number of comparisons", -((h + PAD) / 2), PAD / 3);
      g2.setTransform(orig);

      // Draw ordinate.
      tickInc = (h - PAD) / 10;

      for (int i = tickInc; i < h - PAD; i += tickInc) {
        int x = PAD;
        int closest_10 = ((int) (i / scale) / 10) * 10;

        int y = h - PAD - (int) (closest_10 * scale);
        if (y < PAD) break;
        String tickMark = Integer.toString(closest_10);
        int stringLen = (int) g2.getFontMetrics().getStringBounds(tickMark, g2).getWidth();
        g.drawString(tickMark, x - stringLen - 8, y + 5);
        g2.draw(new Line2D.Double(x - 5, y, x + 5, y));
      }
      g2.draw(new Line2D.Double(PAD, PAD / 2, PAD, h - PAD));
      g.drawString("Array Size", (w - PAD) / 2, h - PAD + 40);

      for (int index = 0; index < plot_data.size(); index++) {
        int[] data = plot_data.get(index);

        // Mark data points.
        g2.setPaint(plot_colors.get(index));

        for (int i = 0; i < data.length; i++) {
          double x = PAD + i * xInc;
          double y = h - PAD - scale * data[i];
          g2.fill(new Ellipse2D.Double(x - pointSize / 2, y - pointSize / 2, pointSize, pointSize));
        }

        g2.setFont(textFont);
        int stringHeight =
            (int) g2.getFontMetrics().getStringBounds(plot_names.get(index), g2).getHeight();
        g.drawString(plot_names.get(index), PAD + 20, PAD + (index + 1) * stringHeight);
      }
    }
Esempio n. 13
0
 /*
  * Draws my name, class, date, assignment #, and label
  * Drawn in the Center
  */
 public static void Branding(Graphics g, String str) {
   g.setColor(Color.black);
   g.drawString("Jordan Leithart", FRAME_WIDTH / 2, 20);
   g.drawString("CS 324", FRAME_WIDTH / 2, 35);
   g.drawString("March 14, 2014", FRAME_WIDTH / 2, 50);
   g.drawString("Assignment 4", FRAME_WIDTH / 2, 65);
   g.drawString(str, FRAME_WIDTH / 2, 80);
 }
Esempio n. 14
0
 public void displayInstructions(Graphics g) {
   // Slightly freshened the look of the intro page.
   g.drawRect(128, 100, 250, 150); // decorative rectangles
   g.drawRect(122, 95, 260, 162);
   g.drawString("Welcome to Snake", 200, 130); // Centered instructions
   g.drawString("Press any key to start", 195, 150);
   g.drawString("Press 'q' to quit", 210, 170);
 }
Esempio n. 15
0
 public void displayScore2(
     Graphics g, int cx, int cy, int sx1, int sy1, int sx2, int sy2, int sx3, int sy3) {
   g.setFont(scoreFont);
   g.setColor(Color.WHITE);
   g.drawImage(new ImageIcon("InGameMenu/coin.png").getImage(), cx, cy, this);
   g.drawString("" + coins, sx1, sy1);
   g.drawString("Score:  " + score, sx2, sy2);
   g.drawString("Height:  " + height + " m", sx3, sy3);
 }
Esempio n. 16
0
 /**
  * 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);
 }
Esempio n. 17
0
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   int x = 20, y = 30;
   String ch1 = "bonjour";
   String ch2 = "monsieur";
   g.drawString(ch1, x, y);
   FontMetrics fm = g.getFontMetrics();
   y += fm.getHeight();
   g.drawString(ch2, x, y);
 }
Esempio n. 18
0
  /*
   *  Draws and labels the axes
   */
  public static void DrawAxes(Graphics g) {
    String num = "";
    Point2D tmpPoint = new Point2D(0, 0);
    drawPoint drawer = new drawPoint(0, 0);
    // X axis
    Point3D PointToDraw = new Point3D(curWin.RightX, 0, 0);
    Move3D(PointToDraw, IDENTITY, CAMERA);

    PointToDraw.SetCoords(curWin.LeftX, 0, 0);
    Draw3D(g, PointToDraw, IDENTITY, CAMERA);

    for (double i = curWin.LeftX; i <= curWin.RightX; i += 0.5) {
      if (i == 0.0) continue;
      PointToDraw.SetCoords(i, 0, 0);

      num = "" + i;
      Move3D(PointToDraw, IDENTITY, CAMERA);
      drawer = ViewPortToFrameWindow(curPos);
      g.drawString(num, drawer.x, drawer.y);
    }

    // y-axis
    PointToDraw.SetCoords(0, curWin.TopY - 1, 0);
    Move3D(PointToDraw, IDENTITY, CAMERA);

    PointToDraw.SetCoords(0, curWin.BotY, 0);
    Draw3D(g, PointToDraw, IDENTITY, CAMERA);

    for (double i = curWin.BotY; i <= curWin.TopY - 1; i += 0.5) {
      if (i == 0.0) continue;
      PointToDraw.SetCoords(0.1, i, 0);

      num = "" + i;
      Move3D(PointToDraw, IDENTITY, CAMERA);
      drawer = ViewPortToFrameWindow(curPos);
      g.drawString(num, drawer.x, drawer.y);
    }

    // z-axis
    PointToDraw.SetCoords(0, 0, 4); // 4 is to keep it on the screen
    Move3D(PointToDraw, IDENTITY, CAMERA);

    PointToDraw.SetCoords(0, 0, -4); // keep it on the screen
    Draw3D(g, PointToDraw, IDENTITY, CAMERA);

    for (double i = -4.0; i <= 4.0; i += 0.5) {
      if (i == 0.0) continue;
      PointToDraw.SetCoords(0, 0.1, i);

      num = "" + i;
      Move3D(PointToDraw, IDENTITY, CAMERA);
      drawer = ViewPortToFrameWindow(curPos);
      g.drawString(num, drawer.x, drawer.y);
    }
  }
Esempio n. 19
0
  // Draws the Battle Menu
  public void drawMenu(Graphics g) {
    if (scene == BATTLE) {
      // Background
      g.setColor(new Color(0, 100, 0));
      g.fillRect(0, 450, 800, 150);
      g.setColor(Color.BLACK);
      g.fillRect(10, 460, 780, 130);

      // Player
      // Health
      g.setColor(Color.WHITE);
      g.setFont(new Font("Bell MT", Font.BOLD, 20));
      FontMetrics metrics = g.getFontMetrics(new Font("Bell MT", Font.BOLD, 20));
      int hgt = metrics.getHeight();
      // Hgt = 26
      int adv = metrics.stringWidth(player.getHealth() + "/" + player.getMaxHealth(0));
      g.setColor(Color.DARK_GRAY);
      g.fillRect(getWidth() - 170, 470, 150, hgt - 6);
      if ((double) player.getHealth() / player.getMaxHealth(0) > .25) g.setColor(Color.RED);
      else g.setColor(player.getLowHealth());
      g.drawString(
          player.getHealth() + "/" + player.getMaxHealth(0), getWidth() - adv - 180, 461 + hgt);
      g.fillRect(
          getWidth() - 167,
          473,
          (int) (144 * player.getHealth() / player.getMaxHealth(0)),
          hgt - 12);

      // Stamina
      g.setColor(Color.DARK_GRAY);
      g.fillRect(getWidth() - 170, 500, 150, hgt - 6);
      adv = metrics.stringWidth((int) player.getStamina() + "%");
      if (player.getStamina() < 33.3) g.setColor(Color.WHITE);
      else if (player.getStamina() == 100) g.setColor(Color.GREEN);
      else g.setColor(Color.CYAN);

      g.drawString((int) player.getStamina() + "%", getWidth() - adv - 180, 491 + hgt);
      g.fillRect(getWidth() - 167, 503, (int) (144 * player.getStamina() / 100), hgt - 12);

      // Basic Attack
      adv = metrics.stringWidth("Kick Dirt");
      g.setColor(Color.DARK_GRAY);
      g.fillRect(20, 470, adv + 10, 30);
      g.setColor(Color.WHITE);
      g.drawString("Kick Dirt", 25, 492);

      // Spell 1
      adv = metrics.stringWidth("Hurl Pebble");
      g.setColor(Color.DARK_GRAY);
      g.fillRect(20, 510, adv + 10, 30);
      g.setColor(Color.WHITE);
      g.drawString("Hurl Pebble", 25, 532);
    }
  }
Esempio n. 20
0
 private void reportStats(Graphics g)
       // Report the number of hits, and time spent playing
     {
   if (!gameOver) // stop incrementing the timer once the game is over
   timeSpentInGame = (int) ((System.nanoTime() - gameStartTime) / 1000000000L); // ns --> secs
   g.setColor(Color.red);
   g.setFont(msgsFont);
   g.drawString("Hits: " + numHits + "/" + MAX_HITS, 15, 25);
   g.drawString("Time: " + timeSpentInGame + " secs", 15, 50);
   g.setColor(Color.black);
 } // end of reportStats()
  public void paintComponent(Graphics g) { // paintComponent

    super.paintComponent(g); // refresh screen (paint background)

    Font f = new Font("Helvetica", Font.BOLD, 40);
    g.setFont(f);
    g.drawString("DON'T ABUSE", 40, 130);
    g.drawString("SUBSTANCES", 40, 180);
    f = new Font("Helvetica", Font.BOLD, 50);
    g.setFont(f);
    g.drawString("KIDS", 120, 240);
  }
 public void displayMetrics(Graphics g) {
   leading = g.getFontMetrics().getLeading();
   ascent = g.getFontMetrics().getAscent();
   descent = g.getFontMetrics().getDescent();
   height = g.getFontMetrics().getHeight();
   g.drawString(movieQuote, x, y += height);
   g.drawString("Leading is " + leading, x, y += height);
   g.drawString("Ascent is " + ascent, x, y += height);
   g.drawString("Descent is " + descent, x, y += height);
   g.drawString("Height is " + height, x, y += height);
   y += height * 2;
 }
  private void drawSkillName(
      Graphics g, String skillText, Rectangle2D textRect, int skillBoxY, int skillBoxX) {
    // Get width and Y pos.
    int skillNameWidth = (int) textRect.getWidth();
    int skillStringY = skillBoxY + (skillRectHeight - (int) textRect.getHeight()) + fm.getAscent();

    // if text is 2 long for the box... Split that shit up boiii
    if (skillNameWidth > skillBoxSize) {
      // Split by whitespace
      String[] arr = skillText.split(" ");
      String curr;
      Rectangle2D textRect2;

      // Loop thru each substring from the end and draw appropriately
      for (int j = arr.length - 1; j >= 0; j--) {
        curr = arr[j];
        textRect = fm.getStringBounds(curr, g);
        // If this substring is less than half the width of the box and theres anotha substring
        if ((int) textRect.getWidth() < skillBoxSize / 2 && j != 0) {
          // Get and measure the otha 1
          String anotha1 = arr[j - 1];
          textRect2 = fm.getStringBounds(anotha1, g);

          // Draw both on the same line if can fit
          int combinedW = (int) textRect.getWidth() + (int) textRect2.getWidth() + 2;
          String combined = anotha1 + " " + curr;
          if (combinedW < skillBoxSize) {
            g.drawString(combined, skillBoxX + (skillBoxSize - combinedW) / 2, skillStringY);
            j--;
          }
          // Otherwise, draw one of those suckas
          else {
            g.drawString(
                curr, skillBoxX + (skillBoxSize - (int) textRect.getWidth()) / 2, skillStringY);
          }
        }
        // Otherwise, draw one of those suckas
        else {
          g.drawString(
              curr, skillBoxX + (skillBoxSize - (int) textRect.getWidth()) / 2, skillStringY);
        }

        // Decrease dat Y
        skillStringY -= (int) textRect.getHeight();
      }

    } else {
      g.drawString(
          skillText,
          skillBoxX + (skillBoxSize - skillNameWidth) / 2,
          skillBoxY + (skillRectHeight - (int) textRect.getHeight()) + fm.getAscent());
    }
  }
Esempio n. 24
0
  public void paintComponent(Graphics g) {

    // HEADER CONTROL
    g.drawString("Name", 20, 40);
    g.drawOval(130, 20, 75, 30);
    g.drawString("Me", 160, 40);
    g.drawOval(230, 20, 75, 30);
    g.drawString("Other", 250, 40);
    g.drawOval(330, 20, 75, 30);
    g.drawString("Win", 360, 40);
    g.drawOval(430, 20, 75, 30);
    g.drawString("Loose", 450, 40);
  }
Esempio n. 25
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    height = this.getHeight();
    width = this.getWidth();

    drawPlayers(g);
    g.setColor(Color.WHITE);
    g.drawString("Score", width - 60, 25);
    g.drawString(String.valueOf(score), width - 60, 40);

    if (countdownF) {
      g.drawString(String.valueOf(counterN), width / 2 - 10, height / 2);
    } else {
      if ((spawnCircleB) && (spawnIncrease)) {
        spawnCircles();
      }
      if (spawnMonsterB) {
        spawnMonsters();
      }
      if (spawnRandomersB) {
        spawnRandomers();
      }
      if (spawnRainB) {
        spawnRain();
      }
      if (spawnBombB()) {
        spawnBomb();
      }

      try {
        Iterator i = enemies.iterator();
        while (i.hasNext()) {
          Enemy e = (Enemy) i.next();
          Iterator j = players.iterator();
          while (j.hasNext()) {
            Player p = (Player) j.next();
            e.move(players, programSpeedAdjust /*/players.size()*/);
            if ((e.collidesWith(p.getX(), p.getY())) && (!p.getImmunity())) {
              p.decLives(p.getX(), p.getY());
              p.setImmunity(true);
            }
          }
          e.paint(g);
        }
      } catch (Exception e) {
      }
    }
    drawLayout(g);
  }
Esempio n. 26
0
 public static void titlePage(Graphics g, String name, int period) {
   Expo.setBackground(g, Expo.gold);
   Expo.setColor(g, Expo.white);
   Expo.fillRectangle(g, 100, 100, 900, 550);
   Expo.setColor(g, Expo.red);
   Font title = new Font("Algerian", Font.BOLD, 48);
   g.setFont(title);
   g.drawString("Flags of the World", 225, 240);
   Expo.setColor(g, Expo.blue);
   g.drawString("by: " + name, 225, 340);
   Expo.setColor(g, Expo.green);
   g.drawString("Period: " + period, 225, 440);
   Expo.delay(3000); // Wait 3 second before showing first flag.
 }
 private void showStats(Graphics g, int panelHeight) {
   // write statistics in bottom-left corner
   g.setFont(msgFont);
   if (imageCount > 0) {
     g.setColor(Color.YELLOW);
     double avgGrabTime = (double) totalTime / imageCount;
     g.drawString(
         "Pic " + imageCount + "  " + df.format(avgGrabTime) + " ms",
         5,
         panelHeight - 10); // bottom left
   } else { // no image yet
     g.setColor(Color.BLUE);
     g.drawString("Loading...", 5, panelHeight - 10);
   }
 } // end of showStats()
Esempio n. 28
0
 public void drawDefeat(Graphics g) {
   g.setColor(new Color(0, 0, 0, 200));
   g.fillRect(195, 220, 410, 110);
   g.setColor(new Color(255, 255, 255, 200));
   g.fillRect(200, 225, 400, 100);
   g.setColor(new Color(0, 0, 0, 200));
   g.setFont(new Font("Bell MT", Font.BOLD, 20));
   FontMetrics metrics = g.getFontMetrics(new Font("Bell MT", Font.BOLD, 20));
   int hgt = metrics.getHeight();
   // Hgt = 26
   int adv = metrics.stringWidth("You all fainted.");
   g.drawString("You all fainted.", getWidth() / 2 - adv / 2, 234 + hgt);
   adv = metrics.stringWidth("Defenseless, you are all eaten.");
   g.drawString("Defenseless, you are all eaten.", getWidth() / 2 - adv / 2, 269 + hgt);
 }
Esempio n. 29
0
  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);
  }
 // Show a message over frozen image in the display
 public void showMessage(String message) {
   Graphics g = getGraphics();
   g.setColor(Color.black);
   g.fillRect(30, (getHeight() / 2) - 16, message.length() * 10, 25);
   g.setColor(Color.white);
   g.drawString(message, 40, getHeight() / 2);
 }