Java 2D graphics Study Notes (1)

Source: Internet
Author: User
Draw simple images
 
// draw Line2D.Doubleg2.draw(new Line2D.Double(x, y+rectHeight-1,                          x + rectWidth, y));
// draw Rectangle2D.Doubleg2.setStroke(stroke);g2.draw(new Rectangle2D.Double(x, y,                               rectWidth,                               rectHeight));
// draw RoundRectangle2D.Doubleg2.setStroke(dashed);g2.draw(new RoundRectangle2D.Double(x, y,                                   rectWidth,                                   rectHeight,                                   10, 10));
// draw Arc2D.Doubleg2.setStroke(wideStroke);g2.draw(new Arc2D.Double(x, y,                         rectWidth,                         rectHeight,                         90, 135,                         Arc2D.OPEN));
// draw Ellipse2D.Doubleg2.setStroke(stroke);g2.draw(new Ellipse2D.Double(x, y,                             rectWidth,                             rectHeight));
// draw GeneralPath (polygon)int x1Points[] = {x, x+rectWidth,                  x, x+rectWidth};int y1Points[] = {y, y+rectHeight,                  y+rectHeight, y};GeneralPath polygon = new GeneralPath(GeneralPath.WIND_EVEN_ODD,     x1Points.length);polygon.moveTo(x1Points[0], y1Points[0]);for (int index = 1;     index < x1Points.length;     index++) {        polygon.lineTo(x1Points[index],                       y1Points[index]);};polygon.closePath();g2.draw(polygon);
// draw GeneralPath (polyline)int x2Points[] = {x, x+rectWidth, x,                  x+rectWidth};int y2Points[] = {y, y+rectHeight,                  y+rectHeight, y};GeneralPath polyline = new         GeneralPath(GeneralPath.WIND_EVEN_ODD,                x2Points.length);polyline.moveTo (x2Points[0], y2Points[0]);for (int index = 1;     index < x2Points.length;     index++) {  polyline.lineTo(x2Points[index],         y2Points[index]);};g2.draw(polyline);
// fill Rectangle2D.Double (red)g2.setPaint(red);g2.fill(new Rectangle2D.Double(x, y,        rectWidth, rectHeight));
// fill RoundRectangle2D.Doubleg2.setPaint(redtowhite);g2.fill(new RoundRectangle2D.Double(x, y,                                   rectWidth,                                   rectHeight,                                   10, 10));
// fill Arc2Dg2.setPaint(red);g2.fill(new Arc2D.Double(x, y, rectWidth,                         rectHeight, 90,                         135, Arc2D.OPEN));
// fill Ellipse2D.Doubleg2.setPaint(redtowhite);g2.fill (new Ellipse2D.Double(x, y,                              rectWidth,                              rectHeight));
// Fill and stroke generalpathint x3points [] = {x, x + rectwidth, x, x + rectwidth}; int y3points [] = {Y, Y + rectheight, Y + rectheight, y}; generalpath filledpolygon = new generalpath (generalpath. wind_even_odd, x3points. length); filledpolygon. moveTo (x3points [0], y3points [0]); For (INT Index = 1; index <x3points. length; index ++) {filledpolygon. lineto (x3points [Index], y3points [Index]) ;}; filledpolygon. closepath (); g2.setpaint (red); g2.fill (filledpolygon );




Stroke
To put it simply, it is used to define the line width/line type.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.