Illustrations Class.


109 views
Uploaded on:
Category: Fashion / Beauty
Description
Illustrations Class Design class is a class in java.awt bundle. contains techniques for making line drawings, rectangles, ovals, curves, polygons. control shading and text styles An Illustrations object speaks to a specific drawing surface.
Transcripts
Slide 1

Design Class Graphics class is a class in java.awt bundle. contains systems for making line drawings, rectangles, ovals, curves, polygons. control shading and textual styles A Graphics item speaks to a specific drawing surface. We can\'t straightforwardly call the constructor of Graphics class to make a Graphics object. A Graphics article is made in a roundabout way. For instance, every applet is connected with a Graphics article, and we can get to this Graphics object. Any routines called with the Graphics article connected with an applet will influence that applet. An object of Graphics class speaks to a specific drawing surface, and Graphics class contains strategies for drawing shapes on that surface. COP 3330 Object Oriented Programming

Slide 2

An Applet’s Graphics Context An applet has an illustrations setting which is naturally gone to the paint system when it is conjured. import java.applet.Applet; import java.awt.*; open class AnApplet expands Applet { public void paint(Graphics g) { … … //utilizing this Graphics object g, … … //we can draw shapes on this applet. } COP 3330 Object Oriented Programming

Slide 3

Coordinate System 0,0 width drawing surface of an applet height width-1,height-1 Each point on the direction framework speaks to a solitary pixel. Anything drawn outside of this range won\'t be obvious. COP 3330 Object Oriented Programming

Slide 4

An Example import java.applet.Applet; import java.awt.*; open class AnApplet broadens Applet { public void paint(Graphics g) { g.drawRect( 10,10 , 100,50 ); upper left corner width and stature of the rectangle g.drawLine( 10,10 , 110,60 ); source coordinate destination coordinate g.drawString(“This a rectangle”, 10,150 ); } } upper left corner COP 3330 Object Oriented Programming

Slide 5

Drawing Shapes Graphics class straightforwardly underpins the drawing of: lines ovals (circles are exceptional types of ovals) rectangles circular segments polygons – triangles, hexagons, … polylines – a progression of line sections Most shapes (with the exception of polylines) can be drawn filled or unfilled. We can see alternate representation objects under an unfilled item The frontal area shading is utilized to fill shapes. Alternate representation objects under a filled item can\'t be seen. Thickness can\'t be indicated (dependably 1 pixel). Thicker lines can be drawn by various lines. g.drawLine(10,10,200,10); g.drawLine(10,11,200,11); COP 3330 Object Oriented Programming

Slide 6

Rectangles drawRect( xsrc,ysrc ,width,height) fillRect( xsrc,ysrc ,width,height) upper left corner COP 3330 Object Oriented Programming

Slide 7

Ovals A jumping rectangle is utilized to characterize the position of an oval. drawRect( xsrc,ysrc ,width,height) fillRect( xsrc,ysrc ,width,height) upper left corner of the jumping rectangle bouncing rectangle is not checked whether width and stature are equivalent  a circle COP 3330 Object Oriented Programming

Slide 8

Some Other Rectangle Related Methods clearRect(x,y,width,height) draws a (filled) rectangle in the present foundation shading. cleans that rectangle region. drawRoundRect(x,y,width,height,arcwidth,archeight) fillRoundRect(x,y,width,height,arcwidth,archeight) draws a rectangle with adjusted corners. archeight arcwidth COP 3330 Object Oriented Programming

Slide 9

Arcs A circular segment is a portion of an oval. The fragment starts at a particular point, and reaches out for a separation determined by the curve edge. drawArc(x,y,width,height,startangle,arcangle) fillArc(x,y,width,height,startangle,arcangle) - 270,90 counter-clockwise (positive) 180,- 180 0,360,- 360 clockwise (negative) 270,- 90 COP 3330 Object Oriented Programming

Slide 10

Arcs (cont.) startangle is in degrees – a quality somewhere around 0 and 360, or somewhere around 0 and - 360 arcangle positive (counter clockwise) negative (clockwise) drawArc(20,20,50,50,90,90); drawArc(20,20,50,50,- 270,90); drawArc(20,20,50,50,180,- 90); drawArc(20,20,50,50,- 180,- 90); same bend is drawn by every one of them fillArc(20,20,50,50,90,90); COP 3330 Object Oriented Programming

Slide 11

Polygons A polygon is a multi-sided figure A polygon is characterized utilizing a progression of <x,y> focuses which shows the end purposes of the sides of that polygon. Polygons are shut. It frames a line section from the last indicate the first. End focuses can be determined by: two whole number clusters or an object of Polygon class demonstrating the end focuses. drawPolygon(int[] xpoints, int[] ypoints, int numofpoints) fillPolygon(int[] xpoints, int[] ypoints, int numofpoints) drawPolygon(Polygon poly) fillPolygon(Polygon poly) COP 3330 Object Oriented Programming

Slide 12

Polygons (cont.) int[] xs = {50,100,150,100}; 100,50 int[] ys = {100,50,100,150}; drawPolygon(xs,ys,4); 50,100 150,100 Polygon p = new Polygon(); p.addPoint(50,100); p.addPoint(100,50); 100,150 p.addPoint(150,100); p.addPoint(100,150); drawPolygon(p); COP 3330 Object Oriented Programming

Slide 13

Polyline A polyline is a like a polygon with the exception of it is not shut. There is no line portion from the last indicate the first. Polylines can\'t be filled. int[] xs = {50,100,150,100}; int[] ys = {100,50,100,150}; drawPolyline(xs,ys,4); COP 3330 Object Oriented Programming

Slide 14

Color Class Color class is utilized to characterize and deal with the shading in which shapes are drawn. We can control the shapes\' shade we draw. A shading is characterized by a R G B esteem (red,green,blue) that indicates the relative commitment of these three essential hues red, green, blue (qualities between 0 to 255). Shading class contains a few last static Color items to characterize fundamental hues. blue Color.blue 0,0,255 green Color.green 0,255,0 red Color.red 255,0,0 black Color.black 0,0,0 white Color.white 255,255,255 yellow Color.yellow 255,255,0 gray Color.gray 128,128,128 COP 3330 Object Oriented Programming

Slide 15

Color Class (cont.) notwithstanding fundamental hues characterized in Color class, we can characterize our own particular setting so as to shade these three qualities (256 3 – right around 16 million distinct hues). Shading mycolor = new Color(100,100,100); We can change frontal area (shades of shapes) and foundation (general shade of the applet) hues. In paint system, setBackground(Color.white) changes the foundation shading to white. setBackground is a system for Applet class. g.setColor(Color.red) changes the frontal area shading to red. setColor is a strategy for Graphics class. COP 3330 Object Oriented Programming

Slide 16

Color Class - Example open void paint (Graphics g) { setBackground(Color.white);  foundation is white g.setColor(Color.yellow);  shade of pen is yellow g.drawString(“This is yellow”,20,20);  This is yellow g.setColor(Color.blue);  shade of pen is blue g.drawLine(20,50,200,50);  g.setColor(Color.green);  shade of pen is green g.drawRect(20,100,200,100);  } COP 3330 Object Oriented Programming

Slide 17

Fonts A text style characterizes the look of every character when it is printed or drawn. Textual style class gives techniques to indicating text styles in a Java program. There is a particular arrangement of text styles in every framework. We can utilize one of the textual styles from this rundown. Utilizing the constructor of Font class we can make a Font object. At that point we can set the present text style to this Font item utilizing setFont system as a part of Graphics class. new Font( fontname , style , size ) “TimesRoman” Font.PLAIN 12 14 16 18 20 … “Helvetica” Font.BOLD Font.ITALIC COP 3330 Object Oriented Programming

Slide 18

Fonts - Example import java.applet.Applet; import java.awt.*; open class FontTest amplifies Applet { open void paint(Graphics g) { g.setFont(new Font("TimesRoman",Font.PLAIN,16)); g.drawString("Font is TimesRoman-PLAIN-16",10,30);  Font is TimesRoman-PLAIN-16 g.setFont(new Font("TimesRoman",Font.ITALIC,20)); g.drawString("Font is TimesRoman-ITALIC-20",10,60);  Font is TimesRoman-ITALIC-20 g.setFont(new Font(“Courier",Font.BOLD+Font.ITALIC,20)); g.drawString("Font is Courier-BOLD-ITALIC-20",10,90);  Font is Courier-BOLD-ITALIC-20 g.setFont(new Font("Courier",Font.PLAIN,16)); g.drawString("Font is Courier-PLAIN-16",10,120);  Font is Courier-PLAIN-16 } COP 3330 Object Oriented Programming

Slide 19

GraphicsTest import java.applet.Applet; import java.awt.*; open class GraphicsTest develops Applet { open void paint(Graphics g) { resize(600,400); g.drawRect(10,10,200,100); g.drawLine(10,10,210,110); g.drawLine(10,110,210,10); g.drawString("This is a rectangle",10,130); g.setColor(Color.red); g.drawString("A red string",10,150); g.setColor(Color.blue); g.drawString("A blue string",10,170); g.fillRect(300,10,100,50); g.drawOval(300,100,100,50); g.fillOval(300,200,100,50); g.drawOval(300,300,40,40); g.fillOval(350,300,40,40); } COP 3330 Object Oriented Programming .:tsl

Recommended
View more...