Java Three-Dimensional Graphics

Source: Internet
Author: User

The support for Java geometric images is not very good. I tried the 2D and 3D images provided after Java, and I did not study them carefully, I don't know if I can draw such a geometric image, so I checked the API and found this method drawpolygon (INT [] xpoints, int [] ypoints, int npoints ), this method can draw any number of rows, so I used this method in combination with other drawing methods to write a three-dimensional rectangular demo.

API explanation of this method:

Public abstract void drawpolygon (INT [] xpoints, int [] ypoints, int npoints)

Draw XAnd YThe closed polygon defined by the coordinate array. Each pair ( X, Y) Coordinates define a point.
This method draws a polygon defined by npoint line segments.

When the npoint-1 line segment is 1 ≤ I ≤ npoints

(Xpoints [I-1], ypoints [I-1]) to (xpoints [I], ypoints [I]) line segments.

If the last vertex and the first vertex are different, the graph will automatically close by drawing a line segment between these two points.

 

Parameters:

 

Xpoints

-

X

Coordinate array.

 

Ypoints

-

Y

Coordinate array.

Npoints

-Total number of points.

Below is my demo program:

Import Java. AWT. color; </P> <p> Import Java. AWT. graphics; </P> <p>/** <br/> * @ author lazy_p <br/> * @ date 2010-3-18 <br/> * <br/> * stereo graphics demo <br/> */<br/> public class threedrec extends Java. applet. applet {</P> <p> Private Static final long serialversionuid =-2427989261965982016l; </P> <p> Public void Init () {<br/> resize (200,200 ); <br/>}// original graph area </P> <p> Public void paint (Graphics g) {</P> <p> G. setcolor (color. red); <br/> G. drawpolygon (New int [] {30, 90,100, 40}, <br/> New int [] {30, 30, 10, 10}, 4 ); // draw a rectangle <br/> G. setcolor (new color (1 ). gray); </P> <p> G. fillpolygon (New int [] {30, 90,100, 40}, <br/> New int [] {30, 30, 10, 10}, 4 ); // fill in a rectangle <br/> G. setcolor (color. red); <br/> G. drawrect (30, 30, 60,100); <br/> G. setcolor (new color (1 ). cyan); <br/> G. fillrect (30, 30, 60,100); <br/> G. setcolor (color. red); <br/> G. drawpolygon (New int [] {90,100,100, 90}, new int [] {30, 10,110, <br/> 130}, 4); <br/> G. setcolor (new color (1 ). green); <br/> G. fillpolygon (New int [] {90,100,100, 90}, new int [] {30, 10,110, <br/> 130}, 4 ); </P> <p >}< br/>

Effect:

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.