List of usage examples for java.awt Graphics2D draw
public abstract void draw(Shape s);
From source file:dataminning2.KmeanGraphplot.java
protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = getWidth(); int h = getHeight(); // Draw ordinate. g2.draw(new Line2D.Double(PAD, PAD, PAD, h - PAD)); // Draw abcissa. g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD, h - PAD)); double xInc = (double) (w - 2 * PAD) / (data.length - 1); double scale = (double) (h - 2 * PAD) / 88; // Mark data points. g2.setPaint(Color.red);//from w w w . j a v a 2 s. co m for (int i = 0; i < cluster0.length; i++) { double x = PAD + i * dataX[i]; double y = h - PAD - scale * dataY[i]; g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4)); } g2.setPaint(Color.BLUE); for (int i = 0; i < cluster1.length; i++) { double x = PAD + i * dataX[i]; double y = h - PAD - scale * dataY[i]; g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4)); } g2.setPaint(Color.YELLOW); for (int i = 0; i < cluster2.length; i++) { double x = PAD + i * dataX[i]; double y = h - PAD - scale * dataY[i]; g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4)); } }
From source file:ec.util.chart.swing.JTimeSeriesRendererSupport.java
static void drawToolTip(Graphics2D g2, double x, double y, double anchorOffset, String label, Font font, Paint paint, Paint fillPaint, Paint outlinePaint, Stroke outlineStroke) { LabelBlock block = new LabelBlock(label/*.replace("\n", "")*/, font, paint); block.setMargin(3, 3, 3, 3);// w w w . j av a 2 s .c o m Rectangle2D hotspot = createHotspot(g2, x, y, anchorOffset + 10, block.arrange(g2)); Shape shape = createShape(x, y, hotspot); if (fillPaint != null) { g2.setPaint(fillPaint); g2.fill(shape); } if (outlinePaint != null && outlineStroke != null) { g2.setStroke(outlineStroke); g2.setPaint(outlinePaint); g2.draw(shape); } block.draw(g2, hotspot); }
From source file:BasicDraw.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; float strokeThickness = 5.0f; float miterLimit = 10f; float[] dashPattern = { 10f }; float dashPhase = 5f; BasicStroke stroke = new BasicStroke(strokeThickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, miterLimit, dashPattern, dashPhase); g2d.setStroke(stroke);//from www . j ava2 s.c o m g2d.draw(new Rectangle(20, 20, 200, 200)); }
From source file:business.model.CaptchaModel.java
/** * * @param CaptchaText//from w w w .j a v a 2 s .c o m * @return */ public static BufferedImage CreateCaptchaImageOld(String CaptchaText) { BufferedImage localBufferedImage = new BufferedImage(width, height, 1); try { Graphics2D localGraphics2D = localBufferedImage.createGraphics(); // List<Font> fonts = FontFactory.getListFont(); List<Font> fonts = new ArrayList<Font>(); if (fonts.isEmpty()) { fonts.add(new Font("Nimbus Roman No9 L", 1, 30)); fonts.add(new Font("VN-NTime", 1, 30)); fonts.add(new Font("DT-Times", 1, 30)); fonts.add(new Font("Times New Roman", 1, 30)); fonts.add(new Font("Vni-Book123", 1, 30)); fonts.add(new Font("VNI-Centur", 1, 30)); fonts.add(new Font("DT-Brookly", 1, 30)); } // fonts.add(loadFont("BINHLBI.TTF")); RenderingHints localRenderingHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); localRenderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); localGraphics2D.setRenderingHints(localRenderingHints); localGraphics2D.fillRect(0, 0, width, height); localGraphics2D.setColor(new Color(50, 50, 50)); Random localRandom = new Random(); int i = 0; int j = 0; for (int k = 0; k < CaptchaText.length(); k++) { i += 25 + Math.abs(localRandom.nextInt()) % 5; j = 25 + Math.abs(localRandom.nextInt()) % 20; int tmp = localRandom.nextInt(fonts.size() - 1); localGraphics2D.setFont(fonts.get(tmp)); localGraphics2D.drawChars(CaptchaText.toCharArray(), k, 1, i, j); } localBufferedImage = getDistortedImage(localBufferedImage); Graphics2D localGraphics2D2 = localBufferedImage.createGraphics(); localGraphics2D2.setRenderingHints(localRenderingHints); // localGraphics2D2.fillRect(0, 0, width, height); localGraphics2D2.setColor(new Color(50, 50, 50)); CubicCurve2D c = new CubicCurve2D.Double();// draw QuadCurve2D.Float with set coordinates for (int l = 0; l < 7; l++) { int x1 = Util.rand(0, width / 2); ; int x2 = Util.rand(width / 2, width); int y1 = Util.rand(0, height); int y2 = Util.rand(0, height); int ctrlx1 = (x1 + x2) / 4 * Util.rand(1, 3); int ctrly1 = y1; int ctrlx2 = (x1 + x2) / 4 * Util.rand(1, 3); int ctrly2 = y2; c.setCurve(x1, y1, ctrlx2, ctrly2, ctrlx1, ctrly1, x2, y2); localGraphics2D2.draw(c); // localGraphics2D2.drawLine(randomX1(), randomY1(), randomX2(), randomY2()); } localGraphics2D.dispose(); } catch (Exception e) { log.error(e.getMessage(), e); return null; } return localBufferedImage; }
From source file:RenderQualityTest.java
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHints(hints);//from w ww .j ava 2s . co m g2.draw(new Ellipse2D.Double(10, 10, 60, 50)); g2.setFont(new Font("Serif", Font.ITALIC, 40)); g2.drawString("Hello", 75, 50); g2.draw(new Rectangle2D.Double(200, 10, 40, 40)); g2.draw(new Line2D.Double(201, 11, 239, 49)); g2.drawImage(image, 250, 10, 100, 100, null); }
From source file:ResizeRectangle.java
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; for (int i = 0; i < points.length; i++) { g2.fill(points[i]);/*w w w . j a va2 s .c o m*/ } s.setRect(points[0].getCenterX(), points[0].getCenterY(), Math.abs(points[1].getCenterX() - points[0].getCenterX()), Math.abs(points[1].getCenterY() - points[0].getCenterY())); g2.draw(s); }
From source file:AnimationTester.java
public synchronized void paintComponent(Graphics g) { if (values == null) return;// w w w . j a v a 2 s. c o m Graphics2D g2 = (Graphics2D) g; int width = getWidth() / values.length; for (int i = 0; i < values.length; i++) { Double v = values[i]; Rectangle2D bar = new Rectangle2D.Double(width * i, 0, width, v); if (v == marked1 || v == marked2) g2.fill(bar); else g2.draw(bar); } }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; int w = getSize().width - 1; int h = getSize().height - 1; for (int i = 0; i < 12; i++) { double angle = Math.PI / 2 - i * Math.PI / 6; double x = Math.cos(angle); double y = Math.sin(angle); Line2D l = new Line2D.Double(100 + 55.0 * x, 100 - 55.0 * y, 100 + 65.0 * x, 100 - 65.0 * y); g2.draw(l); }// www . ja va 2 s.c o m }
From source file:Shear.java
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; AffineTransform tx1 = new AffineTransform(); tx1.translate(50, 90);/*from w w w . j a va2 s . c o m*/ g2d.setTransform(tx1); g2d.setColor(Color.green); g2d.drawRect(0, 0, 80, 50); AffineTransform tx2 = new AffineTransform(); tx2.translate(50, 90); tx2.shear(0, 1); g2d.setTransform(tx2); g2d.setColor(Color.blue); g2d.draw(new Rectangle(0, 0, 80, 50)); }
From source file:OptionDialogTest.java
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; Rectangle2D rect = new Rectangle2D.Double(0, 0, getWidth() - 1, getHeight() - 1); g2.setPaint(Color.YELLOW);/*from w w w . j a va 2 s. c o m*/ g2.fill(rect); g2.setPaint(Color.BLUE); g2.draw(rect); }