⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphicsutil.java

📁 Reinforcement Learning
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
   *  when done.   */    public static void fillRect(Graphics g,                              int left, int top,                              int width, int height,                              Color c) {    Color origColor = g.getColor();    g.setColor(c);    g.fillRect(left, top, width, height);    g.setColor(origColor);  }  //----------------------------------------------------  /** Draws a rounded rectangle at the specified   *  location with the supplied pen thickness.   *  left/top are the <B>center</B> of the lines   *  drawn. Ie width/height are from the center of one   *  side to the center of the other. So the inside   *  width/heights are really lineWidth less than the   *  values of width and height, and the   *  outside width/heights are lineWidth more.   *   * @param g The Graphics object.   * @param left Center of left side edge.   * @param top Center of the top edge.   * @param width Distance from center of L side to   *              center of R side.   * @param height Distance from center of top side to   *               center of bottom side.   * @param arcWidth Horizontal diameter of arc at   *                 corners.   * @param arcHeight Vertical diameter of arc at   *                  corners.   * @param lineWidth Pen thickness.   */     public static void drawRoundRect(Graphics g,                                    int left,                                    int top,                                    int width,                                    int height,                                    int arcWidth,                                    int arcHeight,                                    int lineWidth) {    left = left - lineWidth/2;    top = top - lineWidth/2;    width = width + lineWidth;    height = height + lineWidth;    for(int i=0; i<lineWidth; i++) {      g.drawRoundRect(left, top, width, height,                      arcWidth, arcHeight);      if((i+1)<lineWidth) {        g.drawRoundRect(left, top, width-1, height-1,                        arcWidth, arcHeight);        g.drawRoundRect(left+1, top, width-1, height-1,                        arcWidth, arcHeight);        g.drawRoundRect(left, top+1, width-1, height-1,                        arcWidth, arcHeight);        g.drawRoundRect(left+1, top+1, width-1, height-1,                        arcWidth, arcHeight);        left = left + 1;        top = top + 1;        width = width - 2;        height = height - 2;      }    }  }  /** Draws a rounded rectangle at the specified   *  location with the supplied pen thickness and color.   *  left/top are the <B>center</B> of the lines   *  drawn. Ie width/height are from the center of one   *  side to the center of the other. So the inside   *  width/heights are really lineWidth less than the   *  values of width and height, and the   *  outside width/heights are lineWidth more.   *   * @param g The Graphics object.   * @param left Center of left side edge.   * @param top Center of the top edge.   * @param width Distance from center of L side to   *              center of R side.   * @param height Distance from center of top side to   *               center of bottom side.   * @param arcWidth Horizontal diameter of arc at   *                 corners.   * @param arcHeight Vertical diameter of arc at   *                  corners.   * @param lineWidth Pen thickness.   * @param c Pen color.   */    public static void drawRoundRect(Graphics g,                                   int left,                                   int top,                                   int width,                                   int height,                                   int arcWidth,                                   int arcHeight,                                   int lineWidth,                                   Color c) {    Color origColor = g.getColor();    g.setColor(c);    drawRoundRect(g, left, top, width, height,                  arcWidth, arcHeight, lineWidth);    g.setColor(origColor);  }  /** Draws a 1-pixel wide rounded rectangle with the   *  specified color. Same as g.drawRoundRect except   *  for the color.   *   * @param g The Graphics object.   * @param left The x-coordinate of left edge.   * @param top The y-coordinate of the top edge.   * @param width Distance from L side to R side.   * @param height Distance from top side to bottom side.   * @param arcWidth Horizontal diameter of arc at   *                 corners.   * @param arcHeight Vertical diameter of arc at   *                  corners.   * @param c Pen color.   */    public static void drawRoundRect(Graphics g,                                   int left,                                   int top,                                   int width,                                   int height,                                   int arcWidth,                                   int arcHeight,                                   Color c) {    drawRoundRect(g, left, top, width, height,                  arcWidth, arcHeight, 1, c);  }  //----------------------------------------------------  /** Draws a solid rounded rectangle with the   *  specified color. Same as g.fillRoundRect except   *  for the color.   *   * @param g The Graphics object.   * @param left Center of left side edge.   * @param top Center of the top edge.   * @param width Distance from center of L side to   *              center of R side.   * @param height Distance from center of top side to   *               center of bottom side.   * @param arcWidth Horizontal diameter of arc at   *                 corners.   * @param arcHeight Vertical diameter of arc at   *                  corners.   * @param c Pen color.   */    public static void fillRoundRect(Graphics g,                                   int left,                                   int top,                                   int width,                                   int height,                                   int arcWidth,                                   int arcHeight,                                   Color c) {    Color origColor = g.getColor();    g.setColor(c);    g.fillRoundRect(left, top, width, height,                    arcWidth, arcHeight);    g.setColor(origColor);  }  //----------------------------------------------------  /** Draws a 3D rectangle in the specified location   *  with the given line thickness. left/top   *  are the <B>center</B> of the lines drawn.   *  Ie width/height are from the center of one side   *  to the center of the other. So the inside   *  width/heights are really lineWidth less than   *  the values of width and height; the   *  outside width/heights are lineWidth more.   *   * @param g The Graphics object.   * @param left Center of left side edge.   * @param top Center of the top edge.   * @param width Distance from center of L side to   *              center of R side.   * @param height Distance from center of top side to   *               center of bottom side.   * @param isRaised A boolean variable that determines   *                 if the right and bottom sides are   *                 shaded to try to make the rectangle   *                 look like it is higher than   *                 background (true) or lower (false).   *                 Works best with relatively thin   *                 lines and gray colors.   * @param lineWidth The pen thickness.   */    public static void draw3DRect(Graphics g,                                int left, int top,                                int width, int height,                                boolean isRaised,                                int lineWidth) {    left = left - lineWidth/2;    top = top - lineWidth/2;    width = width + lineWidth;    height = height + lineWidth;    for(int i=0; i<lineWidth; i++) {      g.draw3DRect(left, top, width, height, isRaised);      left = left + 1;      top = top + 1;      width = width - 2;      height = height - 2;    }  }  /** Draws a 3D rectangle in the specified location   *  with the given line thickness and color. left/top   *  are the <B>center</B> of the lines drawn.   *  Ie width/height are from the center of one side   *  to the center of the other. So the inside   *  width/heights are really lineWidth less than   *  the values of width and height; the   *  outside width/heights are lineWidth more.   *   * @param g The Graphics object.   * @param left Center of left side edge.   * @param top Center of the top edge.   * @param width Distance from center of L side to   *              center of R side.   * @param height Distance from center of top side to   *               center of bottom side.   * @param isRaised A boolean variable that determines   *                 if the right and bottom sides are   *                 shaded to try to make the rectangle   *                 look like it is higher than   *                 background (true) or lower (false).   *                 Works best with relatively thin   *                 lines and gray colors.   * @param lineWidth The pen thickness.   * @param c The pen color.   */    public static void draw3DRect(Graphics g,                                int left, int top,                                int width, int height,                                boolean isRaised,                                int lineWidth, Color c) {    Color origColor = g.getColor();    g.setColor(c);    draw3DRect(g, left, top, width, height,               isRaised, lineWidth);    g.setColor(origColor);  }  /** Draws a 1-pixel thick 3D rectangle in the   *  specified location with the given color.    *   * @param g The Graphics object.   * @param left The x-coordinate of left side edge.   * @param top The y-coordinate of the top edge.   * @param width Distance from L side to R side.   * @param height Distance from top side bottom side.   * @param isRaised A boolean variable that determines   *                 if the right and bottom sides are   *                 shaded to try to make the rectangle   *                 look like it is higher than   *                 background (true) or lower (false).   *                 Works best with gray colors.   * @param c The pen color.   */    public static void draw3DRect(Graphics g,                                int left, int top,                                int width, int height,                                boolean isRaised,                                Color c) {    draw3DRect(g, left, top, width, height,               isRaised, 1, c);  }  //----------------------------------------------------  /** Makes a solid 3D rectangle in the given color.   *   * @param g The Graphics object.   * @param left The x-coordinate of left side edge.   * @param top The y-coordinate of the top edge.   * @param width Distance from L side to R side.   * @param height Distance from top side bottom side.   * @param isRaised A boolean variable that determines   *                 if the right and bottom sides are   *                 shaded to try to make the rectangle   *                 look like it is higher than   *                 background (true) or lower (false).   *                 Works best with gray colors.   * @param c The pen color.   */    public static void fill3DRect(Graphics g,                                int left, int top,                                int width, int height,                                boolean isRaised,                                Color c) {    Color origColor = g.getColor();    g.setColor(c);    g.fill3DRect(left, top, width, height, isRaised);    g.setColor(origColor);  }  //----------------------------------------------------  /** Calls g.drawString(s, x, y) after setting the   *  color to c. Resets the color after drawing.   *   * @param g The Graphics object.   * @param s The string to be drawn.   * @param x The left side of the string.   * @param y The <B>bottom</B> (not top) of the string.   * @param c The color in which to draw the string.   */    public static void drawString(Graphics g,                                String s,                                int x, int y,                                Color c) {    Color origColor = g.getColor();    g.setColor(c);    g.drawString(s, x, y);    g.setColor(origColor);  }  /** Calls g.drawString(s, x, y) after setting the   *  font to f. Resets the font after drawing.   *   * @param g The Graphics object.   * @param s The string to be drawn.   * @param x The left side of the string    * @param y The <B>bottom</B> (not top) of the string.   * @param f The font in which to draw the string.   */    public static void drawString(Graphics g,                                String s,                                int x, int y,                                Font f) {    Font origFont = g.getFont();    g.setFont(f);    g.drawString(s, x, y);    g.setFont(origFont);  }  /** Calls g.drawString(s, x, y) after setting the   *  font to f and the color to c. Resets the font   *  and color after drawing.   *   * @param g The Graphics object.   * @param s The string to be drawn.   * @param x The left side of the string   * @param y The <B>bottom</B> (not top) of the string.   * @param f The font in which to draw the string.   * @param c The color in which to draw the string.   */    public static void drawString(Graphics g,                                String s,                                int x, int y,                                Font f, Color c) {    Font origFont = g.getFont();    g.setFont(f);    drawString(g, s, x, y, c);    g.setFont(origFont);  }  //----------------------------------------------------} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -