Class Graphics2DUtil

java.lang.Object
de.pirckheimer_gymnasium.engine_pi.util.Graphics2DUtil

public class Graphics2DUtil extends Object
Eine Sammlung von statischen Hilfsmethoden um auf dem Graphics2D-Objekt zu zeichnen.
  • Constructor Details

    • Graphics2DUtil

      public Graphics2DUtil()
  • Method Details

    • getFont

      public static Font getFont(int size)
    • getFont

      public static Font getFont()
    • setFont

      public static Font setFont(Graphics2D g, Font font)
      Setzt die Schriftart durch Angabe der Schriftart.
      Parameters:
      g - Das Graphics2D-Objekt, in das gezeichnet werden soll.
      font - Die Schriftart.
      Returns:
      Die Schriftart, die in das Graphics2D-Objekt gesetzt wurde.
    • setFont

      public static Font setFont(Graphics2D g, int size, String color)
      Setzt die Schriftart durch Angabe der Schriftgröße und Schriftfarbe.
      Parameters:
      g - Das Graphics2D-Objekt, in das gezeichnet werden soll.
      size - Die Größe der Schrift in pt (Points).
      color - Ein Farbname wie er im ColorContainer hinterlegt ist.
      Returns:
      Die Schriftart, die in das Graphics2D-Objekt gesetzt wurde.
    • setFont

      public static Font setFont(Graphics2D g, int size)
      Setzt die Schriftart auf FONT_COLOR durch Angabe der Schriftgröße.
      Parameters:
      g - Das Graphics2D-Objekt, in das gezeichnet werden soll.
      size - Die Größe der Schrift in pt (Points).
      Returns:
      Die Schriftart, die in das Graphics2D-Objekt gesetzt wurde.
    • setFont

      public static Font setFont(Graphics2D g, String color)
      Setzt die Schriftart auf FONT_SIZE durch Angabe der Schriftfarbe.
      Parameters:
      g - Das Graphics2D-Objekt, in das gezeichnet werden soll.
      color - Ein Farbname wie er im ColorContainer hinterlegt ist.
      Returns:
      Die Schriftart, die in das Graphics2D-Objekt gesetzt wurde.
    • setFont

      public static Font setFont(Graphics2D g)
      Setzt die Schriftart auf FONT_SIZE und FONT_COLOR.
      Parameters:
      g - Das Graphics2D-Objekt, in das gezeichnet werden soll.
      Returns:
      Die Schriftart, die in das Graphics2D-Objekt gesetzt wurde.
    • drawText

      public static void drawText(Graphics2D g, String text, int x, int y)
      Zeichnet einen Text mit der Schriftgröße FONT_SIZE und der Schriftfarbe FONT_COLOR an eine bestimmte Position.
      Parameters:
      g - Das Graphics2D-Objekt, in das gezeichnet werden soll.
      text - Der Text, der eingezeichnet werden soll.
      x - Die x-Koordinate in Pixel der Position, an die der Text gesetzt werden soll.
      y - Die y-Koordinate in Pixel der Position an die der Text gesetzt werden soll.
    • drawText

      public static void drawText(Graphics2D g, String text, int size, int x, int y)
      Zeichnet einen Text mit der Schriftfarbe FONT_COLOR durch Angabe der Schriftgröße und einer Position.
      Parameters:
      g - Das Graphics2D-Objekt, in das gezeichnet werden soll.
      text - Der Text, der eingezeichnet werden soll.
      size - Die Größe der Schrift in pt (Points).
      x - Die x-Koordinate in Pixel der Position, an die der Text gesetzt werden soll.
      y - Die y-Koordinate in Pixel der Position an die der Text gesetzt werden soll.
    • drawTextBox

      public static void drawTextBox(Graphics2D g, String text, int y, Color background)
      Zeichnet eine Textbox, die sich automatische an die Länge des Texts anpasst. Die Schriftfarbe ist FONT_COLOR.
      Parameters:
      g - Das Graphics2D-Objekt, in das gezeichnet werden soll.
      text - Der Text, der in die Textbox gesetzt werden soll.
      y - Die y-Koordinate in Pixel.
      background - Ein Farbname wie er im ColorContainer hinterlegt ist.
    • drawArrowLine

      public static void drawArrowLine(Graphics2D g, int x1, int y1, int x2, int y2, int arrowWidth, int arrowHeight, Color color)
      Draw an arrow line between two points. https://stackoverflow.com/a/27461352
      Parameters:
      g - Das Graphics2D-Objekt, in das gezeichnet werden soll.
      x1 - x-position of first point in Pixel.
      y1 - y-position of first point in Pixel.
      x2 - x-position of second point in Pixel.
      y2 - y-position of second point in Pixel.
      arrowWidth - the width of the arrow in Pixel.
      arrowHeight - the height of the arrow in Pixel.
    • setAntiAliasing

      public static void setAntiAliasing(Graphics2D g, boolean on)
      Die Kantenglättung (Antialiasing) ein- oder ausschalten.
      Parameters:
      on - Ist der Wert wahr, so wird die Kantenglättung eingeschaltet, sonst wird sie ausgeschaltet.
    • main

      public static void main(String[] args)