本文整理汇总了Java中java.awt.Graphics2D.fillRect方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.fillRect方法的具体用法?Java Graphics2D.fillRect怎么用?Java Graphics2D.fillRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Graphics2D
的用法示例。
在下文中一共展示了Graphics2D.fillRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawTileName
import java.awt.Graphics2D; //导入方法依赖的package包/类
private static BufferedImage drawTileName(BufferedImage image, String name) {
BufferedImage i2 = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = i2.createGraphics();
g2.drawImage(image, null, 0, 0);
g2.setColor(Color.red);
g2.setStroke(new BasicStroke(4));
g2.drawRect(8, 8, image.getWidth() - 8, image.getHeight() - 8);
g2.setColor(Color.RED);
g2.setFont(g2.getFont().deriveFont(Font.BOLD).deriveFont(13f));
FontMetrics fm = g2.getFontMetrics();
String[] parts = name.split("/");
for (int i = 0; i < parts.length; i++) {
String s = i == parts.length - 1 ? parts[i] : parts[i] + "/";
int x = 40 + i * 5;
int y = 40 + i * (fm.getHeight() + 5);
Rectangle2D rect = fm.getStringBounds(s, g2);
g2.setColor(Color.white);
g2.fillRect(x, y - fm.getAscent(), (int)rect.getWidth(), fm.getHeight());
g2.setColor(Color.red);
g2.drawString(s, x, y);
}
return i2;
}
示例2: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* @see javax.swing.JComponent#paint(java.awt.Graphics)
*/
public void paint(Graphics g1d) {
Graphics2D g = (Graphics2D) g1d;
g.setPaint(background);
g.fillRect(0,0,getWidth(), getHeight());
g.setColor(Color.yellow);
g.drawRect(0,0,width,height);
if (image != null) {
g.drawImage(image, 0, 0, null);
}
g.setColor(Color.green);
for (int i=0;i<selected.size();i++) {
Sprite sprite = (Sprite) selected.get(i);
g.drawRect(sprite.getX(), sprite.getY(), sprite.getWidth(), sprite.getHeight());
}
}
示例3: createImage
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Creates an BufferedImage and draws a text, using two transformations,
* one for graphics and one for font.
*/
private static BufferedImage createImage(final boolean aa,
final AffineTransform gtx,
final AffineTransform ftx) {
final BufferedImage bi = new BufferedImage(SIZE, SIZE, TYPE_INT_RGB);
final Graphics2D bg = bi.createGraphics();
bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
aa ? RenderingHints.VALUE_ANTIALIAS_ON
: RenderingHints.VALUE_ANTIALIAS_OFF);
bg.setColor(Color.RED);
bg.fillRect(0, 0, SIZE, SIZE);
bg.translate(100, 100);
bg.transform(gtx);
bg.setColor(Color.BLACK);
bg.setFont(bg.getFont().deriveFont(20.0f).deriveFont(ftx));
bg.drawString(STR, 0, 0);
bg.dispose();
return bi;
}
示例4: renderTest
import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void renderTest(Graphics2D g2d, int w, int h) {
g2d.setColor(Color.yellow);
g2d.fillRect(0, 0, w, h);
BufferedImage image = getTestImage();
// draw original image
g2d.drawRenderedImage(image, null);
// draw image with custom composite
g2d.translate(175, 25);
Composite currentComposite = g2d.getComposite();
g2d.setComposite(new TestComposite());
g2d.drawRenderedImage(image, null);
g2d.setComposite(currentComposite);
// draw image with XOR
g2d.translate(175, 25);
g2d.setXORMode(Color.red);
g2d.drawRenderedImage(image, null);
System.out.println("Painting is done...");
}
示例5: createTestFile
import java.awt.Graphics2D; //导入方法依赖的package包/类
private static void createTestFile() {
int w = 1280;
int h = 1024;
BufferedImage img = new
BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = img.createGraphics();
Color[] colors = { Color.red, Color.green, Color.blue };
float[] dist = {0.0f, 0.5f, 1.0f };
Point2D center = new Point2D.Float(0.5f * w, 0.5f * h);
RadialGradientPaint p =
new RadialGradientPaint(center, 0.5f * w, dist, colors);
g.setPaint(p);
g.fillRect(0, 0, w, h);
g.dispose();
try {
System.out.println("Create test image " + file.getAbsolutePath());
boolean b = ImageIO.write(img, "JPEG", file);
if (!b) {
throw new RuntimeException("Failed to create test image.");
}
} catch (IOException e) {
throw new RuntimeException("Test failed", e);
}
}
示例6: repaintImageBuffer
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void repaintImageBuffer() {
if( !useFadeEffects )
return;
// #128324 - image might not be created yet
if ( null == imageBuffer ) {
return;
}
Graphics2D g2d = imageBuffer.createGraphics();
g2d.setColor( contentBackground );
g2d.fillRect(0, 0, imageBuffer.getWidth(), imageBuffer.getHeight() );
g2d.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER, contentAlpha ) );
g2d.drawImage(contentImage, 0, 0, null );
g2d.dispose();
}
示例7: paintButton
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paintButton(Graphics2D g, int width, int height) {
g.setColor(new Color(255, 0, 0, 80));
g.fillRect(0, height/2, width, height/2);
g.setColor(new Color(0, 255, 0, 80));
g.fillRect(0, 0, width, height/2);
super.paintButton(g, width, height);
}
示例8: ConvertToByteIndexed
import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void ConvertToByteIndexed(Color color, int srcType) {
// setup source image and graphics for conversion.
BufferedImage srcImage = new BufferedImage(width, height, srcType);
Graphics2D srcG2D = srcImage.createGraphics();
srcG2D.setColor(color);
srcG2D.fillRect(0, 0, width, height);
// setup destination image and graphics for conversion.
int dstType = BufferedImage.TYPE_BYTE_INDEXED;
BufferedImage dstImage = new BufferedImage(width, height, dstType);
Graphics2D dstG2D = (Graphics2D)dstImage.getGraphics();
// draw source image into Byte Indexed destination
dstG2D.drawImage(srcImage, 0, 0, null);
// draw into ARGB image to verify individual pixel value.
BufferedImage argbImage = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);
Graphics2D argbG2D = (Graphics2D)argbImage.getGraphics();
argbG2D.drawImage(dstImage, 0, 0, null);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
if (color.getRGB() != argbImage.getRGB(i, j)) {
throw new RuntimeException("Conversion from " +
TYPE_TABLE.get(srcType) + " to BYTE_INDEXED is not"
+ " done properly for " + color);
}
}
}
}
示例9: paintButtonPressed
import java.awt.Graphics2D; //导入方法依赖的package包/类
protected void paintButtonPressed(Graphics g, AbstractButton b) {
Color c = g.getColor();
Graphics2D g2 = (Graphics2D) g;
g2.setPaint(colorSelect);
g2.fillRect(0, 0, b.getWidth(), b.getHeight());
// if ("THEME".equals(b.getName()) || "CTX_SORT".equals(b.getName())) {
// g2.setPaint(gradPressed);
// int gapx = 0;
//
// g2.fillRect(gapx + 2, 0, b.getWidth() - (4 + gapx + 2), b
// .getHeight() - 2);
// g2.setColor(Color.LIGHT_GRAY);
// g2.drawRect(gapx + 2, 0, b.getWidth() - (4 + gapx + 2), b
// .getHeight() - 2);
// if (menuItem.getIcon() != null) {
// int gap = menuItem.getIcon().getIconWidth() + 2;
// g.setColor(this.darkColor);
// g.drawLine(gap, 1, gap, menuItem.getHeight() - 3);
// g.setColor(this.lightColor2);
// g.drawLine(gap + 1, 1, gap + 1, menuItem.getHeight() - 3);
// }
// } else {
// g2.setPaint(gradPressed);
// g2.fillRoundRect(0, 0, b.getWidth() - 1, b.getHeight() - 1, 4, 4);
// g2.setColor(Color.LIGHT_GRAY);
// g2.drawRoundRect(0, 0, b.getWidth() - 1, b.getHeight() - 1, 4, 4);
// }
g.setColor(c);
}
示例10: PaintGradiente
import java.awt.Graphics2D; //导入方法依赖的package包/类
protected void PaintGradiente(Graphics2D g, boolean round) {
int dist = 0;
int w = getWidth() - dist;
int h = getHeight() - dist;
int L = getLeft();
int T = getTop();
boolean dv = getGDirecao() == VERTICAL;
//Composite originalComposite = g.getComposite();
//g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OVER, alfa));
GradientPaint GP = new GradientPaint(L, T, getGradienteStartColor(), dv ? L : L + w, dv ? T + h : T, getGradienteEndColor(), true);
//g.setPaint(GP);
g.setPaint(getForeColor());
if (round) {
g.drawRoundRect(L, T, w - 1, h - 1, roundRectSize, roundRectSize);
g.setPaint(GP);
g.fillRoundRect(L + 1, T + 1, w - 2, h - 2, roundRectSize, roundRectSize);
g.setPaint(isDisablePainted()? disabledColor : Color.WHITE);
g.drawRoundRect(L + 1, T + 1, w - 3, h - 3, roundRectSize, roundRectSize);
} else {
g.drawRect(L, T, w - 1, h - 1);
g.setPaint(GP);
g.fillRect(L + 1, T + 1, w - 2, h - 2);
g.setPaint(isDisablePainted()? disabledColor : Color.WHITE);
g.drawRect(L + 1, T + 1, w - 3, h - 3);
}
if (isGradientePinteDetalhe()) {
g.setPaint(getGradienteCorDetalhe());
GeneralPath path = new GeneralPath();
path.moveTo(L + 2, T + 2);
path.quadTo(L + w / 2 + 1, T + h / 2 + 1, L + w - 1, T + 2);
path.closePath();
g.fill(path);
}
//g.setComposite(originalComposite);
}
示例11: drawIcon
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void drawIcon(Graphics2D g2, int width, int height, int percentage) {
g2.setColor(Color.WHITE);
g2.setPaint(new GradientPaint(0, 0, Color.WHITE.darker(), 0, (float) (height * 0.5), Color.WHITE, true));
g2.fillRect(0, 0, width, height);
g2.setColor(Color.GREEN);
g2.setPaint(new GradientPaint(0, 0, Color.GREEN.darker(), percentage, (float) (height * 0.5), Color.GREEN
.darker().darker(), false));
g2.fillRect(0, 0, (int) (percentage * 200d / 100d), height);
g2.setColor(Color.BLACK);
g2.drawRect(0, 0, width - 1, height - 1);
g2.dispose();
}
示例12: paintDeterminate
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void paintDeterminate(Graphics g, JComponent c) {
Insets b = progressBar.getInsets(); // area for border
int barRectWidth = progressBar.getWidth() - (b.right + b.left);
int barRectHeight = progressBar.getHeight() - (b.top + b.bottom);
if (barRectWidth <= 0 || barRectHeight <= 0) {
return;
}
// amount of progress to draw
int amountFull = getAmountFull(b, barRectWidth, barRectHeight);
Graphics2D g2 = (Graphics2D) g;
g2.setColor(progressBar.getForeground());
if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
g2.setPaint(high);
g2.fillRect(0, 0, amountFull, c.getHeight() / 2);
g2.setPaint(low);
g2.fillRect(0, c.getHeight() / 2, amountFull, c.getHeight());
} else { // VERTICAL
}
// Deal with possible text painting
if (progressBar.isStringPainted()) {
paintString(g, b.left, b.top, barRectWidth, barRectHeight,
amountFull, b);
}
}
示例13: doPaint
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object[] extendedCacheKeys) {
//it is assumed that in the normal orientation the separator renders
//horizontally. Other code rotates it as necessary for a vertical
//separator.
g.setColor(c.getForeground());
int y = height / 2;
for (int i=INSET; i<=width-INSET; i+=SPACE) {
g.fillRect(i, y, 1, 1);
}
}
示例14: paintMinus
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void paintMinus(Graphics2D g, Point center, int thickness) {
g.fillRect(
center.x - SQUARE_SIZE / 2,
center.y - thickness / 2,
SQUARE_SIZE,
thickness);
}
示例15: paintContent
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void paintContent(Graphics g) {
Graphics2D gr = (Graphics2D) g;
// fitting
double xspace = getWidth() / 2;
double yspace = getHeight() / game.ceilingHeight;
int posXStart;
int posYStart;
int drawWidth;
int drawHeight;
if (yspace > xspace) {
posXStart = 0;
drawWidth = getWidth();
posYStart = (int) ((getHeight() - drawWidth * game.ceilingHeight / 2) / 2);
drawHeight = (int) (drawWidth * game.ceilingHeight / 2);
} else {
posYStart = 0;
drawHeight = getHeight();
posXStart = (int) (getWidth() - drawHeight / game.ceilingHeight * 2) / 2;
drawWidth = (int) (drawHeight / game.ceilingHeight * 2);
}
gr.setClip(posXStart, posYStart, drawWidth, drawHeight);
int middleX = posXStart + drawWidth / 2;
// background
gr.setColor(COLOR_BACKGROUND_0);
gr.fillRect(posXStart, posYStart, drawWidth / 2, drawHeight);
gr.setColor(COLOR_BACKGROUND_1);
gr.fillRect(middleX, posYStart, drawWidth / 2, drawHeight);
// GameObjects
// players
drawPlayer(gr, game.playerLeft, COLOR_PLAYER_0, posXStart, posYStart, drawWidth, drawHeight);
drawPlayer(gr, game.playerRight, COLOR_PLAYER_1, posXStart, posYStart, drawWidth, drawHeight);
// ball
gr.setColor(COLOR_BALL);
double ballDiameter = drawWidth * game.ballRadius;
gr.fillOval((int) (posXStart + game.ball.getPosX() * drawWidth / 2 - ballDiameter / 2),
(int) (posYStart + (1 - game.ball.getPosY() / game.ceilingHeight) * drawHeight - ballDiameter / 2), (int) ballDiameter, (int) ballDiameter);
}