JFrame frame = new JFrame ( "Bevel Arrows" ); frame.add ( new JPanel() { public void paintComponent ( Graphics g ) { arrows.draw ( ( Graphics2D ) g, getWidth(), getHeight() ); frame.setSize ( 800, 400 ); frame.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ); frame.setVisible ( true ); g.setRenderingHint ( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); g.setColor ( Color.WHITE ); g.fillRect ( 0, 0, width, height ); g.setColor ( Color.ORANGE ); g.fillRect ( 350, 20, 20, 280 ); g.setColor ( Color.YELLOW ); g.draw ( new Line2D.Float ( 50.0f, 0.0f, veeX, 0.0f ) ); g.setColor ( Color.RED ); g.draw ( new Line2D.Float ( 50.0f, 0.0f, veeX - stroke.getLineWidth() * 0.25f, 0.0f ) ); g.setColor ( Color.RED ); g.draw ( new Line2D.Float ( 50.0f, 0.0f, veeX - arrowLength * 0.5f, 0.0f ) );
this.currentPath.reset(); return; PathIterator pi = path.getPathIterator(this.getPageTransform()); float[] c = new float[6]; int currentSegment; path.reset(); return; pi.currentSegment(first); end_pos = new Point2D.Float(c[0], c[1]); line = pc.compare(start_pos, end_pos) == -1 ? new Line2D.Float(start_pos, end_pos) : new Line2D.Float(end_pos, start_pos); if (line.intersects(this.currentClippingPath())) { Ruling r = new Ruling(line.getP1(), line.getP2()).intersect(this.currentClippingPath()); break; line = pc.compare(end_pos, last_move) == -1 ? new Line2D.Float(end_pos, last_move) : new Line2D.Float(last_move, end_pos); if (line.intersects(this.currentClippingPath())) { Ruling r = new Ruling(line.getP1(), line.getP2()).intersect(this.currentClippingPath());
JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new TestPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); customBalloonTip.setVisible(false); lines.add(new Line2D.Float(0, 0, 300, 300)); lines.add(new Line2D.Float(300, 0, 0, 300)); protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(Color.RED); for (Line2D line : lines) { g2d.draw(line); g2d.fill(ellipse); g2d.dispose();
GdiObject gdiObj; int gdiIndex; g.setPaintMode(); g2d.setStroke(solid); float h = vpH; g2d.setColor( Color.black ); float endY = scaleY * ( vpY + yOffset + mr.elementAt( 1 ) ); Line2D.Float line = new Line2D.Float(startX, startY, endX, endY); paintWithPen(penObject, line, g2d); startX = endX; GeneralPath gp = new GeneralPath( GeneralPath.WIND_NON_ZERO ); TextLayout layout = new TextLayout( sr, g2d.getFont(), frc ); GeneralPath gp = new GeneralPath( GeneralPath.WIND_NON_ZERO ); TextLayout layout = new TextLayout( sr, g2d.getFont(), frc ); float _startY = scaleY * ( vpY + yOffset + mr.elementAt( 2 ) ); GeneralPath gp = new GeneralPath( GeneralPath.WIND_NON_ZERO ); gp.moveTo( _startX, _startY );
try { background = ImageIO.read(getClass().getResource("/TreasureMap.png")); foreground = new BufferedImage(background.getWidth(), background.getHeight(), BufferedImage.TYPE_INT_ARGB); } catch (Exception e) { e.printStackTrace(); Point to = new Point(endPoint); to.translate(-offset.x, -offset.y); g2d.setColor(Color.RED); g2d.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); g2d.draw(new Line2D.Float(from, to)); g2d.dispose(); startPoint = endPoint; repaint(); super.paintComponent(g); if (background != null) { Graphics2D g2d = (Graphics2D) g.create(); Point offset = getOffset(); g2d.drawImage(background, offset.x, offset.y, this); g2d.setComposite(AlphaComposite.SrcOver.derive(0.5f)); g2d.drawImage(foreground, offset.x, offset.y, this); g2d.dispose();
setLayout(new BorderLayout()); bgOps.add(eraser); operations.add(pencil, gbc); protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); int x = (cursorPoint.x - (drawCursor.getBounds().width) / 2); int y = (cursorPoint.y - (drawCursor.getBounds().height) / 2); g2d.translate(x, y); g2d.draw(drawCursor); Graphics2D g2d = image.createGraphics(); switch (op) { g2d.draw(new Line2D.Float(fromPoint, toPoint)); break; g2d.setStroke(new BasicStroke(eraseSize)); g2d.draw(new Line2D.Float(fromPoint, toPoint)); break;
window.add(content); window.pack(); window.setVisible(true); BufferedImage tileImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); Graphics2D tile = tileImage.createGraphics(); int edgeLength = tileImage.getWidth() / 2; Polygon hexagon = new Polygon(); Point[] vertex = new Point[6]; tile.setColor(Color.black); tile.fillPolygon(hexagon); tile.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN)); tile.setStroke(new BasicStroke(10)); Arc2D.Double arc = new Arc2D.Double(); arc.setArcByCenter(vertex[vertexIndex].x, vertex[vertexIndex].y, edgeLength / 2, 0, 360, Arc2D.OPEN); tile.setColor(tileColors[i]); tile.draw(arc); vertexIndex++; } else if (tilePaths[i] == "curve") { Point midPoint2 = new Point((vertex[vertexIndex + 3].x + vertex[vertexIndex + 4].x) / 2, (vertex[vertexIndex + 3].y + vertex[vertexIndex + 4].y) / 2); tile.setColor(tileColors[i]); tile.draw(new Line2D.Float(midPoint1.x, midPoint1.y, midPoint2.x, midPoint2.y)); vertexIndex++;
GeneralPath path = new GeneralPath(); Point2D p1 = null; Point2D p2 = null; Line2D line = new Line2D.Float(); Point2D p = new Point2D.Float(); int foundPointX = -1; for(int i=image.getWidth()-1; i>=0; i--) { for(int j=0; j<image.getHeight(); j++) { if((image.getRGB(i,j) & 0xff000000) != 0) { if(p2 == null) { p1 = new Point2D.Float(foundPointX, image.getHeight()-1); path.moveTo(p1.getX(), p1.getY()); p2 = new Point2D.Float(); p2.setLocation(p); } else { path.lineTo(p.getX(), p.getY()); if(foundPointX >= 0) { path.lineTo(foundPointX, image.getHeight()-1);
BufferedImage BoardImg = new BufferedImage(makeSize, makeSize, BufferedImage.TYPE_INT_RGB); Graphics2D BGraphs = BoardImg.createGraphics(); BGraphs.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); H = BoardBackground.getHeight(); W = BoardBackground.getWidth(); BGraphs.setPaint(new TexturePaint(BoardBackground, new Rectangle(0, 0, W, H))); BGraphs.fillRect(0, 0, makeSize, makeSize); Line2D.Float aLine = new Line2D.Float(); y1 = lineSp; y2 = makeSize - lineSp; aLine.setLine(x1, y1, x2, y2); BGraphs.setColor(Color.black); BGraphs.draw(aLine); x1 = lineSp; x2 = makeSize - lineSp; aLine.setLine(x1, y1, x2, y2); BGraphs.setColor(Color.black); BGraphs.draw(aLine);
/** {@inheritDoc} */ public void paint(final float x, final float y, final Graphics2D g) { g.setColor(this.col); final Stroke oldStroke = g.getStroke(); if (this.dash) { final float dashWidth = 3.0f * this.width; g.setStroke(new BasicStroke(this.width, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, this.width, new float[] { dashWidth, dashWidth, }, 0)); } else { g.setStroke(new BasicStroke(this.width)); } g.draw(new Line2D.Float(x + this.x1, y + this.y1, x + this.x2, y + this.y2)); g.setStroke(oldStroke); } }
bounds.add(pTo.x, pTo.y); BufferedImage img = new BufferedImage((int) (bounds.width - bounds.x + 50), (int) (bounds.height - bounds.y + 50), BufferedImage.TYPE_4BYTE_ABGR_PRE); Graphics2D g = img.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.translate(25.0f - bounds.getX(), 25.0f - bounds.getY()); g.setStroke(new BasicStroke(1.0f)); g.setColor(Color.DARK_GRAY); g.drawLine(-1000, 0, 1000, 0); g.drawLine(0, -1000, 0, 1000); g.setColor(Color.RED); for (int i = 0; i < points.size(); ++i) { if (i > 0) { Line2D.Float f = new Line2D.Float(points.get(i - 1).x, points.get(i - 1).y, points.get(i).x, points.get(i).y); System.out.println("Dist : " + f.getP1().distance(f.getP2()));
int h = height; Graphics2D g2d = (Graphics2D) g.create(); float strokeWidth = SubstanceSizeUtils .getBorderStrokeWidth(SubstanceSizeUtils .getComponentFontSize(c)); g2d.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND)); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.translate(x, y); g2d.setColor(getShadowColor(c)); g2d.setColor(getHighlightColor(c)); g2d.draw(new Line2D.Float(strokeWidth, h - 3 * strokeWidth, strokeWidth, strokeWidth)); g2d.draw(new Line2D.Float(delta + strokeWidth, delta + strokeWidth, w - delta - 3 * strokeWidth, delta + strokeWidth)); g2d.draw(new Line2D.Float(delta, h - delta - strokeWidth, w - delta - strokeWidth, h - delta - strokeWidth)); g2d.draw(new Line2D.Float(w - delta - strokeWidth, h - delta - strokeWidth, w - delta - strokeWidth, delta));
import java.awt.*; import java.awt.geom.Line2D; import javax.swing.*; public class FrameTest { public static void main(String[] args) { JFrame jf = new JFrame("Demo"); Container cp = jf.getContentPane(); cp.add(new JComponent() { public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setStroke(new BasicStroke(10)); g2.draw(new Line2D.Float(30, 20, 80, 90)); } }); jf.setSize(300, 200); jf.setVisible(true); } }
Point2D p1 = null; Point2D p2 = null; Line2D line = new Line2D.Float(); for (int i = 0; i < image.getHeight(); i += sample) { boolean aPointExistsOnThisLine = false; for (int j = 0; j < image.getWidth(); j += sample) { if ((image.getRGB(j, i) & 0xff000000) != 0) { Point2D p = new Point2D.Float(j, i); aPointExistsOnThisLine = true; if (path.getCurrentPoint() != null) { path.moveTo(j, i); firstx = j; p1 = p;
setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(new BorderLayout()); add(new DrawPane(), BorderLayout.CENTER); pack(); drawing.setVisible(true); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.translate(getWidth() / 2, getHeight() / 2); g2.scale(getWidth() / 2, -getHeight() / 2); g2.setColor(Color.red); g2.setStroke(new BasicStroke(0.001f)); g2.draw(new Line2D.Float(-1f, 0f, 1.0f, 0f)); g2.draw(new Line2D.Float(0, -1.0f, 0.0f, 1.0f)); g2.draw(new Line2D.Float(0f, 0f, 0.25f, 0.25f));
JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new DrawLine()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setStroke(new BasicStroke(1)); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.50f)); return new Line2D.Float(x1, y1, x2, y2);
g.clearRect(0, 0, getWidth(), getHeight()); Graphics2D g2 = (Graphics2D) g; for(int i =0; i < 18; i++) { if(Grid[i][j] != 0){ if( i < 1 || j < 1 || i > 26 || j > 17) { g2.setColor(Color.RED); g2.fillRect(j*32, i*32, 32, 32); }else { g2.setColor(Color.BLUE); Line2D lin = new Line2D.Float(i*32, 0, i*32, getHeight()); g2.draw(lin); Line2D lin = new Line2D.Float(0, i*32, getWidth(), i*32); g2.draw(lin); JFrame frame=new JFrame(); Creator s=new Creator(); frame.setSize(864, 544); frame.add(s); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) {
setLayout(new BorderLayout()); setDefaultCloseOperation(EXIT_ON_CLOSE); centerPoint = new Point2D.Float(center, center); diameter = minDimen - MARGIN * 2; final Rectangle2D.Float bounds = new Rectangle2D.Float(center - diameter/2, slice.append(new Line2D.Float(center, center, arcP1.x, arcP1.y), true); slice.append(new Line2D.Float(arcP2.x, arcP2.y, center, center), true); g2d.setColor(CIRCLE_COLOR); g2d.setStroke(new BasicStroke(minDimen/ 50)); for(Shape s : slices){ g2d.draw(s); g2d.setColor(NUMB_COLOR); g2d.setFont(new Font("Arial", Font.PLAIN, 25)); for(int i = 0; i < divisions; i++){ g2d.drawString(j + "", (int)loc.x, (int)loc.y); return new Point2D.Float((float)(Math.cos(rad) * radius + center.x), (float)(- Math.sin(rad) * radius + center.y));
this.setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("C:/Users/TPC/workspace/ProjectMoney/Resources/backgroundForApp.png"))))); } catch (IOException e) { this.setLayout(new BorderLayout()); thePanel.add(button1); thePanel.add(but1); super.paintComponent(g); Graphics2D graph2 = (Graphics2D) g; graph2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Shape drawLine = new Line2D.Float(20, 90, 55, 250); graph2.setPaint(Color.BLACK); graph2.draw(drawLine); graph2.draw(drawArc2D); graph2.draw(drawEllipse); graph2.setColor(Color.GREEN); graph2.fill(drawRoundRec);