コード例 #1
0
  public void paint(Graphics gOld) {
    if (image == null || xsize != getSize().width || ysize != getSize().height) {
      xsize = getSize().width;
      ysize = getSize().height;
      image = createImage(xsize, ysize);
      g = (Graphics2D) image.getGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }
    // fill background
    g.setColor(Color.cyan);
    g.fillRect(0, 0, xsize, ysize);

    int x[] = {getX(0), getX(getWidth2()), getX(getWidth2()), getX(0), getX(0)};
    int y[] = {getY(0), getY(0), getY(getHeight2()), getY(getHeight2()), getY(0)};
    // fill border
    g.setColor(Color.black);
    g.fillPolygon(x, y, 4);
    // draw border
    g.setColor(Color.red);
    g.drawPolyline(x, y, 5);
    if (animateFirstTime) {
      gOld.drawImage(image, 0, 0, null);
      return;
    }
    if (gameOver) return;
    g.drawImage(outerSpaceImage, getX(0), getY(0), getWidth2(), getHeight2(), this);
    for (int index = 0; index < missile.length; index++) {
      if (missile[index].active) {
        g.setColor(Color.red);
        drawCircle(getX(missile[index].xPos), getYNormal(missile[index].yPos), 90, .3, 1.5);
      }
    }
    if (rocketRight) {
      drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, 2.0, 2.0);
    } else {
      drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, -2.0, 2.0);
    }
    for (int index = 0; index < numStars; index++) {
      g.setColor(Color.yellow);
      if (starActive[index])
        drawCircle(getX(starXPos[index]), getYNormal(starYPos[index]), 0, 1.5, 1.5);
    }
    g.setColor(Color.magenta);
    g.setFont(new Font("Impact", Font.BOLD, 15));
    g.drawString("Score: " + score, 10, 45);
    g.setColor(Color.magenta);
    g.setFont(new Font("Impact", Font.BOLD, 15));
    g.drawString("HighScore: " + highScore, 300, 45);
    g.setColor(Color.magenta);
    g.setFont(new Font("Impact", Font.BOLD, 15));
    g.drawString("Lives: " + rocketLife, 150, 45);
    if (rocketLife == 0) {
      g.setColor(Color.red);
      g.setFont(new Font("Impact", Font.BOLD, 60));
      g.drawString("GAME OVER", getX(getWidth2() / 6), getYNormal(getHeight2() / 2));
    }
    gOld.drawImage(image, 0, 0, null);
  }
コード例 #2
0
  public void drawFunctionToGraphic(Graphics2D g, int x, int y, int UNITYX, int UNITYY) {
    int _x, _y;

    g.setColor(Color.red);
    g.drawString("f(x) = " + F.toString(), 15, 20);

    g.setColor(Color.blue);
    for (double i = 0; ; i += EPSILON) {
      _x = (int) (i * UNITYX) + x / 2;
      _y = -(int) (F.evaluate(i) * UNITYY) + y / 2;

      g.drawLine(
          _x,
          _y,
          (int) ((i + EPSILON) * UNITYX) + x / 2,
          -(int) (F.evaluate(i + EPSILON) * UNITYY) + y / 2);

      if (_x < 0 || _x > x || _y < 0 || _y > y) break;
    }

    for (double i = 0; ; i -= EPSILON) {
      _x = (int) (i * UNITYX) + x / 2;
      _y = -(int) (F.evaluate(i) * UNITYY) + y / 2;

      g.drawLine(
          _x,
          _y,
          (int) ((i + EPSILON) * UNITYX) + x / 2,
          -(int) (F.evaluate(i + EPSILON) * UNITYY) + y / 2);

      if (_x < 0 || _x > x || _y < 0 || _y > y) break;
    }
  }
コード例 #3
0
ファイル: FTACanvas.java プロジェクト: jandcmoore/OpenFTA
  private void drawString(String str, int x, int y) {

    // text does not work correctly for very small scales.
    if (textEnabled && scale > 0.05) {
      gRef.drawString(str, x, y);
    }
  }
コード例 #4
0
ファイル: KeyTest.java プロジェクト: Gogoro/Undef
 // draw on screen
 public synchronized void draw(Graphics2D g) {
   Window w = s.getFullScreenWindow();
   g.setColor(w.getBackground());
   g.fillRect(0, 0, s.getWidth(), s.getHeight());
   g.setColor(w.getForeground());
   g.drawString(mess, 100, 100);
 }
コード例 #5
0
ファイル: GeoBall.java プロジェクト: nbitesGuest/nbites
 public void draw(Graphics2D g2, boolean shouldFlip) {
   Font font = new Font("Sans_Serif", Font.PLAIN, 30);
   g2.setColor(Color.orange);
   g2.fillOval((int) x - 10, (int) (FieldConstants.FIELD_HEIGHT - y - 10), 20, 20);
   font = new Font("Sans_Serif", Font.PLAIN, 18);
   g2.setFont(font);
   g2.drawString(Double.toString(confidence), x, FieldConstants.FIELD_HEIGHT - y + 60);
 }
コード例 #6
0
 static void renderSplashFrame(Graphics2D g, int frame) {
   final String[] comps = {"foo", "bar", "baz"};
   g.setComposite(AlphaComposite.Clear);
   g.fillRect(120, 140, 200, 40);
   g.setPaintMode();
   g.setColor(Color.BLACK);
   g.drawString("Loading " + comps[(frame / 5) % 3] + "...", 120, 150);
 }
コード例 #7
0
ファイル: My29.java プロジェクト: Buzov/Java_lesson
  public void paintComponent(Graphics g) {
    // необходиом чтобы текст коректно отрисовывался в окне
    super.paintComponent(g);
    // рисуем текст в окне
    Graphics2D g2 = (Graphics2D) g;
    AffineTransform t = g2.getTransform();
    g.drawString("It is text", 5, 5);
    // создание шрифта
    Font f = new Font("SanasSerif", Font.ITALIC, 20);
    g2.setFont(f);
    g2.drawString("It is new text", 5, 33);
    String[] fontNames =
        GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    for (int i = 5; i < 20; i++) {
      g2.rotate(-0.05);
      g2.setColor(
          new Color(
              (int) (Math.random() * 255),
              (int) (Math.random() * 255),
              (int) (Math.random() * 255)));
      Font f1 = new Font(fontNames[i], Font.BOLD, 20);
      g2.setFont(f1);
      g2.drawString(fontNames[i], 5, 20 * i);
    }
    // текст в центре

    g2.setTransform(t); // возращение к кординатам, которые запонилив начале
    Font f2 = new Font("SanasSerif", Font.ITALIC, 20);
    g2.setFont(f2);
    String s = "It is center!";
    FontRenderContext context = g2.getFontRenderContext();
    Rectangle2D r = f2.getStringBounds(s, context);
    double x1 = (getWidth() - r.getWidth()) / 2;
    double y1 = (getHeight() - r.getHeight()) / 2;
    double ascent = -r.getY(); // узнаем высоту текста
    double y2 = y1 + ascent;
    Rectangle2D rect = new Rectangle2D.Double(x1, y1, r.getWidth(), r.getHeight());
    g2.setColor(Color.YELLOW);
    g2.fill(rect);
    g2.setColor(Color.red);
    g2.drawString(s, (int) x1, (int) y2);
    g2.setColor(Color.blue);
    g2.draw(new Line2D.Double(x1, y2, x1 + r.getWidth(), y2));

    g2.draw(rect);
  }
コード例 #8
0
 ////////////////////////////////////////////////////////////////////////////
 // Paint
 //
 public synchronized void paint(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   // Graphics2D buffGraphics2 = (Graphics2D) buffGraphics;
   //    g2.drawImage(bImage, 3, 3, getWidth() - 3, getHeight() - 3,
   //        0, 0, iWidth, iHeight, null);
   g2.drawImage(bImage, 0, 0, iWidth, iHeight, null);
   g2.drawString(String.valueOf(System.currentTimeMillis()), 10, 10);
 }
コード例 #9
0
ファイル: StdDraw.java プロジェクト: ihordey/algorithms-4th
 /**
  * Write the given text string in the current font, left-aligned at (x, y).
  *
  * @param x the x-coordinate of the text
  * @param y the y-coordinate of the text
  * @param s the text
  */
 public static void textLeft(double x, double y, String s) {
   offscreen.setFont(font);
   FontMetrics metrics = offscreen.getFontMetrics();
   double xs = scaleX(x);
   double ys = scaleY(y);
   int hs = metrics.getDescent();
   offscreen.drawString(s, (float) (xs), (float) (ys + hs));
   draw();
 }
コード例 #10
0
  /** Draw vertices on top of the edge structure */
  public void drawNodes(Graphics2D gg) {
    Enumeration nodeList = argument.getBreadthFirstTraversal().elements();
    // Run through the traversal and draw each vertex
    // using an Ellipse2D
    // The draw point has been determined previously in
    // calcNodeCoords()
    while (nodeList.hasMoreElements()) {
      TreeVertex vertex = (TreeVertex) nodeList.nextElement();
      // Don't draw virtual nodes
      if (vertex.isVirtual()) continue;

      // If tree is incomplete and we're on the top layer, skip it
      if (argument.isMultiRoots() && vertex.getLayer() == 0) continue;

      Point corner = vertex.getDrawPoint();
      Shape node = new Ellipse2D.Float(corner.x, corner.y, NODE_DIAM, NODE_DIAM);
      vertex.setShape(node, this);

      // Fill the interior of the node with vertex's fillPaint
      gg.setPaint(vertex.fillPaint);
      gg.fill(node);

      // Draw the outline with vertex's outlinePaint; bold if selected
      gg.setPaint(vertex.outlinePaint);
      if (vertex.isSelected()) {
        gg.setStroke(selectStroke);
      } else {
        gg.setStroke(solidStroke);
      }
      gg.draw(node);

      // Draw the short label on top of the vertex
      gg.setPaint(vertex.textPaint);
      String shortLabelString = new String(vertex.getShortLabel());
      if (shortLabelString.length() == 1) {
        gg.setFont(labelFont1);
        gg.drawString(shortLabelString, corner.x + NODE_DIAM / 4, corner.y + 3 * NODE_DIAM / 4);
      } else if (shortLabelString.length() == 2) {
        gg.setFont(labelFont2);
        gg.drawString(shortLabelString, corner.x + NODE_DIAM / 5, corner.y + 3 * NODE_DIAM / 4);
      }
    }
  }
コード例 #11
0
ファイル: graphPanel.java プロジェクト: TUDelftNAS/graphGEAR
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (nodes.get(0) == null) {
      return;
    }
    Graphics2D g2 = (Graphics2D) g;
    g2.setColor(Color.blue);
    int x = 0;
    int y = 0;
    double xs = (double) (this.getWidth() - b - (nodes.get(0).r * nodeScaling));
    double ys = (double) (this.getHeight() - b - (nodes.get(0).r * nodeScaling) - noticeBorder);
    g2.setColor(Color.black);
    g2.fillRect(0, 0, this.getWidth(), this.getHeight());
    g2.setColor(Color.blue);
    drawNode s;
    drawNode d;
    RenderingHints rh =
        new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHints(rh);
    g2.setColor(Color.white);
    if (!ignoreLinks) {
      for (drawLink L : links.values()) {
        g2.setColor(L.color);
        s = nodes.get(L.sid);
        d = nodes.get(L.eid);
        if (s != null && d != null) {
          g2.drawLine(
              (int) ((s.x * xs) + (s.r * nodeScaling) / 2d),
              (int) ((s.y * ys) + (s.r * nodeScaling) / 2d),
              (int) ((d.x * xs) + (d.r * nodeScaling) / 2d),
              (int) ((d.y * ys) + (d.r * nodeScaling) / 2d));
        }
      }
    }
    for (drawNode N : nodes.values()) {
      g2.setColor(N.color);
      g2.fill(new Ellipse2D.Double(N.x * xs, N.y * ys, N.r * nodeScaling, N.r * nodeScaling));
      g2.setColor(Color.black);
      g2.draw(new Ellipse2D.Double(N.x * xs, N.y * ys, N.r * nodeScaling, N.r * nodeScaling));
    }
    if (showInfoForNode != -1 && nodeInfo.containsKey(showInfoForNode)) {
      drawNode N = nodes.get(showInfoForNode);

      x = (int) (N.x * xs + N.r * nodeScaling) + 3;
      y = (int) (N.y * ys);
      CTB.flipShift = (int) (N.r * nodeScaling) + 5;
      CTB.draw(g2, x, y, this.getWidth(), this.getHeight(), nodeInfo.get(showInfoForNode));
    }
    g2.setColor(Color.white);
    g2.setFont(new Font("Arial", Font.PLAIN, 10));
    g2.drawString("Ruud van de Bovenkamp - NAS", b, this.getHeight() - b);
    doneDrawing = true;
  }
コード例 #12
0
ファイル: SpaceDodger.java プロジェクト: PCW888/SpaceDodger
 /** Draws a message centered in the window. */
 private void drawMessage(Graphics2D g2, String message) {
   g2.setColor(Color.WHITE);
   g2.setFont(new Font("serif", Font.PLAIN, 72));
   // Calculate the size of the text so we can center it in the window
   FontMetrics metrics = g2.getFontMetrics();
   Rectangle2D textBounds = metrics.getStringBounds(message, g2);
   g2.drawString(
       message,
       windowWidth / 2 - (int) textBounds.getCenterX(),
       windowHeight / 2 - (int) textBounds.getCenterY());
 }
コード例 #13
0
    protected BufferedImage makeImage() {
      BufferedImage image =
          new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_4BYTE_ABGR);
      Graphics2D g = image.createGraphics();

      g.setPaint(Color.WHITE);
      g.fill3DRect(0, 0, IMAGE_SIZE, IMAGE_SIZE, false);

      g.setPaint(Color.RED);
      g.setFont(Font.decode("ARIAL-BOLD-50"));

      g.drawString(Long.toString(++this.counter) + " frames", 10, IMAGE_SIZE / 4);
      g.drawString(
          Long.toString((System.currentTimeMillis() - start) / 1000) + " sec", 10, IMAGE_SIZE / 2);
      g.drawString(
          "Heap:" + Long.toString(Runtime.getRuntime().totalMemory()), 10, 3 * IMAGE_SIZE / 4);

      g.dispose();

      return image;
    }
コード例 #14
0
 public void draw(Graphics2D g) {
   g.setColor(fillColor);
   g.fill(gp);
   g.setColor(Color.black);
   g.draw(gp);
   for (int i = 0; i < points.size(); i++) {
     GlyphPoint p = points.get(i);
     g.setColor(Color.red);
     g.draw(p.gp);
     g.setColor(Color.blue);
     g.setFont(gfont);
     g.drawString(String.valueOf(i), p.x + 3, p.y + 3);
   }
   g.setColor(Color.black);
   //	    System.out.println("Advance: "+advance);
   g.draw(advp);
   if (name != null) {
     g.setFont(gfont);
     g.drawString(name, 0, -40);
   }
 }
コード例 #15
0
ファイル: Enviroment.java プロジェクト: BuyouT/COP3502
 @Override
 public void paintComponent(Graphics g) {
   g.setColor(Color.WHITE);
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   if (isDead) {
     g2.setColor(Color.BLACK);
     g2.setFont(new Font("Serif", Font.PLAIN, 30));
     g2.drawString("Game Over!", 300, 300);
     g2.drawString("Your final score was " + score, 250, 330);
     moverTimer.stop();
     scoreTimer.stop();
   } else {
     topWall.paint(g2);
     bottomWall.paint(g2);
     bird.paint(g2);
     g2.setColor(Color.BLACK);
     g2.setFont(new Font("Serif", Font.PLAIN, 20));
     g2.drawString("Score: " + score, 50, 50);
   }
 }
コード例 #16
0
ファイル: Breakout.java プロジェクト: BuyouT/COP3502
    @Override
    public void paintComponent(Graphics g) {
      super.paintComponent(g);
      Graphics2D g2 = (Graphics2D) g;

      // paint ball, paddle, and brick configuration
      g2.drawImage(background.getImage(), 0, 0, null);
      bconfig.paint(g2);
      paddle.paint(g2);
      ball.paint(g2);
      g2.setColor(Color.WHITE);
      g2.setFont(new Font("Serif", Font.PLAIN, 20));
      g2.drawString("Score: " + score, 15, 20);
      if (ball.getY() > 500) {
        g2.setColor(Color.WHITE);
        g2.setFont(new Font("Serif", Font.PLAIN, 30));
        g2.drawString("Game Over!", 200, 300);
        g2.drawString("Your final score was " + score, 150, 330);
        timer.stop();
      }
    }
コード例 #17
0
ファイル: Homework10.java プロジェクト: Sfhillier/YinYang
  @Override
  // TODO Auto-generated method stub
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;

    // Draws the two initial two YinYang symbols on the frame
    g2.setColor(color1);
    if (timeLeft < 6000) {
      g2.rotate(degrees, yin1X + (yin1Width / 2), yin1Y + (yin1Height / 2));
    }
    g2.fill(new MyYinYang(yin1X, yin1Y, yin1Width, yin1Height));
    if (timeLeft < 6000) {
      g2.rotate(-degrees, yin1X + (yin1Width / 2), yin1Y + (yin1Height / 2));
    }
    g2.setColor(color2);
    if (timeLeft < 6000) {
      g2.rotate(degrees, yin2X + (yin2Width / 2), yin2Y + (yin2Height / 2));
    }
    g2.fill(new MyYinYang(yin2X, yin2Y, yin2Width, yin2Height));
    if (timeLeft < 6000) {
      g2.rotate(-degrees, yin2X + (yin2Width / 2), yin2Y + (yin2Height / 2));
    }

    // Alters and prints the text on the screen
    g2.setColor(Color.BLACK);
    g2.setFont(font);
    g2.drawString("Score", 700, 25);
    g2.drawString(Integer.toString(points), 700, 75);
    g2.drawString("Misses", 800, 25);
    g2.drawString(Integer.toString(misses), 800, 75);
    g2.drawString("Time Left", 700, 110);
    timeDisplay = timeLeft / 100.0;
    g2.drawString(timeDisplay.toString(), 700, 160);
  }
コード例 #18
0
    public void paintComponent(Graphics g) {
      super.paintComponent(g);

      Graphics2D g2 = (Graphics2D) g;

      if (!text.equals("")) {
        g2.translate(0, getSize().getHeight());
        g2.rotate(-Math.PI / 2);
        g2.setColor(Color.black);
        g2.drawString(text, 20, 14);

        g2.translate(0, -getSize().getHeight());
        g2.transform(AffineTransform.getQuadrantRotateInstance(1));
      }
    }
コード例 #19
0
 void drawMessage(Graphics2D g2d) {
   if (promptMsg == null) {
     return;
   }
   g2d.setFont(fontMsg);
   g2d.setColor(new Color(1f, 1f, 1f, 1));
   int sw = g2d.getFontMetrics().stringWidth(promptMsg);
   int sh = g2d.getFontMetrics().getMaxAscent();
   Rectangle ubound = (new ScreenUnion()).getBounds();
   for (int i = 0; i < Screen.getNumberScreens(); i++) {
     Rectangle bound = Screen.getBounds(i);
     int cx = bound.x + (bound.width - sw) / 2 - ubound.x;
     int cy = bound.y + (bound.height - sh) / 2 - ubound.y;
     g2d.drawString(promptMsg, cx, cy);
   }
 }
コード例 #20
0
 protected float drawBoxedString(Graphics2D g2, String s, Color c1, Color c2, double x) {
   // Calculate the width of the string.
   FontRenderContext frc = g2.getFontRenderContext();
   TextLayout subLayout = new TextLayout(s, mFont, frc);
   float advance = subLayout.getAdvance();
   // Fill the background rectangle with a gradient.
   GradientPaint gradient = new GradientPaint((float) x, 0, c1, (float) (x + advance), 0, c2);
   g2.setPaint(gradient);
   Rectangle2D bounds = mLayout.getBounds();
   Rectangle2D back = new Rectangle2D.Double(x, 0, advance, bounds.getHeight());
   g2.fill(back);
   // Draw the string over the gradient rectangle.
   g2.setPaint(Color.white);
   g2.setFont(mFont);
   g2.drawString(s, (float) x, (float) -bounds.getY());
   return advance;
 }
コード例 #21
0
  public void paintComponent(Graphics gr) {
    Graphics2D g = (Graphics2D) gr;
    Object oldHints = QuaquaUtilities.beginGraphics((Graphics2D) g);

    g.drawImage(crayonsImage, 0, 0, this);

    if (selectedCrayon != null) {
      /*
      g.setColor(new Color(0x60ffffff & selectedCrayon.color.getRGB(),true));
      g.fill(selectedCrayon.shape);
       */
      g.setColor(getForeground());
      FontMetrics fm = g.getFontMetrics();
      int nameWidth = fm.stringWidth(selectedCrayon.name);
      g.drawString(
          selectedCrayon.name, (crayonsImage.getWidth(this) - nameWidth) / 2, fm.getAscent() + 1);
    }
    QuaquaUtilities.endGraphics((Graphics2D) g, oldHints);
  }
コード例 #22
0
ファイル: DrawPanel.java プロジェクト: GustavRibom/Test
  public void drawBuffer() {
    Graphics2D b = buffer.createGraphics();

    b.setColor(Color.black);
    b.fillRect(0, 0, 800, 600);

    if (hast.collision == false) {
      b.setColor(Color.red);
      b.fillRect(hast.getX(), hast.getY(), hast.getWidth(), hast.getHeight());

      for (int i = 0; i < 20; i++) {
        b.setColor(Color.blue);
        b.fillRect(box[i].getX(), box[i].getY(), box[i].getWidth(), box[i].getHeight());
      }

      b.dispose();
    } else b.setColor(Color.white);
    b.drawString("Horsie is DEAD!!!!", 350, 300);
    b.dispose();
  }
コード例 #23
0
 public void draw(
     Graphics2D g,
     Color stringColor,
     Color foreground,
     Color background,
     String info,
     double x,
     double y) {
   FontMetrics fm = g.getFontMetrics();
   int h = fm.getHeight();
   int w = fm.stringWidth(info);
   r1.setRect(
       x - w / 2 - in.left, y - in.top - h / 2, w + in.right + in.left, h + in.bottom + in.top);
   g.setColor(background);
   g.fill(r1);
   g.setColor(stringColor);
   g.draw(r1);
   g.setColor(foreground);
   r2.setRect(r1.getX() + 1, r1.getY() + 1, r1.getWidth() - 2, r1.getHeight() - 2);
   g.draw(r2);
   g.setColor(stringColor);
   g.drawString(
       info, (float) (r2.getX() + in.left), (float) (r2.getY() + h - (r2.getHeight() - h) / 2));
 }
コード例 #24
0
ファイル: TerminalPanel.java プロジェクト: bitekas/jediterm
  private void drawInputMethodUncommitedChars(Graphics2D gfx) {
    if (myInputMethodUncommitedChars != null && myInputMethodUncommitedChars.length() > 0) {
      int x = myCursor.getCoordX() * myCharSize.width;
      int y = (myCursor.getCoordY()) * myCharSize.height - 2;

      int len = (myInputMethodUncommitedChars.length()) * myCharSize.width;

      gfx.setColor(getBackground());
      gfx.fillRect(x, (myCursor.getCoordY() - 1) * myCharSize.height, len, myCharSize.height);

      gfx.setColor(getForeground());
      gfx.setFont(myNormalFont);

      gfx.drawString(myInputMethodUncommitedChars, x, y);
      Stroke saved = gfx.getStroke();
      BasicStroke dotted =
          new BasicStroke(
              1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, new float[] {0, 2, 0, 2}, 0);
      gfx.setStroke(dotted);

      gfx.drawLine(x, y, x + len, y);
      gfx.setStroke(saved);
    }
  }
コード例 #25
0
  public void onRepaint(Graphics g1) {
    Graphics2D g = (Graphics2D) g1;
    String paintText = "Hide Paint";

    if (hidePaint) {
      paintText = "Show Paint";
      g.setColor(color1);
      g.fillRoundRect(closePaint.x, closePaint.y, closePaint.width, closePaint.height, 16, 16);
      g.setColor(color3);
      g.drawString(paintText, 435, 27);
    } else {
      g.setColor(color2);
      g.fillRoundRect(closePaint.x, closePaint.y, closePaint.width, closePaint.height, 16, 16);
      g.setColor(color3);
      g.drawString(paintText, 438, 27);

      final int skillPercent = skills.getPercentToNextLevel(Skills.FARMING);
      final int skillXP = skills.getExpToNextLevel(Skills.FARMING);
      final String xpToLevel;
      if (skillXP >= 1000) xpToLevel = Integer.toString(skillXP / 1000) + "k";
      else xpToLevel = Integer.toString(skillXP);
      final int nextLevel = skills.getRealLevel(Skills.FARMING) + 1;
      final int profit = marketPriceOfHerbs * numHerbsFarmed - marketPriceOfSeeds * numSeedsPlanted;
      final String profitMade;
      if (profit >= 100000) profitMade = Integer.toString(profit / 1000) + "k";
      else profitMade = Integer.toString(profit);

      String displayStatus = status;
      if (displayStatus == "Breaking while herbs grow: ")
        displayStatus += breakTimer.toRemainingString();

      int mouseX, mouseY;
      mouseX = (int) mouse.getLocation().getX();
      mouseY = (int) mouse.getLocation().getY();

      g.setColor(color1);
      g.drawLine(mouseX - 1000, mouseY, mouseX + 1000, mouseY);
      g.drawLine(mouseX, mouseY - 1000, mouseX, mouseY + 1000);
      g.fillRect(69, 320, 450, 21);
      g.setColor(color2);
      g.fillRect(69, 320, 450 * skillPercent / 100, 21);
      g.drawImage(img1, 0, 243, null);
      g.setFont(font1);
      g.drawString("Version: " + scriptVersion, 431, 471);
      g.setColor(color3);
      g.drawString(skillPercent + "% to level " + nextLevel + " (" + xpToLevel + " xp)", 216, 334);
      g.setColor(color1);
      g.drawString("Time Running: " + runTime.toElapsedString(), 102, 398);
      g.drawString("Herbs Farmed: " + numHerbsFarmed, 319, 399);
      g.drawString("Profit Made: " + profitMade, 319, 416);
      g.drawString("Seeds Planted: " + numSeedsPlanted, 102, 415);
      g.drawString("Seed Type: " + seedType, 102, 431);
      g.drawString("Status: " + displayStatus, 102, 449);

      if (currentLocation == Location.ARDOUGNE)
        for (int i = 1; i < camelotPath.length; i++) camelotPath[i].drawTo(g1, camelotPath[i - 1]);
      if (currentLocation == Location.CAMELOT)
        for (int i = 1; i < faladorPath.length; i++) faladorPath[i].drawTo(g1, faladorPath[i - 1]);
      if (currentLocation == Location.FALADOR)
        for (int i = 1; i < ardougnePath.length; i++)
          ardougnePath[i].drawTo(g1, ardougnePath[i - 1]);
    }
  }
コード例 #26
0
  public void paintComponent(java.awt.Graphics g) {
    if (offer == null || g == null) return;

    Graphics2D g2d = (Graphics2D) g;
    AffineTransform origTx = g2d.getTransform();
    AffineTransform at = new AffineTransform();

    int x = getSize().width;
    int y = getSize().height;

    int xGap = 25;
    int yGap = 35;

    int xPaint = x - xGap;
    int yPaint = y - yGap;

    int maxRows = offer.maxRows;
    int maxCols = offer.maxCols;

    g2d.setColor(Color.lightGray);
    g2d.clearRect(0, 0, x, y);

    double xDist = ((double) xPaint) / maxCols, yDist = ((double) yPaint) / maxRows;

    // I = resourcen
    for (int i = 0; i < maxCols; i++) {
      // J= farben
      for (int j = 0; j < maxRows; j++) {
        if (offer.history[i][j] != 0) {
          g2d.setColor(color[offer.history[i][j]]);
          g2d.fillRect(
              xGap + (int) (xDist * i),
              yGap + yPaint - (int) (yDist * (j + 1)),
              (int) (xDist + 1),
              (int) (yDist + 1));
        }
      }
    }

    g2d.setColor(Color.black);
    // Rotate 90 degrees clockwise about the position (x, y)
    at.rotate(-Math.PI / 2, y / 2, y / 2);
    g2d.transform(at);

    // Draw the string at the position (x, y)
    g2d.setFont(new Font("Arial", Font.ITALIC, 15));
    g2d.drawString("Capacity of resource", 20, 14);

    // Rotate back
    g2d.setTransform(origTx);

    for (int i = 0; i < maxRows; i++) {
      g2d.drawLine(xGap, yGap + (int) (yDist * i), xGap + xPaint, yGap + (int) (yDist * i));
      g2d.drawLine(xGap, yGap + (int) (yDist * i + 1), xGap + xPaint, yGap + (int) (yDist * i + 1));
    }
    g2d.drawLine(
        xGap,
        yGap + (int) (yDist * maxRows) - 1,
        xGap + xPaint,
        yGap + (int) (yDist * maxRows) - 1);
    g2d.drawLine(
        xGap,
        yGap + (int) (yDist * maxRows) - 2,
        xGap + xPaint,
        yGap + (int) (yDist * maxRows) - 2);

    g2d.setFont(new Font("Dialog", Font.BOLD, 12));
    g2d.drawString("t = ", 10, 16);
    for (int i = 0; i < maxCols; i++) {
      g2d.drawLine(xGap + (int) (xDist * i), yGap, xGap + (int) (xDist * i), y);
      g2d.drawLine(xGap + (int) (xDist * i + 1), yGap, xGap + (int) (xDist * i + 1), y);
      g2d.drawString(String.valueOf(i + 1), xGap + (int) (xDist * i) + (i < 9 ? 8 : 4), 16);
    }
    g2d.drawLine(xGap + (int) (xDist * maxCols) - 1, yGap, xGap + (int) (xDist * maxCols) - 1, y);
    g2d.drawLine(xGap + (int) (xDist * maxCols) - 2, yGap, xGap + (int) (xDist * maxCols) - 2, y);
  }
コード例 #27
0
ファイル: shit.java プロジェクト: JettJengaGod/katana-shoujo
  public void paint(Graphics g) // function that puts everything on the screen
      {
    Graphics2D scene = (Graphics2D) g; // Not really sure what this is. Blame Victor
    // use scene to draw the background

    scene.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g.clearRect(0, 0, SCREENWIDTH, SCREENHEIGHT); // Clears the screen

    Font q =
        new Font(
            "Source Sans Pro", Font.PLAIN, 40); // Makes the font we use for options and story text
    g.setFont(q); // Sets the default font

    g.setColor(Color.white);

    if (state == 1) // Story text
    {
      drawTag(g);
      g.drawImage(textBox, 0, 0, null); // draw the story boxes
      Font n = new Font("Source Sans Pro", Font.BOLD, 48); // Makes the font for the names
      g.setFont(n); // Sets the name font
      scene.drawString(nameC, 53, 435); // Draws the current name
      g.setFont(q); // sets the quote font

      fm = g.getFontMetrics();

      ArrayList<String> lines = new ArrayList<String>();
      String line = "";

      for (int i = 0; i < quoteC.length(); i++) {
        line += quoteC.charAt(i);
        if (fm.stringWidth(line) > 1180) {
          String lineCopy = line;
          line = line.substring(0, lineCopy.lastIndexOf(' '));
          i -= lineCopy.length() - lineCopy.lastIndexOf(' ') - 1;
          lines.add(line);
          line = "";
        }
      }
      lines.add(line);

      for (int i = 0; i < lines.size(); i++) {
        scene.drawString(lines.get(i), 40, 535 + 65 * i);
      }
    } else if (state == 2) // Draws the options
    {
      scene.drawImage(bg, screenShakeX, screenShakeY, null);
      scene.drawImage(obox, screenShakeX, screenShakeY, null); // options thing
      scene.drawString(options.get(0), 220, 255);
      scene.drawString(options.get(1), 220, 375);
      scene.drawString(options.get(2), 220, 495);
    } else if (state == 3) // Game is over
    {
      scene.drawImage(oldbg, screenShakeX, screenShakeY, null);

      float opacity = fadeCounter / FADETIMELIMIT;
      if (opacity > 1.0f) opacity = 1.0f;
      scene.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
      scene.drawImage(bg, screenShakeX, screenShakeY, null); // draws the background image
      scene.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
      scene.drawString("The end", 40, 520); // End screen
    }
  }
コード例 #28
0
    private void doPaint(Graphics g) {
      GraphicsUtil.setupAntialiasing(g);

      final boolean isEmpty = getIcon() == null && StringUtil.isEmpty(getText());
      final Dimension size = getSize();
      if (isSmallVariant()) {
        final Graphics2D g2 = (Graphics2D) g;
        g2.setColor(UIUtil.getControlColor());
        final int w = getWidth();
        final int h = getHeight();
        if (getModel().isArmed() && getModel().isPressed()) {
          g2.setPaint(
              new GradientPaint(
                  0,
                  0,
                  UIUtil.getControlColor(),
                  0,
                  h,
                  ColorUtil.shift(UIUtil.getControlColor(), 0.8)));
        } else {
          g2.setPaint(
              new GradientPaint(
                  0,
                  0,
                  ColorUtil.shift(UIUtil.getControlColor(), 1.1),
                  0,
                  h,
                  ColorUtil.shift(UIUtil.getControlColor(), 0.9)));
        }
        g2.fillRect(2, 0, w - 2, h);
        GraphicsUtil.setupAntialiasing(g2);
        if (!myMouseInside) {
          g2.setPaint(
              new GradientPaint(
                  0, 0, UIUtil.getBorderColor(), 0, h, UIUtil.getBorderColor().darker()));
          // g2.setColor(UIUtil.getBorderColor());
        } else {
          g2.setPaint(
              new GradientPaint(
                  0,
                  0,
                  UIUtil.getBorderColor().darker(),
                  0,
                  h,
                  UIUtil.getBorderColor().darker().darker()));
        }
        g2.drawRect(2, 0, w - 3, h - 1);
        final Icon icon = getIcon();
        int x = 7;
        if (icon != null) {
          icon.paintIcon(null, g, x, (size.height - icon.getIconHeight()) / 2);
          x += icon.getIconWidth() + 3;
        }
        if (!StringUtil.isEmpty(getText())) {
          final Font font = getFont();
          g2.setFont(font);
          g2.setColor(UIManager.getColor("Panel.foreground"));
          g2.drawString(getText(), x, (size.height + font.getSize()) / 2 - 1);
        }
      } else {
        super.paintComponent(g);
      }
      final Insets insets = super.getInsets();
      final Icon icon = isEnabled() ? ARROW_ICON : DISABLED_ARROW_ICON;
      final int x;
      if (isEmpty) {
        x = (size.width - icon.getIconWidth()) / 2;
      } else {
        if (isSmallVariant()) {
          x = size.width - icon.getIconWidth() - insets.right + 1;
        } else {
          x =
              size.width
                  - icon.getIconWidth()
                  - insets.right
                  + (UIUtil.isUnderNimbusLookAndFeel() ? -3 : 2);
        }
      }
      if (UIUtil.isUnderDarcula()) {
        g.setXORMode(new Color(208, 188, 159));
      }
      icon.paintIcon(null, g, x, (size.height - icon.getIconHeight()) / 2);
      g.setPaintMode();
    }
コード例 #29
0
ファイル: instructions.java プロジェクト: nlillie/Blackjack
  @Override
  public void paintComponent(Graphics window) {
    super.paintComponent(window);

    Image bufferedImage = createImage(getWidth(), getHeight());
    Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics();

    g2d.setPaint(gradient1);
    g2d.fillRect(0, 0, 300, 1000);

    if (showInstructions == true) {
      g2d.setColor(Color.YELLOW);
      g2d.setFont(font1);
      g2d.drawString("Instructions:", 10, 150);
      g2d.setFont(font3);
      g2d.drawString("To Play, Click New Game", 10, 200);
      g2d.drawString("Each game costs $1", 10, 230);
      g2d.drawString("Hit adds a card to your hand", 10, 260);
      g2d.drawString("Stand stops the game and", 10, 290);
      g2d.drawString("calculates each persons score", 10, 320);
      g2d.drawString("To play dealer, click Play Dealer", 10, 350);
      g2d.drawString("Enter your desired wager", 10, 380);
      g2d.drawString("Every time you score 20 or 21", 10, 470);
      g2d.drawString("you get one arcade token", 10, 500);
      g2d.drawString("Arcade Tokens can be redeemed", 10, 530);
      g2d.drawString("By closing instructions and clicking", 10, 560);
      g2d.drawString("Play Arcade Game", 10, 590);
    } else {
      g2d.setColor(Color.YELLOW);
      g2d.setFont(font1);
      g2d.drawString("Arcade Game:", 10, 250);
      g2d.setFont(font3);
      g2d.drawString("Select the game you would like", 10, 320);
      g2d.drawString("Click Play to Play.", 10, 350);
      g2d.drawString("Hold and Drag the Mouse", 10, 380);
      g2d.drawString("to move in Cube Runner", 10, 410);
      g2d.drawString("Press the mouse to sprint", 10, 440);
      g2d.drawString("in Spiral Game, and click", 10, 500);
      g2d.drawString("to Jump", 10, 530);
      g2d.drawString("Each game costs one token", 10, 560);
      g2d.drawString("", 10, 590);
    }
    g2d.setColor(Color.YELLOW);
    g2d.setFont(font1);
    g2d.drawString("Tokens: " + tempObject.tokens, 10, 700);
    window.drawImage(bufferedImage, 0, 0, this);
  }
コード例 #30
0
 private void paintScore(Graphics2D g2d) {
   Font font = new Font("sans", Font.PLAIN, 36);
   g2d.setColor(Color.green);
   g2d.setFont(font);
   g2d.drawString((int) c.getPoints() + "", 10, 50);
 }