本文整理汇总了Java中java.awt.Graphics2D.drawPolyline方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.drawPolyline方法的具体用法?Java Graphics2D.drawPolyline怎么用?Java Graphics2D.drawPolyline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Graphics2D
的用法示例。
在下文中一共展示了Graphics2D.drawPolyline方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paintComponent
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g.create();
g2d.translate(-getX(), -getY());
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(Color.BLUE);
int[] xs = new int[points.length];
int[] ys = new int[points.length];
for (int i = 0; i < points.length; i++) {
xs[i] = points[i].x;
ys[i] = points[i].y;
}
g2d.setColor(UIHelper.getColor("NodeConnection.border"));
g2d.setStroke(new BasicStroke(3));
g2d.drawPolyline(xs, ys, points.length);
g2d.setPaint(new GradientPaint(points[0], UIHelper.getColor("NodeConnection.color1"), points[points.length - 1], UIHelper.getColor("NodeConnection.color2")));
g2d.setStroke(new BasicStroke(1.5f));
g2d.drawPolyline(xs, ys, points.length);
g2d.dispose();
}
示例2: DoPaint
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void DoPaint(Graphics2D g) {
super.DoPaint(g);
Stroke bkp = g.getStroke();
g.setPaint(getForeColor());
if (getPontosParaDesenho() != null) {
if (isDashed()) {
g.setStroke(new BasicStroke(getLargura(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{1, 2}, 0));
} else {
g.setStroke(new BasicStroke(
getLargura(),
BasicStroke.CAP_ROUND,
BasicStroke.JOIN_ROUND));
}
g.drawPolyline(pontosParaDesenhoX, pontosParaDesenhoY, pontosParaDesenhoX.length);
}
g.setStroke(bkp);
}
示例3: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
protected void paint(XYItem item, List<ItemSelection> highlighted,
List<ItemSelection> selected, Graphics2D g,
Rectangle dirtyArea, SynchronousXYChartContext context) {
int valuesCount = item.getValuesCount();
int extraTrailing = fillColor != null ? 2 : 0;
Rectangle dirtyExtended = new Rectangle(dirtyArea);
dirtyExtended.x -= lineWidth;
dirtyExtended.width += lineWidth * 2;
int[][] idxs = computer.getVisible(dirtyExtended, valuesCount, context, 1,
extraTrailing);
if (idxs == null) return;
int[] visibleIndexes = idxs[0];
int npoints = idxs[1][0];
int[][] points = computer.createPoints(visibleIndexes, npoints, item,
dataFactor, context);
if (fillColor != null) {
points[0][npoints - 2] = points[0][npoints - 3];
points[1][npoints - 2] = computer.getZeroY(context);
points[0][npoints - 1] = points[0][0];
points[1][npoints - 1] = points[1][npoints - 2];
POLYGON.xpoints = points[0];
POLYGON.ypoints = points[1];
POLYGON.npoints = npoints;
g.setPaint(fillColor);
g.fill(POLYGON);
}
if (lineColor != null) {
g.setPaint(lineColor);
g.setStroke(lineStroke);
g.drawPolyline(points[0], points[1], npoints - extraTrailing);
}
}
示例4: test
import java.awt.Graphics2D; //导入方法依赖的package包/类
private static void test(final Graphics2D g, final int[] arr) {
g.drawPolygon(arr, arr, arr.length);
g.drawPolygon(new Polygon(arr, arr, arr.length));
g.fillPolygon(arr, arr, arr.length);
g.fillPolygon(new Polygon(arr, arr, arr.length));
g.drawPolyline(arr, arr, arr.length);
}
示例5: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
protected void paint(XYItem item, List<ItemSelection> highlighted,
List<ItemSelection> selected, Graphics2D g,
Rectangle dirtyArea, SynchronousXYChartContext context) {
if (item.getValuesCount() < 2) return;
if (context.getViewWidth() == 0 || context.getViewHeight() == 0) return;
int[][] points = createPoints(item, dirtyArea, context, type, maxValueOffset);
if (points == null) return;
int[] xPoints = points[0];
int[] yPoints = points[1];
int npoints = xPoints.length;
//long start = System.nanoTime();
if (fillColor != null) {
int zeroY = Utils.checkedInt(context.getViewY(context.getDataOffsetY()));
zeroY = Math.max(Utils.checkedInt(context.getViewportOffsetY()), zeroY);
zeroY = Math.min(Utils.checkedInt(context.getViewportOffsetY() +
context.getViewportHeight()), zeroY);
Polygon polygon = new Polygon();
polygon.xpoints = xPoints;
polygon.ypoints = yPoints;
polygon.npoints = npoints;
polygon.xpoints[npoints - 2] = xPoints[npoints - 3];
polygon.ypoints[npoints - 2] = zeroY;
polygon.xpoints[npoints - 1] = xPoints[0];
polygon.ypoints[npoints - 1] = zeroY;
g.setPaint(fillColor);
g.fill(polygon);
}
if (lineColor != null) {
g.setPaint(lineColor);
g.setStroke(lineStroke);
g.drawPolyline(xPoints, yPoints, npoints - 2);
}
//System.err.println(">>> Paint: " + (System.nanoTime() - start) / 1000 + " [ms], dirtyArea: " + dirtyArea);
// if (type == TYPE_RELATIVE) {
// g.setColor(Color.RED);
// Rectangle bbox = new Rectangle(dirtyArea);
//// bbox.width -= 1;
//// bbox.height -= 1;
// g.draw(bbox);
//// System.err.println(">>> Here");
// }
// if (type == TYPE_RELATIVE_BOUNDED) {
// System.err.println(">>> paintItem, dirtyArea: " + dirtyArea);
// }
}
示例6: drawData
import java.awt.Graphics2D; //导入方法依赖的package包/类
private synchronized void drawData(Graphics2D g2) {
int n;
int [] x;
int [] y;
int length = 0;
g2.setStroke(new BasicStroke());
for(Iterator<GraphData> it = currentGraphs.values().iterator(); it.hasNext(); ) {
GraphData dt = it.next();
g2.setColor(dt.Color);
synchronized (dt.Y) {
switch(dt.DataType) {
case YScrolling:
length = Math.min(this.getWidth(), dt.Y.size());
x = new int[length];
y = new int[length];
int l = dt.Y.size() - length;
for(n = 0; n < length;n++ ) {
x[n] = n;
y[n] = (int)(this.getHeight()- (dt.Y.get(l + n) - (double)getMinY())/(double)(max_y - getMinY())*this.getHeight());
}
break;
case YScaling:
length = this.getWidth();
x = new int[length];
y = new int[length];
double scale = ((double) dt.Y.size() ) / (double)length;
for(n = 0; n < length ;n++ ) {
x[n] = n;
y[n] = (int)(this.getHeight()- (dt.Y.get((int)(n*scale)) - (double)getMinY())/(double)(max_y - getMinY())*this.getHeight());
}
break;
case XY:
assert(dt.X.size() == dt.Y.size());
length = dt.X.size();
x = new int[length];
y = new int[length];
for(n = 0; n < length;n++ ) {
x[n] = (int)((dt.X.get(n) - (double)getMinX())/(double)(max_x - getMinX())*this.getWidth());
y[n] = (int)(this.getHeight()- (dt.Y.get(n) - (double)getMinY())/(double)(max_y - getMinY())*this.getHeight());
}
break;
default:
length = 0;
x = new int[length];
y = new int[length];
}
if(dt.Style == LineStyle.Point || dt.Style == LineStyle.PointLine) {
for(n = 0; n < length ;n++ ) {
g2.setStroke(new BasicStroke(3.0f));
g2.drawOval(x[n] - 2, y[n] -2, 4 , 4);
g2.setStroke(new BasicStroke(1.0f));
}
}
if(dt.Style == LineStyle.Line || dt.Style == LineStyle.PointLine) {
g2.drawPolyline(x, y, length);
}
}
}
}
示例7: drawPolylineBAD
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void drawPolylineBAD(Graphics2D g, int[] xp, int[] yp) {
int offset = 200;
g.translate(0, offset);
g.drawPolyline(xp, yp, xp.length);
}
示例8: main
import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void main(String[] args) {
DrawFrame df = DrawFrame.create("MyDrawing", 200, 300);
Graphics2D g = df.getGraphics2D();
float linewidth = 5.0f; // line width = 5 pixels
g.setStroke(new BasicStroke(linewidth));
g.setColor(Color.BLUE);
g.drawLine(40, 10, 10, 40);
g.draw(new Line2D.Double(70.2, 10.3, 100.4, 40.5));
g.fillOval(10, 60, 30, 30);
g.drawOval(60, 60, 30, 30);
g.fillRoundRect(110, 60, 30, 30, 10, 10);
g.drawRoundRect(160, 60, 30, 30, 10, 10);
g.setColor(Color.GREEN.darker());
g.fillArc(10, 110, 30, 30, 45, 240);
g.fillArc(60, 110, 30, 30, 45 + 240, 360 - 240);
g.fillArc(110, 110, 30, 30, 90, 270);
g.fillArc(160, 110, 30, 30, 270, 270);
g.setColor(Color.MAGENTA);
g.drawArc(10, 160, 30, 30, 45, 240);
g.drawArc(60, 160, 30, 30, 45 + 240, 360 - 240);
g.drawArc(110, 160, 30, 30, 90, 270);
g.drawArc(160, 160, 30, 30, 270, 270);
g.setColor(Color.ORANGE);
g.fillPolygon(new int[] { 10, 40, 10, 40 }, new int[] { 210, 210, 240, 240 }, 4);
g.drawPolygon(new int[] { 60, 90, 60, 90 }, new int[] { 210, 210, 240, 240 }, 4);
g.drawPolyline(new int[] { 110, 140, 110, 140 }, new int[] { 210, 210, 240, 240 }, 4);
g.drawPolyline(new int[] { 160, 160, 190, 190 }, new int[] {240, 210, 240, 210 }, 4);
// Printing texts
g.setColor(Color.BLACK);
g.setFont(new Font("Monospaced", Font.PLAIN, 14));
g.drawString("Drawn with JGraphix", 10, 275);
df.refresh();
System.out.println("done.");
}