tailieunhanh - Java All-in-One Desk Reference For Dummies phần 10
Elip là một hình tròn phù hợp trong một khu vực hình chữ nhật. Vì vậy, các nhà xây dựng cho lớp là tương tự như để Rectangle2D. Float xây dựng. Dưới đây là một ví dụ mà tạo ra một hình elip, hình chữ nhật bounding là một hình vuông: | 774 Creating Shapes Shape round2 new 210 10 60 80 50 75 Here the arc s width is 50 and its height is 75. Creating ellipses An ellipse is a round shape that fits within a rectangular area. Thus the constructor for the class is similar to the Rectangle2D. Float constructor. Here s an example that creates an ellipse where the bounding rectangle is a square Shape ellipse1 new 10 110 80 80 Note that if the bounding rectangle happens to be a square the ellipse is a circle. This one is the first shape in the second row in Figure 2-2. Here s the code for the second ellipse in the figure Shape ellipse2 new 110 110 80 40 Here the ellipse fits inside a rectangle whose width is 80 and height is 40. Thus the ellipse is short and wide kind of like me. If I ate a little less and exercised a little more maybe I d look more like the third ellipse created with this code Shape ellipse3 new 210 110 40 80 Creating arcs Another useful type of shape is an arc which is a segment of an ellipse. To create an arc you supply the bounding rectangle that contains the ellipse. Here are the parameters you need to specify The starting angle for the arc in degrees 0 is due east or 3 o clock as they say in the movies. The extent which is an angle that represents how much of the ellipse the arc spans. This too is specified in degrees. The important thing to know is that the arc travels counterclockwise from the starting point. So if you specify 0 as the starting point and 90 as the extent the arc travels from 3 o clock to 12 o clock high. One of three arc types indicates that you want to draw just the arc itself. means you want to draw the arc and then connect the ends with a straight line to create a closed shape. means you want to connect the ends with straight lines back to the center of the ellipse to create a shape that looks like a piece of pie. Creating Shapes 115 Here s an .
đang nạp các trang xem trước