本文整理了Java中java.awt.Graphics2D.drawRect()
方法的一些代码示例,展示了Graphics2D.drawRect()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graphics2D.drawRect()
方法的具体详情如下:
包路径:java.awt.Graphics2D
类名称:Graphics2D
方法名:drawRect
暂无
代码示例来源:origin: MovingBlocks/Terasology
private void renderSelectedChunk(Graphics2D g, int offsetx, int offsety, Vector3i pos) {
if (pos != null) {
g.setColor(COLOR_SELECTED_CHUNK);
g.drawRect(pos.x * chunkSize + offsetx, pos.z * chunkSize + offsety, chunkSize - 1, chunkSize - 1);
g.drawRect(pos.x * chunkSize + offsetx - 1, pos.z * chunkSize + offsety - 1, chunkSize + 1, chunkSize + 1);
}
}
代码示例来源:origin: libgdx/libgdx
protected void paintComponent (Graphics graphics) {
Graphics2D g = (Graphics2D)graphics;
int width = getWidth() - 1;
int height = getHeight() - 1;
for (int i = 0, n = paletteColors.length - 1; i < n; i++) {
Color color1 = paletteColors[i];
Color color2 = paletteColors[i + 1];
float point1 = i / (float)n * width;
float point2 = (i + 1) / (float)n * width;
g.setPaint(new GradientPaint(point1, 0, color1, point2, 0, color2, false));
g.fillRect((int)point1, 0, (int)Math.ceil(point2 - point1), height);
}
g.setPaint(null);
g.setColor(Color.black);
g.drawRect(0, 0, width, height);
}
}
代码示例来源:origin: jphp-group/jphp
@Signature
public void rect(int x, int y, int width, int height, DrawOptions options) {
applyOptions(options);
if (options.isOutline()) {
gc.drawRect(x, y, width, height);
} else {
gc.fillRect(x, y, width, height);
}
}
代码示例来源:origin: libgdx/libgdx
protected void paintComponent (Graphics graphics) {
Graphics2D g = (Graphics2D)graphics;
int width = getWidth() - 1;
int height = getHeight() - 1;
for (int i = 0, n = paletteColors.length - 1; i < n; i++) {
Color color1 = paletteColors[i];
Color color2 = paletteColors[i + 1];
float point1 = i / (float)n * width;
float point2 = (i + 1) / (float)n * width;
g.setPaint(new GradientPaint(point1, 0, color1, point2, 0, color2, false));
g.fillRect((int)point1, 0, (int)Math.ceil(point2 - point1), height);
}
g.setPaint(null);
g.setColor(Color.black);
g.drawRect(0, 0, width, height);
}
}
代码示例来源:origin: MovingBlocks/Terasology
private void renderBox(Graphics2D g, int offsetx, int offsety, Rectangle box) {
g.setColor(Color.WHITE);
g.drawRect(box.x * chunkSize + offsetx, box.y * chunkSize + offsety, box.width * chunkSize - 1, box.height * chunkSize - 1);
}
代码示例来源:origin: marytts/marytts
protected void drawDot(Graphics2D g, int x, int y, int currentDotStyle) {
switch (currentDotStyle) {
case DOT_FULLCIRCLE:
g.fillOval(x - dotSize / 2, y - dotSize / 2, dotSize, dotSize);
break;
case DOT_FULLSQUARE:
g.fillRect(x - dotSize / 2, y - dotSize / 2, dotSize, dotSize);
break;
case DOT_FULLDIAMOND:
g.fillPolygon(new int[] { x - dotSize / 2, x, x + dotSize / 2, x }, new int[] { y, y - dotSize / 2, y,
y + dotSize / 2 }, 4);
break;
case DOT_EMPTYCIRCLE:
g.drawOval(x - dotSize / 2, y - dotSize / 2, dotSize, dotSize);
break;
case DOT_EMPTYSQUARE:
g.drawRect(x - dotSize / 2, y - dotSize / 2, dotSize, dotSize);
break;
case DOT_EMPTYDIAMOND:
g.drawPolygon(new int[] { x - dotSize / 2, x, x + dotSize / 2, x }, new int[] { y, y - dotSize / 2, y,
y + dotSize / 2 }, 4);
break;
default:
break;
}
}
代码示例来源:origin: libgdx/libgdx
protected void paintComponent (Graphics graphics) {
Graphics2D g = (Graphics2D)graphics;
int width = getWidth() - 1;
int height = getHeight() - 1;
for (int i = 0, n = paletteColors.length - 1; i < n; i++) {
Color color1 = paletteColors[i];
Color color2 = paletteColors[i + 1];
float point1 = i / (float)n * width;
float point2 = (i + 1) / (float)n * width;
g.setPaint(new GradientPaint(point1, 0, color1, point2, 0, color2, false));
g.fillRect((int)point1, 0, (int)Math.ceil(point2 - point1), height);
}
g.setPaint(null);
g.setColor(Color.black);
g.drawRect(0, 0, width, height);
}
}
代码示例来源:origin: runelite/runelite
private void drawRectangle(Graphics2D graphics, Rectangle rect, Color color, boolean inList, boolean hiddenBox)
graphics.setColor(Color.BLACK);
graphics.drawRect(rect.x + 1, rect.y + 1, rect.width, rect.height);
graphics.setColor(color);
graphics.draw(rect);
graphics.setColor(Color.WHITE);
代码示例来源:origin: marytts/marytts
protected void drawDot(Graphics2D g, int x, int y, int currentDotStyle) {
switch (currentDotStyle) {
case DOT_FULLCIRCLE:
g.fillOval(x - dotSize / 2, y - dotSize / 2, dotSize, dotSize);
break;
case DOT_FULLSQUARE:
g.fillRect(x - dotSize / 2, y - dotSize / 2, dotSize, dotSize);
break;
case DOT_FULLDIAMOND:
g.fillPolygon(new int[] { x - dotSize / 2, x, x + dotSize / 2, x }, new int[] { y, y - dotSize / 2, y,
y + dotSize / 2 }, 4);
break;
case DOT_EMPTYCIRCLE:
g.drawOval(x - dotSize / 2, y - dotSize / 2, dotSize, dotSize);
break;
case DOT_EMPTYSQUARE:
g.drawRect(x - dotSize / 2, y - dotSize / 2, dotSize, dotSize);
break;
case DOT_EMPTYDIAMOND:
g.drawPolygon(new int[] { x - dotSize / 2, x, x + dotSize / 2, x }, new int[] { y, y - dotSize / 2, y,
y + dotSize / 2 }, 4);
break;
default:
break;
}
}
代码示例来源:origin: libgdx/libgdx
protected void paintComponent (Graphics graphics) {
Graphics2D g = (Graphics2D)graphics;
int width = getWidth() - 1;
int height = getHeight() - 1;
for (int i = 0, n = paletteColors.length - 1; i < n; i++) {
Color color1 = paletteColors[i];
Color color2 = paletteColors[i + 1];
float point1 = i / (float)n * width;
float point2 = (i + 1) / (float)n * width;
g.setPaint(new GradientPaint(point1, 0, color1, point2, 0, color2, false));
g.fillRect((int)point1, 0, (int)Math.ceil(point2 - point1), height);
}
g.setPaint(null);
g.setColor(Color.black);
g.drawRect(0, 0, width, height);
}
}
代码示例来源:origin: jersey/jersey
@Path("discrete")
@GET
public Response discrete(
@DefaultValue("2") @QueryParam("width") final int width,
@DefaultValue("50") @QueryParam("upper") final int upper,
@DefaultValue("red") @QueryParam("upper-color") final ColorParam upperColor,
@DefaultValue("gray") @QueryParam("lower-color") final ColorParam lowerColor
) {
final BufferedImage image = new BufferedImage(
data.size() * width - 1, imageHeight, BufferedImage.TYPE_INT_RGB);
final Graphics2D g = image.createGraphics();
g.setBackground(Color.WHITE);
g.clearRect(0, 0, image.getWidth(), image.getHeight());
final int gap = 4;
final float d = (limits.width() + 1) / (float) (imageHeight - gap);
for (int i = 0, x = 0, y; i < data.size(); i++, x += width) {
final int v = data.get(i);
g.setColor((v >= upper) ? upperColor : lowerColor);
y = imageHeight - (int) ((v - limits.lower()) / d);
g.drawRect(x, y - gap, width - 2, gap);
}
return Response.ok(image).tag(tag).build();
}
代码示例来源:origin: magefree/mage
g.drawRect(
0, 0,
half.cw - 1, half.ch - 1);
g.fillRect(
1, typeLineY,
half.cw - 2, half.ch - typeLineY - 1);
代码示例来源:origin: runelite/runelite
private static void renderBar(Graphics2D graphics, int x, int y, int max, int current, int height, Color filled)
{
graphics.setColor(BACKGROUND);
graphics.drawRect(x, y, WIDTH - PADDING, height - PADDING);
graphics.fillRect(x, y, WIDTH, height);
final int filledHeight = getBarHeight(max, current, height);
graphics.setColor(filled);
graphics.fillRect(x + PADDING,
y + PADDING + (height - filledHeight),
WIDTH - PADDING * OFFSET,
filledHeight - PADDING * OFFSET);
}
代码示例来源:origin: runelite/runelite
private void drawMapIcons(BufferedImage image, int drawBaseX, int drawBaseY, Region region, int z)
{
int baseX = region.getBaseX();
int baseY = region.getBaseY();
Graphics2D graphics = image.createGraphics();
drawMapIcons(graphics, region, z, drawBaseX, drawBaseY);
if (labelRegions)
{
graphics.setColor(Color.WHITE);
String str = baseX + "," + baseY + " (" + region.getRegionX() + "," + region.getRegionY() + ")";
graphics.drawString(str, drawBaseX * MAP_SCALE, drawBaseY * MAP_SCALE + graphics.getFontMetrics().getHeight());
}
if (outlineRegions)
{
graphics.setColor(Color.WHITE);
graphics.drawRect(drawBaseX * MAP_SCALE, drawBaseY * MAP_SCALE, Region.X * MAP_SCALE, Region.Y * MAP_SCALE);
}
graphics.dispose();
}
代码示例来源:origin: runelite/runelite
@Override
public Dimension render(Graphics2D graphics)
{
int thickness = borderThickness;
int width = preferredSize.width;
int height = preferredSize.height;
//draw the fill
graphics.setColor(fill);
graphics.fillRect(thickness, thickness, width - thickness * 2, height - thickness * 2);
//because the stroke is centered on the rectangle we draw, we need to translate where we draw the rectangle
//this is to ensure that the rectangle we draw is our preferred size
int offset = thickness / 2;
graphics.setColor(color);
graphics.setStroke(stroke);
graphics.drawRect(offset, offset, width - thickness, height - thickness);
return preferredSize;
}
}
代码示例来源:origin: libgdx/libgdx
g.setColor(Color.magenta);
g.drawRect(rectX, rectY, rect.width - settings.paddingX - 1, rect.height - settings.paddingY - 1);
g.setColor(Color.magenta);
g.drawRect(0, 0, width - 1, height - 1);
代码示例来源:origin: libgdx/libgdx
int point2 = (int)Math.ceil(percent2 * gradientWidth);
g.setPaint(new GradientPaint(point1, 0, color1, point2, 0, color2, false));
g.fillRect(point1, 0, point2 - point1, gradientHeight);
g.setColor(Color.black);
g.drawRect(0, 0, gradientWidth, gradientHeight);
xPoints[2] = x + handleWidth / 2;
if (i == selectedIndex) {
g.setColor(colors.get(i));
g.fillPolygon(xPoints, yPoints, 3);
g.fillRect(xPoints[1], yPoints[1] + 2, handleWidth + 1, 2);
g.setColor(Color.black);
代码示例来源:origin: libgdx/libgdx
g.setColor(Color.magenta);
g.drawRect(rectX, rectY, rect.width - settings.paddingX - 1, rect.height - settings.paddingY - 1);
g.setColor(Color.magenta);
g.drawRect(0, 0, width - 1, height - 1);
代码示例来源:origin: libgdx/libgdx
int point2 = (int)Math.ceil(percent2 * gradientWidth);
g.setPaint(new GradientPaint(point1, 0, color1, point2, 0, color2, false));
g.fillRect(point1, 0, point2 - point1, gradientHeight);
g.setColor(Color.black);
g.drawRect(0, 0, gradientWidth, gradientHeight);
xPoints[2] = x + handleWidth / 2;
if (i == selectedIndex) {
g.setColor(colors.get(i));
g.fillPolygon(xPoints, yPoints, 3);
g.fillRect(xPoints[1], yPoints[1] + 2, handleWidth + 1, 2);
g.setColor(Color.black);
代码示例来源:origin: runelite/runelite
@Override
public Dimension render(Graphics2D graphics)
{
ScreenMarker marker = plugin.getCurrentMarker();
if (marker == null)
{
return null;
}
int thickness = marker.getBorderThickness();
int offset = thickness / 2;
int width = getBounds().width - thickness;
int height = getBounds().height - thickness;
graphics.setStroke(createStripedStroke(thickness));
graphics.setColor(marker.getColor());
graphics.drawRect(offset, offset, width, height);
return getBounds().getSize();
}
内容来源于网络,如有侵权,请联系作者删除!