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


Java Graphics2D类代码示例

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


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

示例1: draw

import java.awt.Graphics2D; //导入依赖的package包/类
@Override
public void draw(Graphics2D graphics) {
	graphics.setStroke(JSpaceSettlersComponent.THIN_STROKE);
	
       final AffineTransform transform =
               AffineTransform.getTranslateInstance(drawLocation.getX(), drawLocation.getY());
       transform.rotate(-Math.PI / 2.0);

   	transform.scale(scale, scale);

       Shape newFlagShape = transform.createTransformedShape(FLAG_SHAPE);

       // color the flag to match the team
       graphics.setPaint(flagColor);
       graphics.fill(newFlagShape);
}
 
开发者ID:amymcgovern,项目名称:spacesettlers,代码行数:17,代码来源:FlagGraphics.java

示例2: resizeToBig

import java.awt.Graphics2D; //导入依赖的package包/类
private Image resizeToBig(Image originalImage, int biggerWidth, int biggerHeight) {
    final BufferedImage resizedImage = new BufferedImage(biggerWidth, biggerHeight,
        BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g = resizedImage.createGraphics();

    g.setComposite(AlphaComposite.Src);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
        RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g.drawImage(originalImage, 0, 0, biggerWidth, biggerHeight, this);
    g.dispose();

    return resizedImage;
}
 
开发者ID:bcgov,项目名称:sbc-qsystem,代码行数:17,代码来源:FCallDialog.java

示例3: paintComponent

import java.awt.Graphics2D; //导入依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform origXform = g2d.getTransform();
    AffineTransform newXform = (AffineTransform) (origXform.clone());
    //center of rotation is center of the panel
    int xRot = this.getWidth() / 2;
    int yRot = this.getHeight() / 2;
    newXform.rotate((2 * Math.PI) - currentAngle, xRot, yRot);
    g2d.setTransform(newXform);
    //draw image centered in panel
    int x = (getWidth() - image.getWidth(this)) / 2;
    int y = (getHeight() - image.getHeight(this)) / 2;
    g2d.drawImage(image, x, y, this);
    g2d.setTransform(origXform);
}
 
开发者ID:Esri,项目名称:defense-solutions-proofs-of-concept,代码行数:18,代码来源:RotatableImagePanel.java

示例4: drawVerticalLine

import java.awt.Graphics2D; //导入依赖的package包/类
/**
 * Utility method for drawing a vertical line on the data area of the plot.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param value  the coordinate, where to draw the line.
 * @param stroke  the stroke to use.
 * @param paint  the paint to use.
 */
protected void drawVerticalLine(Graphics2D g2, Rectangle2D dataArea,
                                double value, Stroke stroke, Paint paint) {

    ValueAxis axis = getDomainAxis();
    if (getOrientation() == PlotOrientation.HORIZONTAL) {
        axis = getRangeAxis();
    }
    if (axis.getRange().contains(value)) {
        double xx = axis.valueToJava2D(value, dataArea, 
                RectangleEdge.BOTTOM);
        Line2D line = new Line2D.Double(xx, dataArea.getMinY(), xx, 
                dataArea.getMaxY());
        g2.setStroke(stroke);
        g2.setPaint(paint);
        g2.draw(line);
    }

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:28,代码来源:XYPlot.java

示例5: PathGraphics

import java.awt.Graphics2D; //导入依赖的package包/类
protected PathGraphics(Graphics2D graphics, PrinterJob printerJob,
                       Printable painter, PageFormat pageFormat,
                       int pageIndex, boolean canRedraw) {
    super(graphics, printerJob);

    mPainter = painter;
    mPageFormat = pageFormat;
    mPageIndex = pageIndex;
    mCanRedraw = canRedraw;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:PathGraphics.java

示例6: medidaH

import java.awt.Graphics2D; //导入依赖的package包/类
private void medidaH(Graphics2D g, int l, int t) {
    FontMetrics fm = g.getFontMetrics();
    String vl = dono.FormateUnidadeMedida(width);
    int xini = l;
    int pre_y = t;
    int xfim = l + width;
    int yfim = t + height / 2;

    int traco = height;
    int ytraco = pre_y;// - (traco/2);

    g.drawLine(xini, ytraco, xini, ytraco + traco);
    g.drawLine(xfim, ytraco, xfim, ytraco + traco);
    g.drawLine(xini, yfim, xfim, yfim);

    xini = xini + (width - fm.stringWidth(vl)) / 2;
    int yini = invertido ? yfim + (fm.getHeight() - fm.getDescent()) : yfim - fm.getDescent();// yfim + (fm.getHeight()) / 2 - fm.getDescent();
    g.drawString(vl, xini, yini);
}
 
开发者ID:chcandido,项目名称:brModelo,代码行数:20,代码来源:baseDrawerItem.java

示例7: init

import java.awt.Graphics2D; //导入依赖的package包/类
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    double theta = Math.toRadians(15);
    double cos = Math.cos(theta);
    double sin = Math.sin(theta);
    double xsize = sin * h + cos * w;
    double ysize = sin * w + cos * h;
    double scale = Math.min(w / xsize, h / ysize);
    xsize *= scale;
    ysize *= scale;
    AffineTransform at = new AffineTransform();
    at.translate((w - xsize) / 2.0, (h - ysize) / 2.0);
    at.translate(sin * h * scale, 0.0);
    at.rotate(theta);
    g2d.transform(at);
    dim.setSize(scaleForTransform(at, dim));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:GraphicsTests.java

示例8: draw

import java.awt.Graphics2D; //导入依赖的package包/类
/**
 * Draws the frame.  This method is called by the {@link DialPlot} class,
 * you shouldn't need to call it directly.
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the plot (<code>null</code> not permitted).
 * @param frame  the frame (<code>null</code> not permitted).
 * @param view  the view (<code>null</code> not permitted).
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
        Rectangle2D view) {
    
    Shape window = getWindow(frame);
    
    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius + 0.02, 
            this.radius + 0.02);
    Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), 
            f.getHeight());
    
    Area area = new Area(e);
    Area area2 = new Area(window);
    area.subtract(area2);
    g2.setPaint(this.backgroundPaint);
    g2.fill(area);
    
    g2.setStroke(this.stroke);
    g2.setPaint(this.foregroundPaint);
    g2.draw(window);
    g2.draw(e);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:31,代码来源:SimpleDialFrame.java

示例9: getPreferredWidth

import java.awt.Graphics2D; //导入依赖的package包/类
/**
 * Returns the preferred width of the title.  This will only be called when the title
 * is being drawn at the left or right of a chart.
 *
 * @param g2  the graphics device.
 * @param height  the height.
 *
 * @return The preferred width of the title.
 */
public float getPreferredWidth(Graphics2D g2, float height) {
    float result = 0.0f;
    if (this.text != null && !this.text.equals("")) {
        g2.setFont(this.font);
        TextBlock title = TextUtilities.createTextBlock(
            this.text, this.font, this.paint, height, new G2TextMeasurer(g2)
        );
        Size2D d = title.calculateDimensions(g2);
        result = (float) getSpacer().getAdjustedWidth(d.getHeight());
                                                 // use height here because the title
                                                 // is displayed rotated
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Title preferred width = " + result);   
    }
    return result;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:27,代码来源:TextTitle.java

示例10: paintEastArrow

import java.awt.Graphics2D; //导入依赖的package包/类
private void paintEastArrow(Graphics2D g2, int w, int h, boolean isPressed, boolean isRollover) {
	g2.setColor(Colors.SCROLLBAR_ARROW_BORDER);
	g2.drawLine(0, 0, w - 1, 0);

	if (isPressed) {
		g2.setColor(Colors.SCROLLBAR_ARROW_PRESSED);
	} else if (isRollover) {
		g2.setColor(Colors.SCROLLBAR_ARROW_ROLLOVER);
	} else {
		g2.setColor(Colors.SCROLLBAR_ARROW);
	}

	g2.setStroke(ARROW_STROKE);
	g2.drawLine(6, OFFSET, w - 6, h / 2);
	g2.drawLine(w - 6, h / 2, 6, h - OFFSET);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:17,代码来源:GenericArrowButton.java

示例11: createComponentImage

import java.awt.Graphics2D; //导入依赖的package包/类
protected static BufferedImage createComponentImage(int w, int h,
                                                    ComponentColorModel cm)
{
    WritableRaster wr = cm.createCompatibleWritableRaster(w, h);

    BufferedImage img = new BufferedImage(cm, wr, false, null);
    Graphics2D g = img.createGraphics();
    int width = w / 8;
    Color[] colors = new Color[8];
    colors[0] = Color.red;
    colors[1] = Color.green;
    colors[2] = Color.blue;
    colors[3] = Color.white;
    colors[4] = Color.black;
    colors[5] = new Color(0x80, 0x80, 0x80, 0x00);
    colors[6] = Color.yellow;
    colors[7] = Color.cyan;

    for (int i = 0; i < 8; i++) {
        g.setColor(colors[i]);
        g.fillRect(i * width, 0, width, h);
    }
    return img;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:IndexingTest.java

示例12: 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

示例13: 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

示例14: 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

示例15: createMap

import java.awt.Graphics2D; //导入依赖的package包/类
public BufferedImage createMap(ItemMap mapItem) {
    new ArrayList<>();
    List<BaseFullChunk> chunks = new ArrayList<>();
    Color[][] blockColors = new Color[16][16];
    BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = (Graphics2D)img.getGraphics();

    chunks.add(this.level.getChunk((int) this.x >> 4, (int) this.z >> 4, false));
    for(int x=0;x < 16;x++){
        for( int y=0;y < 16;y++){
            blockColors[x][y] = Block.get(chunks.get(0).getHighestBlockAt((int)this.x, (int)this.z)).getColor();
            g2.drawImage(img, x, y, blockColors[x][y], null);
        }
    }

    BufferedImage data = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);
    data.createGraphics().drawImage(img, 0, 0, null);
    return data;
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:20,代码来源:Player.java


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