当前位置: 首页>>代码示例>>Java>>正文


Java Graphics2D.fillRect方法代码示例

本文整理汇总了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;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:25,代码来源:PoleMapServer.java

示例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());
	}
}
 
开发者ID:IngSW-unipv,项目名称:Progetto-C,代码行数:23,代码来源:SheetPanel.java

示例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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:DrawRotatedStringUsingRotatedFont.java

示例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...");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:CustomCompositeTest.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:ReadingInterruptionTest.java

示例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();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:DragWindow.java

示例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);
}
 
开发者ID:CalebKussmaul,项目名称:GIFKR,代码行数:10,代码来源:BoolInterpolator.java

示例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);
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:ConvertToByteIndexedTest.java

示例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);
	}
 
开发者ID:kmarius,项目名称:xdman,代码行数:34,代码来源:XDMMenuUI.java

示例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);

}
 
开发者ID:chcandido,项目名称:brModelo,代码行数:39,代码来源:PreTexto.java

示例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();
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:14,代码来源:DynamicIconUrlStreamHandler.java

示例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);
	}
}
 
开发者ID:kmarius,项目名称:xdman,代码行数:31,代码来源:XDMProgressBarUI.java

示例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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:ToolBarSeparatorPainter.java

示例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);
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:8,代码来源:ShedCollapseWidget.java

示例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);
}
 
开发者ID:DavidSichma,项目名称:EVB,代码行数:38,代码来源:GameWindow.java


注:本文中的java.awt.Graphics2D.fillRect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。