Java Illustrations.


75 views
Uploaded on:
Description
Java Representation. Joe Komar. Design Class. Characterized in java.awt bundle of the Java Programming interface Line drawing, rectangles, ovals, curves, and polygons As of now seen drawString, drawLine, drawOval, drawRect These and different techniques are a piece of the Representation object
Transcripts
Slide 1

Java Graphics Joe Komar Associates

Slide 2

Graphics Class Defined in java.awt bundle of the Java API Line drawing, rectangles, ovals, curves, and polygons Already seen drawString, drawLine, drawOval, drawRect These and different routines are a Graphics\' piece article Objects of the Graphics class speak to drawing surfaces Contains techniques for drawing on that surface Device ward Use either getGraphics strategy or utilization as parameter ( Graphics page ) to utilize it (no instantiation) Komar Associates

Slide 3

Graphics Coordinate System 0,0 is the upper left corner Each direction point speaks to one pixel All direction qualities are certain x 0,0 X y x,y Y Komar Associates

Slide 4

Coordinates Applet import java.awt.*; import java.applet.*; open class Coordinates augments Applet { open void paint (Graphics page){ setSize (300,200); page.drawRect (0, 0, 299, 199); page.drawLine (50, 50, 250, 100); page.drawString ("<50, 50>", 25, 45); page.drawString ("<250, 100>", 225, 115); }//technique paint }//class Coordinates Komar Associates

Slide 5

Output of Coordinates Applet Komar Associates

Slide 6

Colors Color class is a piece of java.awt Colors are characterized by a blend of Red, Blue, and Green RGB characterized by three numbers going from (0,0,0) for dark to (255,255,255) for white more than 16 million hues accessible numerous frameworks can\'t recognize among such a variety of hues Predefined hues ( last static Color items) e.g., Color.blue, Color.green, Color.cyan see p 256 for more Komar Associates

Slide 7

Defining Colors Color (int red, int green, int blue) Integer qualities somewhere around 0 and 255 Color (buoy red, buoy green, buoy blue) Decimal qualities somewhere around 0.0 and 1.0 Color (int rgb) bits 0-7 speak to blue, 8-15 speak to green, 16-23 speak to red Komar Associates

Slide 8

Defining Colors Color cocoa = new Color (107, 69, 38); brown.getBlue() returns 38 ( getRed and getGreen ) brown.brighter() gives back a touch brighter Color brown.darker() gives back a touch darker Color Komar Associates

Slide 9

Nature Applet import java.awt.*; import java.applet.*; open class Nature develops Applet { open void paint (Graphics page) { setBackground (Color.darkGray); page.setColor (Color.red); page.drawRect (10, 15, 125, 85); page.setColor (Color.green); page.drawString ("Nature\'s first green", 25, 45); page.setColor (Color.yellow); page.drawString ("is gold", 50, 75); }//strategy paint }//class Nature Komar Associates

Slide 10

Nature Applet Results Komar Associates

Slide 11

XOR Mode Normally, one shape drawn over another overwrites XOR mode permits shapes to stay unmistakable regardless of the possibility that covering Use the setXORMode capacity to turn it on Takes a shading as a parameter - shading is utilized to process a shading for the cover of shapes Also used to eradicate a shape by drawing over it Komar Associates

Slide 12

XOR_Mode Applet import java.awt.*; import java.applet.*; open class XOR_Mode augments Applet { open void paint (Graphics page){ page.setXORMode (Color.red); page.fillRect (10,10,20,20); page.fillRect (40,10,20,20); page.fillRect (100,10,20,20); page.fillRect (110,20,20,20); page.fillRect (140,10,20,20); page.fillRect (140,10,20,20); }//technique paint }//class XOR_Mode Komar Associates

Slide 13

XOR_Mode Applet Results Komar Associates

Slide 14

Drawing Shapes Lines, ovals, rectangles, circular segments, polygons, and polylines circle is a particular sort of oval square is a particular sort of rectangle polygons incorporate any versatile shapes polylines are lines joined end-to-end Most shapes can be drawn filled or unfilled e.g. drawOval versus fillOval Komar Associates

Slide 15

Ovals drawOval (int x, int y, int width, int tallness) fillOval (int x, int y, int width, int stature) width stature Komar Associates

Slide 16

Ovals as Spinning Disk import java.awt.*; import java.applet.*; open class Rotating_Disk amplifies Applet { open void paint (Graphics page) { int width = 0, stature = 40; int x = 100, y = 100, twist = 1; page.setXORMode (getBackground()); for (int change = 1; change < 1000; change++) { width += twist * 2; x - = twist; if (width == 0 || width == 40) twist *= - 1; page.fillOval (x, y, width, stature); for (int stop = 1; delay <= 500000; pause++); page.fillOval (x, y, width, stature); }//technique paint }//class Rotating_Disk Komar Associates

Slide 17

Spinning Disk In Action Rotating Disk Applet Komar Associates

Slide 18

Rectangles drawRect (int x, int y, int width, int tallness) fillRect (int x, int y, int width, int stature) clearRect (int x, int y, int width, int tallness) drawRoundRect (int x, int y, int width, int tallness, int arc_width, int arc_height) fillRoundRect (int x, int y, int width, int tallness, int arc_width, int arc_height) draw3DRect (int x, int y, int width, int tallness, boolean raised) draw3DRect (int x, int y, int width, int stature, boolean raised) Komar Associates

Slide 19

Rounded and 3D Rectangles import java.awt.*; import java.applet.*; open class Rectangles develops Applet { open void paint (Graphics page) { page.drawRoundRect (10,10,50,50,25,25); page.setColor (Color.red); page.fillRoundRect (90,10,40,40,10,30); page.setColor (Color.blue); page.fillRoundRect (150,30,50,20,15,15); page.setColor (Color.orange); page.fill3DRect (10,70,50,50,true); page.draw3DRect (70,70,50,50,false); }//strategy paint }//class Rectangles Komar Associates

Slide 20

Rectangle Results Komar Associates

Slide 21

Arc Angle Start Angle tallness Width Arcs drawArc (int x, int y, int width, int stature, int start_angle, int arc_angle) fillArc (int x, int y, int width, int stature, int start_angle, int arc_angle) Komar Associates

Slide 22

Arcs Applet import java.awt.*; import java.applet.*; open class Arcs augments Applet { open void paint (Graphics page) { page.drawArc (10,10,50,50,45,225); page.drawArc (70,10,30,70,- 180,180); page.setColor (Color.red); page.fillArc (130,10,60,60,- 180,- 90); page.setColor (Color.blue); page.fillArc (190,10,50,50,45,270); page.setColor (Color.green); page.fillArc (250,10,80,40,- 225,180); }//strategy paint }//Class Arcs Komar Associates

Slide 23

Arcs Applet Results Komar Associates

Slide 24

Polygons Polygon class can be utilized to characterize a polygon addPoint system adds focuses to the polygon Graphics class contains strategies to draw a polygon drawPolygon(int[ ] xpoints, int[ ] ypoints, int numpoints) drawPolygon(Polygon poly) fillPolygon(int[ ] xpoints, int[ ] ypoints, int numpoints) fillPolygon(Polygon poly) Polygons are constantly shut shapes - if the last point determined does not close the shape, it is naturally shut Komar Associates

Slide 25

Polygons Applet import java.awt.*; import java.applet.*; open class Polygons expands Applet { private int[] xset1 = {110,110,115,120,150,135}; private int[] yset1 = {10,40,30,50,15,7}; private int[] xset2 = {195,170,170,195,220,220}; private int[] yset2 = {10,20,40,50,40,20}; private int[] xset3 = {110,150,110,150,110}; private int[] yset3 = {70,70,110,110,70}; private Polygon poly = new Polygon(); Komar Associates

Slide 26

Polygons Applet open void paint (Graphics page) { page.drawPolygon (xset1, yset1, 6); page.drawPolygon (xset2, yset2, 6); page.setColor (Color.red); page.fillPolygon (xset3, yset3, 5); poly.addPoint (170, 70); poly.addPoint (170, 90); poly.addPoint (190, 110); poly.addPoint (220, 90); page.setColor (Color.blue); page.fillPolygon (poly); }//system paint }//class Polygons Komar Associates

Slide 27

Polygons Applet Results Komar Associates

Slide 28

Polylines drawPolyline (int[ ] xpoints, int[ ] ypoints, int numpoints) Similar to polygon aside from a polyline is not a shut shape Komar Associates

Slide 29

Fonts Each PC framework may bolster an alternate arrangement of text styles See Font_Lister program on p. 275 Font class page.setFont (new Font (String name, int style, int size)) name is the textual style\'s name (TimesRoman, etc.0 style is whole number for plain, striking, italic - use Font.PLAIN , Font.BOLD , or Font.ITALIC size is the point size of the text style Komar Associates

Slide 30

Fonts Applet import java.awt.*; import java.applet.*; open class Fonts augments Applet { private String quote = "Komar is an extraordinary instructor."; open void paint (Graphics page) { page.setFont (new Font ("TimesRoman", Font.PLAIN, 12)); page.drawString (quote, 10, 20); page.setFont (new Font ("TimesRoman", Font.BOLD, 12)); page.drawString (quote, 10, 40); page.setColor (Color.red); page.setFont (new Font ("Helvetica", Font.ITALIC+Font.BOLD, 16)); page.drawString (quote, 10, 60); page.setFont (new Font ("Helvetica", Font.PLAIN, 20)); page.drawString (quote, 10, 80); }//technique paint }//class Fonts Komar Associates

Slide 31

Fonts Applet Results Komar Associates

Slide 32

Bouncing Ball import java.awt.*; import java.applet.*; open class Bouncing_Ball develops Applet { private last int PAUSE = 100000; private last int SIZE = 300; private ball = new Ball (150,10,250,200); private Graphics page; Komar Associates

Slide 33

Bouncing Ball (cont’d) open void ini

Recommended
View more...