1 / 13

# Representation Programming.

89 views
Category: Food / Beverages
Description
Illustrations Programming In this class we will cover: Drawing lines, rectangles, and circles Replicating a territory Drawing a picture Drawing Lines, Rectangles and Ovals Java2D oraganizes geometric shapes in OO style. There are classes to speak to lines, rectangles and ovals. Line2D
Transcripts
Slide 1

Design Programming

Slide 2

In this class we will cover: Drawing lines, rectangles, and ovals Copying a territory Drawing a picture

Slide 3

Drawing Lines, Rectangles and Ellipses Java2D oraganizes geometric shapes in OO style. There are classes to speak to lines, rectangles and ovals. Line2D Rectangle2D Ellipse2D These all execute the Shape interface

Slide 4

Drawing Shapes To draw a shape, you first make an object of a class that actualizes the Shape interface and after that call the draw technique for the Graphics2D class. Rectangle 2D rect = . . .; g2.draw(rect); There are two adaptations of every Shape class one with buoy directions (saves memory) one with twofold organizes (simpler to utilize) Example: Rectangle2D rect = new Rectangle2D.Double(10.0, 25.0, 22.5, 20.0);

Slide 5

Drawing Rectangles are easy to build Requires four contentions x-and y-directions of the upper-left corner the width and the stature The Rectangle2D class has more than 20 valuable strategies including: get Width getHeight getCenterX getCenterY

Slide 6

Drawing Rectangles Sometimes you donât have the upper left corner promptly accessible. It is conceivable to have two askew corners of a rectangle that are not the upper left corner and the base right corner. To make a rectangle for this situation utilize the setFrameFromDiagonal technique. Rectangle2D rect = new Rectangle2D.Double(); rect.setFrameFromDiagonal(px, py, qx, qy); If you have a Point2D object, you can likewise make a rectangle by calling Rectangle2D rect = new Rectangle2D.Double(p1, p2);

Slide 7

Drawing Ellipses The class Ellipse2D is acquired from the same Rectangle class that Rectangle2D is. in view of the jumping box encompassing the circle So, making an Ellipse2D article is fundamentally the same to making a Rectangle2D object. Ellipse2D e = new Ellipse2D.Double(px, py, qx, qy) where px, py are the x-and y-directions of the upper left corner and qx, qy are the x-and y-directions of the base right corner of the bouncing box of the oval

Slide 8

Drawing Lines To develop a line, basic utilize the Line2D class. It as well, obliges 4 contentions (the x and y directions of the begin and end positions) These directions can be 2 Point2D items or 2 sets of numbers. Line2D line = new Line2D.Double(start, end) or Line2D line = new Line2D.Double(px, py, qx, qy)

Slide 9

Filling Shapes You can fill the inside of shut shape objects with a shading. Basically call the fill rather than draw technique on the Graphics object. Rectangle2D rect = new Rectangle2D.Double(x, y, x2, y2); g2.setPaint(Color.red); g2.fill(rect);

Slide 10

Images You can show pictures on the Graphics object. You can utilize pictures put away locally or somewhere on the Internet. In the event that a picture is put away locally call: String filename = ââ¦â; Image picture = ImageIO.read(new File(filename)); If a picture is on the Internet, utilize the url: String filename = ââ¦â; Image picture = ImageIO.read(new URL(url); To draw the picture: g.drawImage(image, x, y, invalid)

Slide 11

Copying an Area copyArea() system - Use to duplicate a range Requires 6 parameters x-direction and y-direction of the upper-left corner of the zone to be replicated Width and stature of the region to be replicated The level and vertical dislodging of the duplicate\'s destination

Slide 12

More on Graphics We have quite recently started to touch on the different illustrations shapes accessible. You can likewise draw: circular segments polygons three-dimensional shpes Java 2D additionally gives you a chance to make higher-quality two-dimensional design, pictures, and content utilizing: fill examples, for example, angles strokes that characterize the width and style of a drawing stroke hostile to associating, an illustrations procedure for delivering smoother on-screen representation For more data see: http://java.sun.com/docs/books/instructional exercise/2d/show/strokeandfill.html

Slide 13

Example So, letâs set up the greater part of this together in a case: See: http://www2.bc.edu/~bernier/MC697/LectureNotes/DrawShapesTest.java .:t

Recommended
View more...