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


Java Graphics2D.drawLine方法代码示例

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


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

示例1: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paint(final Graphics gr) {
    super.paint(gr);
    int l = getWidth();
    if (l > getHeight())
        l = getHeight();
    l /= 2;
    final int x = (getWidth() - l) / 2;
    final int y = (getHeight() - l) / 2;
    final Graphics2D g = (Graphics2D) gr;

    g.setColor(getBackground());
    final Insets is = getBorder().getBorderInsets(this);
    g.fillRect(is.left, is.right, getWidth() - is.right - is.left,
            getHeight() - is.bottom - is.left);
    final Color f = getForeground();
    g.setColor(new Color(255 - (255 - f.getRed()) / 2, 255 - (255 - f
            .getGreen()) / 2, 255 - (255 - f.getBlue()) / 2));
    g.setStroke(new BasicStroke(3.0f/*
                                     * , BasicStroke.CAP_ROUND,
			 * BasicStroke.JOIN_ROUND
			 */));
    g.drawLine(x, y, x + l, y + l);
    g.drawLine(x, y + l, x + l, y);

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

示例2: draw

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Draws a line trough all path's coordinates.
 * @param g2 The graphics context to draw to
 */
@Override
public void draw(Graphics2D g2) {
	if (coords == null) {
		return;
	}
	
	g2.setColor(PATH_COLOR);
	Coord prev = coords.get(0);
	
	for (int i=1, n=coords.size(); i < n; i++) {
		Coord next = coords.get(i);
		g2.drawLine(scale(prev.getX()), scale(prev.getY()),
				scale(next.getX()), scale(next.getY()));
		prev = next;
	}
}
 
开发者ID:mdonnyk,项目名称:the-one-mdonnyk,代码行数:21,代码来源:PathGraphic.java

示例3: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
    if( isAquaLaF && g instanceof Graphics2D ) {
        Graphics2D g2d = (Graphics2D) g;
        Color col1 = UIManager.getColor("NbExplorerView.quicksearch.background.top"); //NOI18N
        Color col2 = UIManager.getColor("NbExplorerView.quicksearch.background.bottom"); //NOI18N
        Color col3 = UIManager.getColor("NbExplorerView.quicksearch.border"); //NOI18N
        if( col1 != null && col2 != null && col3 != null ) {
            g2d.setPaint( new GradientPaint(0, 0, col1, 0, getHeight(), col2));
            g2d.fillRect(0, 0, getWidth(), getHeight());
            g2d.setColor( col3 );
            g2d.drawLine(0, 0, getWidth(), 0);
            return;
        }
    }
    super.paintComponent(g);
    g.setColor( UIManager.getColor( "PropSheet.setBackground" ) ); //NOI18N
    g.drawLine(0, 0, getWidth(), 0);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:PalettePanel.java

示例4: drawLineAtAge

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void drawLineAtAge( int currentAge )	{
	if ( exists ) {
		synchronized (getTreeLock()) {
			Graphics2D g = (Graphics2D)getGraphics();
			Rectangle r = getVisibleRect();
			int x1 = r.x;
			int x2 = r.x+r.width;
			g.setXORMode( Color.cyan );
			if ( prevAge != -1)	{
				g.drawLine(x1, prevAge, x2, prevAge);
			}
			g.drawLine(x1, currentAge, x2, currentAge);
			prevAge = currentAge;
		}
	}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:17,代码来源:CoreDescriptionsDisplay.java

示例5: IconButton

import java.awt.Graphics2D; //导入方法依赖的package包/类
public IconButton(int type, int size, Color color, float width) {
  super();

  setMinimumSize(new Dimension(size, size));
  setPreferredSize(new Dimension(size, size));

  final BufferedImage image =
    ImageUtils.createCompatibleTranslucentImage(size, size);

  final Graphics2D g = image.createGraphics();
  g.setStroke(new BasicStroke(width));
  g.setColor(color);

  switch (type) {
  case PLUS_ICON:
    g.drawLine(5, size / 2, size - 5, size / 2);
    g.drawLine(size / 2, 5, size / 2, size - 5);
    break;
  case MINUS_ICON:
    g.drawLine(5, size / 2, size - 5, size / 2);
    break;
  case TICK_ICON:
    g.drawLine(5, size/2, size/2, size-5);
    g.drawLine(size/2, size-5, 5, size-5);
    break;
  case CROSS_ICON:
    g.drawLine(5, 5, size-5, size-5);
    g.drawLine(5, size-5, size-5, 5);
    break;
  }
  setIcon(new ImageIcon(image));
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:33,代码来源:IconButton.java

示例6: drawGridlines

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Draw the gridlines for the grid. We only draw the portion of the
 * lines that intersect the current clipping bounds.
 *
 * @param g2 the Graphics2 object to use to render
 */
private void drawGridlines(Graphics2D g2) {
    Rectangle curClip = g2.getClip().getBounds();
    int top = getInsets().top, left = getInsets().left;

    int miny = Math.max(0, (curClip.y - top) / (cellSize + 1)) * (cellSize + 1) + top;
    int minx = Math.max(0, (curClip.x - left) / (cellSize + 1)) * (cellSize + 1) + left;
    int maxy = Math.min(numRows,
            (curClip.y + curClip.height - top + cellSize) / (cellSize + 1))
            * (cellSize + 1) + top;
    int maxx = Math.min(numCols,
            (curClip.x + curClip.width - left + cellSize) / (cellSize + 1))
            * (cellSize + 1) + left;

    g2.setColor(Color.GRAY);
    for (int y = miny; y <= maxy; y += cellSize + 1)
        for (int x = minx; x <= maxx; x += cellSize + 1) {
            Location loc = locationForPoint(
                    new Point(x + cellSize / 2, y + cellSize / 2));
            if (loc != null && !grid.isValid(loc))
                g2.fillRect(x + 1, y + 1, cellSize, cellSize);
        }

    g2.setColor(Color.BLACK);
    for (int y = miny; y <= maxy; y += cellSize + 1)
        // draw horizontal lines
        g2.drawLine(minx, y, maxx, y);

    for (int x = minx; x <= maxx; x += cellSize + 1)
        // draw vertical lines
        g2.drawLine(x, miny, x, maxy);
}
 
开发者ID:CBSkarmory,项目名称:AWGW,代码行数:38,代码来源:GridPanel.java

示例7: main

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void main(final String[] args) throws IOException {
    for (int  point = 5; point < 11; ++point) {
        Graphics2D g2d = bi.createGraphics();
        g2d.setFont(new Font(Font.DIALOG, Font.PLAIN, point));
        g2d.scale(scale, scale);
        g2d.setColor(Color.WHITE);
        g2d.fillRect(0, 0, width, height);
        g2d.setColor(Color.green);
        g2d.drawString(TEXT, 0, 20);
        int length = g2d.getFontMetrics().stringWidth(TEXT);
        if (length < 0) {
            throw new RuntimeException("Negative length");
        }
        for (int i = (length + 1) * scale; i < width; ++i) {
            for (int j = 0; j < height; ++j) {
                if (bi.getRGB(i, j) != Color.white.getRGB()) {
                    g2d.drawLine(length, 0, length, height);
                    ImageIO.write(bi, "png", new File("image.png"));
                    System.out.println("length = " + length);
                    System.err.println("Wrong color at x=" + i + ",y=" + j);
                    System.err.println("Color is:" + new Color(bi.getRGB(i,
                                                                         j)));
                    throw new RuntimeException("Test failed.");
                }
            }
        }
        g2d.dispose();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:IncorrectTextSize.java

示例8: drawLasso

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
	Draws the last line in polygon poly to XYGraph xyg
	Uses XOR mode
*/
void drawLasso(XYGraph xyg) {
	synchronized (xyg.getTreeLock()) {
		Graphics2D g = (Graphics2D) xyg.getGraphics(); 
		g.setXORMode(Color.GRAY);
		int x1 = poly.xpoints[poly.npoints-2];
		int y1 = poly.ypoints[poly.npoints-2];
		int x2 = poly.xpoints[poly.npoints-1];
		int y2 = poly.ypoints[poly.npoints-1];
		g.drawLine(x1, y1, x2, y2);
	}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:16,代码来源:PDBDataSetGraph.java

示例9: drawLine

import java.awt.Graphics2D; //导入方法依赖的package包/类
void drawLine(XYGraph xyg) {
	if( Float.isNaN(lastV) || side==0) return;
	synchronized (xyg.getTreeLock()) {
		Graphics2D g = (Graphics2D)xyg.getGraphics();
		g.transform(dat);
		g.setXORMode( Color.white );
		g.setColor(Color.blue);
		if (side<0) g.drawLine((int)((lastV-x0)*xScale), y1, (int)((lastV-x0)*xScale), y2);
		else g.drawLine(x1, (int)((lastV-y0)*-yScale), x2, (int)((lastV-y0)*-yScale));
	}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:12,代码来源:PDBDataSetGraph.java

示例10: paintTextLimitLine

import java.awt.Graphics2D; //导入方法依赖的package包/类
static void paintTextLimitLine(Graphics2D g, DocumentView docView, int x, int y, int lastX, int lastY) {
    int textLimitLineX = docView.op.getTextLimitLineX();
    if (textLimitLineX > 0 && textLimitLineX >= x && textLimitLineX <= lastX) {
        g.setColor(docView.op.getTextLimitLineColor());
        g.drawLine(textLimitLineX, y, textLimitLineX, lastY);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:HighlightsViewUtils.java

示例11: drawSimpleNumericalLegend

import java.awt.Graphics2D; //导入方法依赖的package包/类
/** This method can be used to draw a legend on the given graphics context. */
public void drawSimpleNumericalLegend(Graphics graphics, int x, int y, String legendColumnName, String minColorString,
		String maxColorString) {
	Graphics2D g = (Graphics2D) graphics.create();

	// painting label name
	g.setFont(LABEL_FONT_BOLD);
	g.setColor(Color.black);
	g.drawString(legendColumnName, x, y + 1);
	Rectangle2D legendNameBounds = LABEL_FONT.getStringBounds(legendColumnName, g.getFontRenderContext());
	g.translate(legendNameBounds.getWidth() + 5, 0);

	// painting legend
	g.setFont(LABEL_FONT);
	g.setColor(Color.black);
	Rectangle2D minStringBounds = LABEL_FONT.getStringBounds(minColorString, g.getFontRenderContext());

	int keyX = x;
	int keyY = y;

	g.drawString(minColorString, keyX, keyY + 1);
	keyX += minStringBounds.getWidth() + 5;
	for (int i = 0; i < 100; i++) {
		double scaledColor = i / 100.0d;
		Color lineColor = getColorProvider().getPointColor(scaledColor, 255);
		g.setColor(lineColor);
		g.drawLine(keyX, keyY, keyX, keyY - 8);
		keyX++;
	}
	g.setColor(Color.black);
	Rectangle2D frame = new Rectangle2D.Double(keyX - 101, keyY - 8, 101, 8);
	g.draw(frame);
	keyX += 4;
	g.drawString(maxColorString, keyX, keyY + 1);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:36,代码来源:PlotterAdapter.java

示例12: unDrawLasso

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
	undraws the polygon represented by poly
*/
void unDrawLasso(XYGraph xyg){
	synchronized (xyg.getTreeLock()) {
		Graphics2D g = (Graphics2D) xyg.getGraphics(); 
		g.setXORMode(Color.GRAY);
		for(int i=1;i<poly.npoints;i++) {
			g.drawLine(poly.xpoints[i-1], poly.ypoints[i-1], poly.xpoints[i], poly.ypoints[i]);
		}
	}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:13,代码来源:DataSetGraph.java

示例13: drawInstance

import java.awt.Graphics2D; //导入方法依赖的package包/类
private void drawInstance(InstancePainter painter, boolean isGhost) {
	Bounds bds = painter.getBounds();
	Object powerLoc = painter.getAttributeValue(Wiring.ATTR_GATE);
	Direction facing = painter.getAttributeValue(StdAttr.FACING);
	boolean flip = (facing == Direction.SOUTH || facing == Direction.WEST) == (powerLoc == Wiring.GATE_TOP_LEFT);

	int degrees = Direction.WEST.toDegrees() - facing.toDegrees();
	if (flip)
		degrees += 180;
	double radians = Math.toRadians((degrees + 360) % 360);

	Graphics2D g = (Graphics2D) painter.getGraphics().create();
	g.rotate(radians, bds.getX() + 20, bds.getY() + 20);
	g.translate(bds.getX(), bds.getY());
	GraphicsUtil.switchToWidth(g, Wire.WIDTH);

	Color gate0 = g.getColor();
	Color gate1 = gate0;
	Color input = gate0;
	Color output = gate0;
	Color platform = gate0;
	if (!isGhost && painter.getShowState()) {
		gate0 = painter.getPort(GATE0).getColor();
		gate1 = painter.getPort(GATE0).getColor();
		input = painter.getPort(INPUT).getColor();
		output = painter.getPort(OUTPUT).getColor();
		platform = computeOutput(painter).getColor();
	}

	g.setColor(flip ? input : output);
	g.drawLine(0, 20, 11, 20);
	g.drawLine(11, 13, 11, 27);

	g.setColor(flip ? output : input);
	g.drawLine(29, 20, 40, 20);
	g.drawLine(29, 13, 29, 27);

	g.setColor(gate0);
	g.drawLine(20, 35, 20, 40);
	GraphicsUtil.switchToWidth(g, 1);
	g.drawOval(18, 30, 4, 4);
	g.drawLine(10, 30, 30, 30);
	GraphicsUtil.switchToWidth(g, Wire.WIDTH);

	g.setColor(gate1);
	g.drawLine(20, 9, 20, 0);
	GraphicsUtil.switchToWidth(g, 1);
	g.drawLine(10, 10, 30, 10);

	g.setColor(platform);
	g.drawLine(9, 12, 31, 12);
	g.drawLine(9, 28, 31, 28);
	if (flip) { // arrow
		g.drawLine(18, 17, 21, 20);
		g.drawLine(18, 23, 21, 20);
	} else {
		g.drawLine(22, 17, 19, 20);
		g.drawLine(22, 23, 19, 20);
	}

	g.dispose();
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:63,代码来源:TransmissionGate.java

示例14: drawAct

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void drawAct(Graphics2D g2d, Point center, String title, String bodyText,
		boolean isExec, boolean isPend, boolean isPetri) {
	
	int leftX = center.x - Constants.ACTIVITY_WIDTH / 2;
	int rightX = center.x + Constants.ACTIVITY_WIDTH /2;
	int upperY = center.y - Constants.ACTIVITY_HEIGHT / 2;
	int lineY = upperY + Constants.HEADER_HEIGHT;
	
    // border
	g2d.setColor(Constants.ACTIVITY_BACKGROUND_COLOR);
	g2d.fillRect(leftX, upperY, Constants.ACTIVITY_WIDTH, Constants.ACTIVITY_HEIGHT);
	g2d.setColor(Color.BLACK);
	g2d.drawRect(leftX, upperY, Constants.ACTIVITY_WIDTH, Constants.ACTIVITY_HEIGHT);
	g2d.drawLine(leftX, lineY, rightX, lineY);
	
	// font
	g2d.setFont(Constants.BASIC_FONT);
	FontMetrics metrics = g2d.getFontMetrics(g2d.getFont());
	
	// title
    int xTitle = leftX + (Constants.ACTIVITY_WIDTH - metrics.stringWidth(title)) / 2;
    int yTitle = upperY + ((Constants.HEADER_HEIGHT - metrics.getHeight()) / 2) + metrics.getAscent();
    g2d.drawString(title, xTitle, yTitle);
	  
    // body text
    int xBody = leftX + (Constants.ACTIVITY_WIDTH - metrics.stringWidth(bodyText)) / 2;
    int yBody = upperY + Constants.LINE_HEIGHT + Constants.HEADER_HEIGHT + 9 + g2d.getFontMetrics().getHeight();
    g2d.drawString(bodyText, xBody, yBody);
    
    // checkmark
    if (isExec) {
    	g2d.setFont(Constants.CHECKMARK_FONT);
	    g2d.setColor(Constants.CHECKMARK_COLOR);
	    int xCheck = leftX + Constants.PETRI_MARGIN;
	    int yCheck = upperY + Constants.HEADER_HEIGHT + 20;
	    g2d.drawString(Constants.CHECKMARK_SYMB, xCheck, yCheck);
    }
    
    // exclamation mark
    if (isPend) {
    	g2d.setFont(Constants.EXCLAMATION_FONT);
	    g2d.setColor(Constants.EXCLAMATION_COLOR);
	    int xExclam = rightX - Constants.PETRI_MARGIN - 10;
	    int yExclam = upperY + Constants.HEADER_HEIGHT + 20;
	    g2d.drawString(Constants.EXCLAMATION_SYMB, xExclam, yExclam);
    }
    
    // Petri
    if (isPetri) {
    	g2d.setColor(Color.BLACK);
	    g2d.setFont(Constants.BASIC_FONT);
	    g2d.drawRect(leftX + Constants.PETRI_MARGIN, lineY + Constants.PETRI_MARGIN,
			Constants.ACTIVITY_WIDTH - 2 * Constants.PETRI_MARGIN, Constants.ACTIVITY_HEIGHT - Constants.HEADER_HEIGHT - 2 * Constants.PETRI_MARGIN);
    } 
}
 
开发者ID:tslaats,项目名称:SE2017-Team1,代码行数:56,代码来源:TestUtil.java

示例15: drawVerticalTargetLine

import java.awt.Graphics2D; //导入方法依赖的package包/类
private static void drawVerticalTargetLine(Graphics2D g, int x, int y, int len) {
    g.setColor(DROP_TARGET_COLOR);
    g.setStroke(DROP_TARGET_LINE_STROKE);
    g.drawLine(x-1, y, x-1, y+len);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:6,代码来源:DropTargetLayer.java


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