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


Java Graphics2D.setColor方法代码示例

本文整理汇总了Java中java.awt.Graphics2D.setColor方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.setColor方法的具体用法?Java Graphics2D.setColor怎么用?Java Graphics2D.setColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Graphics2D的用法示例。


在下文中一共展示了Graphics2D.setColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDrawEmptyString

import java.awt.Graphics2D; //导入方法依赖的package包/类
private static void testDrawEmptyString() {
    JLabel label = new JLabel();
    BufferedImage buffImage = createBufferedImage(50, 50);
    Graphics2D g2 = buffImage.createGraphics();
    g2.setColor(DRAW_COLOR);
    BasicGraphicsUtils.drawString(null, g2, null, 0, 0);
    BasicGraphicsUtils.drawString(label, g2, null, 0, 0);
    BasicGraphicsUtils.drawString(null, g2, "", 0, 0);
    BasicGraphicsUtils.drawString(label, g2, "", 0, 0);
    BasicGraphicsUtils.drawStringUnderlineCharAt(null, g2, null, 3, 0, 0);
    BasicGraphicsUtils.drawStringUnderlineCharAt(label, g2, null, 3, 0, 0);
    BasicGraphicsUtils.drawStringUnderlineCharAt(null, g2, "", 3, 0, 0);
    BasicGraphicsUtils.drawStringUnderlineCharAt(label, g2, "", 3, 0, 0);
    g2.dispose();
    checkImageIsEmpty(buffImage);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:bug8132119.java

示例2: renderFogOfWar

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void renderFogOfWar(final Graphics2D g) {
  if (this.fogOfWar == null) {
    return;
  }

  final AffineTransform oldTransform = g.getTransform();
  final AffineTransform at = new AffineTransform();
  at.scale(Game.getCamera().getRenderScale(), Game.getCamera().getRenderScale());
  at.translate(Game.getCamera().getPixelOffsetX(), Game.getCamera().getPixelOffsetY());

  g.setTransform(at);
  g.setColor(FogOfWarColor);
  g.fill(this.fogOfWar);
  g.setTransform(oldTransform);
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:17,代码来源:CombatEntityVision.java

示例3: draw

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void draw(Graphics2D g) {
      float radius = Beacon.BEACON_RADIUS;
      float diameter = Beacon.BEACON_RADIUS * 2;
      
      Ellipse2D.Double shape = new Ellipse2D.Double(drawLocation.getX() - radius,
      		drawLocation.getY() - radius, diameter, diameter);

      g.setColor(BEACON_COLOR);
      g.fill(shape);

      g.setStroke(JSpaceSettlersComponent.THICK_STROKE);
      g.setColor(BEACON_LINE_COLOR);
      g.draw(shape);

      // add an E to make it clear it is an energy beacon
g.setPaint(Color.BLACK);
g.drawString("E", (int) drawLocation.getX()-3, (int) drawLocation.getY() + 4);

  }
 
开发者ID:amymcgovern,项目名称:spacesettlers,代码行数:20,代码来源:BeaconGraphics.java

示例4: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
    final int r = 6;
    super.paint(g);

    // paint cross hairs to show center
    Graphics2D g2 = (Graphics2D) calibrationPanel.getGraphics();
    int w = calibrationPanel.getWidth(), h = calibrationPanel.getHeight();
    g2.setColor(Color.gray);
    g2.drawLine(w / 2, 0, w / 2, h);
    g2.drawLine(0, h / 2, w, h / 2);
    g2.setColor(Color.red) ;
    float x=w/2+w/2*currentPanTiltRad.x/controller.getTiltLimitRad();
    float y=h/2+h/2*(-currentPanTiltRad.y/controller.getTiltLimitRad());
    final int s=20;
    g2.drawOval((int)x-s/2, (int)y-s/2, s, s);

    trajectory.paint();
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:20,代码来源:LabyrinthTableTiltControllerGUI.java

示例5: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paint(Graphics2D g) {

    g.setColor(function.getBackground());
    final Rectangle2D rect = movingArea.getBounds(getBounds());

    RoundRectangle2D.Double rec = new RoundRectangle2D.Double(rect.getX(),
            rect.getY(), rect.getWidth(), rect.getHeight(),
            movingArea.getIDoubleOrdinate(4),
            movingArea.getIDoubleOrdinate(4));

    g.fill(rec);
    g.setFont(function.getFont());
    paintText(g);

    paintBorder(g);

    final Stroke tmp = g.getStroke();
    g.draw(rec);
    g.setStroke(tmp);
    paintTringle(g);

}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:24,代码来源:DFDSRole.java

示例6: drawLine

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * 随机像图片中画短直线
 *
 * @param image 被画直线的图片
 */
private void drawLine(BufferedImage image) {
    Random r = new Random();
    Graphics2D g2 = (Graphics2D) image.getGraphics();
    int max = this.textLength * this.linePower;
    for (int i = 0; i < max; i++) {
        int x1 = r.nextInt(w);
        int y1 = r.nextInt(h);
        int x2 = r.nextInt(w);
        int y2 = r.nextInt(h);
        g2.setStroke(new BasicStroke(1.5F));
        g2.setColor(this.randomColor());
        g2.drawLine(x1, y1, x2, y2);
    }
    g2.dispose();
}
 
开发者ID:FlyingHe,项目名称:UtilsMaven,代码行数:21,代码来源:VerificationCodeImage.java

示例7: getBufferedImage

import java.awt.Graphics2D; //导入方法依赖的package包/类
private static BufferedImage getBufferedImage(int sw) {
    final BufferedImage bi = new BufferedImage(sw, sw, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = bi.createGraphics();
    g2d.setColor(Color.RED);
    g2d.fillRect(0, 0, sw, sw);
    g2d.dispose();

    final DataBuffer db = bi.getRaster().getDataBuffer();
    if (db instanceof DataBufferInt) {
        ((DataBufferInt) db).getData();
    } else if (db instanceof DataBufferShort) {
        ((DataBufferShort) db).getData();
    } else if (db instanceof DataBufferByte) {
        ((DataBufferByte) db).getData();
    } else {
        try {
            bi.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return bi;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:IncorrectClipXorModeSW2Surface.java

示例8: writeImage

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void writeImage(File fontFile, File outputFile, String value) throws Exception {
    BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = image.createGraphics();
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, image.getWidth(), image.getHeight());
    g.setColor(Color.BLACK);

    Font font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
    font = font.deriveFont(Font.PLAIN, 72f);
    FontRenderContext frc = new FontRenderContext(null, false, false);
    GlyphVector gv = font.createGlyphVector(frc, value);
    g.drawGlyphVector(gv, 10, 80);
    g.fill(gv.getOutline(10, 180));
    ImageIO.write(image, "png", outputFile);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:GlyphVectorOutline.java

示例9: paintWidget

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void
        paintWidget() {
    int secondsPerTick = 10;
    int secTickHeight = 6;

    Graphics2D g = getGraphics();
    g.setColor(getForeground());

    int ticksNum = (int) (totalTime / (1000 * secondsPerTick));

    Stroke formerStroke = g.getStroke();
    g.setStroke(lineStroke);

    // draw main line
    g.drawLine(0, 0, (int) (totalTime / TLWidget.zoomFactor), 0);

    // draw ticks
    for (int tick = 0; tick <= ticksNum; tick++) {
        int x = tick * secondsPerTick * 1000 / TLWidget.zoomFactor;
        g.drawLine(x, 0, x, majorTickHeight);

        // draw label
        String time = ((tick * secondsPerTick) / 60) + ":" + ((tick * secondsPerTick) % 60);
        //g.drawString(time, x, majorTickHeight);

        Rectangle2D r = g.getFontMetrics().getStringBounds(time, g);
        g.drawString(time, x - (float)r.getWidth() * 0.5f, majorTickHeight + (float)(r.getHeight()));

        // draw minor ticks, per seconds
        int lastSecTick = (int) (totalTime / 1000 < (tick + 1) * secondsPerTick - 1 ? totalTime / 1000 : (tick+1) * secondsPerTick - 1);
        for (int secTick = tick * secondsPerTick + 1; secTick <= lastSecTick; secTick++) {
            int secX = secTick * 1000/TLWidget.zoomFactor;
            g.drawLine(secX, 0, secX, secTickHeight);
        }
    }

    g.setStroke(formerStroke);
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:40,代码来源:TimeTicsWidget.java

示例10: draw

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void draw( Graphics2D g ) {
	Rectangle area = g.getClipBounds();
	currentPoint = null;
	if( !intersects(area) ) return;
	Color color = g.getColor();
	g.setColor( OFF_COLOR );
	GeneralPath path = new GeneralPath();
	float offset = (float)this.offset;
	for( int seg=0 ; seg<cptIndex.length ; seg++ ) {
		path.moveTo( offset+cptX[seg][0], cptY[seg][0] );
		for( int i=0 ; i<cptIndex[seg].length ; i++ ) {
			path.lineTo( offset+cptX[seg][i], cptY[seg][i] );
		}
	}
	g.draw(path);
	double wrap = map.getWrap();
	if(wrap>0) {
		AffineTransform xform = g.getTransform();
		offset += (float)wrap;
		while( mapBounds.getX()+(double)offset < area.getX()+area.getWidth() ) {
			g.translate( (double)wrap, 0.d );
			g.draw(path);
			offset += (float)wrap;
		}
		g.setTransform( xform );
	}
	g.setColor( ON_COLOR );
	drawCurrentSeg(g, true);
	g.setColor( color );
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:31,代码来源:MGGData.java

示例11: drawCoOrdinates

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void drawCoOrdinates(double[]x,double[]y,int size, Graphics2D g){

		GeneralPath path = new GeneralPath();
		path.moveTo(x[0],-y[0]);

		for(int j=1;j<(size+1);j++){
			path.lineTo(x[j], -y[j]);
		}
		path.closePath();
		g.setColor(Color.BLACK);
		g.fill(path);

	}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:14,代码来源:FMSDraw.java

示例12: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics graphics) {
	super.paintComponent(graphics);
	Graphics2D g = (Graphics2D) graphics;
	g.setColor(Color.WHITE);
	g.fillRect(0, 0, getWidth(), getHeight());

	// determine if to use low res image (if available)
	Image imageToUse = image;
	if (minDimension != null) {
		double panelWidth = getWidth();
		double panelHeight = getHeight();
		if (panelWidth < minDimension.getWidth() || panelHeight < minDimension.getHeight()) {
			imageToUse = imageLowResolution;
		}
	}

	if (imageToUse != null) {
		if (!strechImage) {
			if (anchor == VerticalAnchor.BOTTOM) {
				g.drawImage(imageToUse, 0, getHeight() - imageToUse.getHeight(null), imageToUse.getWidth(null),
						imageToUse.getHeight(null), this);
			} else {
				g.drawImage(imageToUse, 0, 0, imageToUse.getWidth(null), imageToUse.getHeight(null), this);
			}
		} else {
			g.drawImage(imageToUse, 0, 0, getWidth(), getHeight(), this);
		}
	}
	paintChildren(graphics);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:32,代码来源:ImagePanel.java

示例13: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
protected void paintComponent(Graphics graphics) {
    SwingTools.disableClearType(this);
    ((Graphics2D)graphics).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Graphics2D g = (Graphics2D)graphics.create();
    ButtonModel model = this.getModel();
    if(model.isEnabled() && (model.isRollover() || model.isSelected())) {
        g.setColor(this.colorHover);
        g.fillRoundRect(0, 0, this.getWidth(), this.getHeight(), 10, 10);
    }

    g.dispose();
    super.paintComponent(graphics);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:14,代码来源:CardButton.java

示例14: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g1) {
	Graphics2D g = (Graphics2D) g1;

	g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, Main.config.getBackgroundOpacity()));
	g.setColor(Main.config.getBackgroundColor());
	g.fillRect(0, 0, this.getWidth(), this.getHeight());
	g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, Main.config.getForegroundOpacity()));
	g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

	BufferedImage colorImage = isActive() ? ColorManager.pressed : ColorManager.unpressed;
	g.drawImage(colorImage, 2, 2, this.getWidth() - 2, this.getHeight() - 2, 0, 0, colorImage.getWidth(), colorImage.getHeight(), this);

	g.setColor(isActive() ? Main.config.getBackgroundColor() : Main.config.getForegroundColor());

	String titleString = getTitle();
	Font titleFont = Main.config.mode.getTitleFont(titleString);
	Point namePos = Main.config.mode.getTitleDrawPosition(g, this, titleString, titleFont);
	g.setFont(titleFont);
	g.drawString(titleString, namePos.x, namePos.y);

	String valueString = getValue();
	Font valueFont = Main.config.mode.getValueFont(valueString);
	Point keyCountPos = Main.config.mode.getValueDrawPosition(g, this, valueString, valueFont);
	g.setFont(valueFont);
	g.drawString(valueString, keyCountPos.x, keyCountPos.y);
}
 
开发者ID:RoanH,项目名称:KeysPerSecond,代码行数:28,代码来源:BasePanel.java

示例15: step2

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Draws standard JMenuBar and border on top of it.
 */
private BufferedImage step2(final JMenuBar menubar) {
    final BufferedImage bi2 = new BufferedImage(W, H, TYPE_INT_ARGB_PRE);
    final Graphics2D g2d2 = bi2.createGraphics();
    g2d2.scale(2, 2);
    g2d2.setColor(Color.RED);
    g2d2.fillRect(0, 0, W, H);
    menubar.paintAll(g2d2);
    menubar.getBorder().paintBorder(menubar, g2d2, menubar.getX(), menubar
            .getX(), menubar.getWidth(), menubar.getHeight());
    g2d2.dispose();
    return bi2;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:MisplacedBorder.java


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