Representation and Java2D.


94 views
Uploaded on:
Category: Medical / Health
Description
Illustrations and Java2D Joe Komar Review Design connections and representation objects Shading control Textual style control Drawing lines, rectangles, ovals, curves, polygons, and polylines Java2D Programming interface Java2D Shapes Illustrations Coordinate Framework 0,0 is the upper left corner
Transcripts
Slide 1

Design and Java2D Joe Komar Associates

Slide 2

Overview Graphics settings and illustrations items Color control Font control Drawing lines, rectangles, ovals, circular segments, polygons, and polylines Java2D API Java2D Shapes 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 sure x 0,0 X y x,y Y Komar Associates

Slide 4

Coordinates Applet import java.awt.*; import java.applet.*; open class Coordinates amplifies 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); }//strategy paint }//class Coordinates Komar Associates

Slide 5

Output of Coordinates Applet Komar Associates

Slide 6

Graphics “context” empowers drawing on the screen Graphics article deals with a representation connection Graphics is a theoretical class actualized on every stage Component class is essential superclass for Applet and JApplet Komar Associates

Slide 7

paint technique for Component Accepts a Graphics object Must be overridden When Applet runs, calls init, begin , then paint strategies repaint technique called by software engineer, which calls the Component ’s upgrade then paint technique Komar Associates

Slide 8

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 large number of hues Predefined hues ( last static Color articles) e.g., Color.blue, Color.green, Color.cyan Komar Associates

Slide 9

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 10

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

Slide 11

Nature Applet import java.awt.*; import java.applet.*; open class Nature augments 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); }//technique paint }//class Nature Komar Associates

Slide 12

Nature Applet Results Komar Associates

Slide 13

ShowColors Example/Fig. 11.5: ShowColors.java/Demonstrating Colors import java.awt.*; import javax.swing.*; import java.awt.event.*; open class ShowColors augments JFrame { open ShowColors() { super( "Using colors" ); setSize( 400, 130 ); appear(); } Komar Associates

Slide 14

ShowColors Example open void paint( Graphics g ) {/set new drawing shading utilizing numbers g.setColor( new Color( 255, 0, 0 ) ); g.fillRect( 25, 25, 100, 20 ); g.drawString( "Current RGB: " + g.getColor(), 130, 40 );/set new drawing shading utilizing buoys g.setColor( new Color( 0.0f, 1.0f, 0.0f ) ); g.fillRect( 25, 50, 100, 20 ); g.drawString( "Current RGB: " + g.getColor(), 130, 65 );/set new drawing shading utilizing static Color articles g.setColor( Color.blue ); g.fillRect( 25, 75, 100, 20 ); g.drawString( "Current RGB: " + g.getColor(), 130, 90 ); Komar Associates

Slide 15

ShowColors Example/show individual RGB qualities Color c = Color.magenta; g.setColor( c ); g.fillRect( 25, 100, 100, 20 ); g.drawString( "RGB values: " + c.getRed() + ", " + c.getGreen() + ", " + c.getBlue(), 130, 115 ); } Komar Associates

Slide 16

ShowColors Example open static void primary( String args[] ) { ShowColors application = new ShowColors(); app.addWindowListener( new WindowAdapter() { open void windowClosing( WindowEvent e ) { System.exit( 0 ); } ); } Komar Associates

Slide 17

ShowColors Example Komar Associates

Slide 18

JColorChooser Dialog Box static technique showDialog of class JColorChooser presents dialog Can pick by shading swatch; tone, immersion and splendor (HSB); or by red, green, blue (RGB) Returns the Color item picked See case run... Komar Associates

Slide 19

Fonts Uses right now bolstered text styles on the framework Constructor takes String textual style name, int style, int size Styles - Font.PLAIN, Font.BOLD, Font.ITALIC Size is number of focuses (1/72nd of an inch) Komar Associates

Slide 20

Fonts Example/Fig. 11.9: Fonts.java/Using textual styles import java.awt.*; import javax.swing.*; import java.awt.event.*; open class Fonts broadens JFrame { open Fonts() { super( "Using fonts" ); setSize( 420, 125 ); appear(); } Komar Associates

Slide 21

Fonts Example open void paint( Graphics g ) {/set current textual style to Serif (Times), strong, 12pt/and draw a string g.setFont( new Font( "Serif", Font.BOLD, 12 ) ); g.drawString( "Serif 12 point bold.", 20, 50 );/set current textual style to Monospaced (Courier),/italic, 24pt and draw a string g.setFont( new Font( "Monospaced", Font.ITALIC, 24 ) ); g.drawString( "Monospaced 24 point italic.", 20, 70 );/set current text style to SansSerif (Helvetica),/plain, 14pt and draw a string g.setFont( new Font( "SansSerif", Font.PLAIN, 14 ) ); g.drawString( "SansSerif 14 point plain.", 20, 90 ); Komar Associates

Slide 22

Fonts Example/set current text style to Serif (times), intense/italic,/18pt and draw a string g.setColor( Color.red ); g.setFont( new Font( "Serif", Font.BOLD + Font.ITALIC, 18 ) ); g.drawString( g.getFont().getName() + " " + g.getFont().getSize() + " point striking italic.", 20, 110 ); } Komar Associates

Slide 23

Fonts Example open static void primary( String args[] ) { Fonts application = new Fonts(); app.addWindowListener( new WindowAdapter() { open void windowClosing( WindowEvent e ) { System.exit( 0 ); } ); } Komar Associates

Slide 24

Fonts Example Komar Associates

Slide 25

Font Metrics Height - aggregate size Ascent - essential character size Leading - above character Descent - beneath character Methods to get these and also getFontMetrics to give back a FontMetrics object Komar Associates

Slide 26

Drawing Shapes Lines, ovals, rectangles, bends, 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 27

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

Slide 28

Ovals as Spinning Disk import java.awt.*; import java.applet.*; open class Rotating_Disk amplifies Applet { open void paint (Graphics page) { int width = 0, tallness = 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, tallness); }//for circle }//technique paint }//class Rotating_Disk Komar Associates

Slide 29

Spinning Disk In Action Rotating Disk Applet Komar Associates

Slide 30

Rectangles drawRect (int x, int y, int width, int stature) fillRect (int x, int y, int width, int tallness) clearRect (int x, int y, int width, int tallness) drawRoundRect (int x, int y, int width, int stature, int arc_width, int arc_height) fillRoundRect (int x, int y, int width, int stature, 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 tallness, boolean raised) Komar Associates

Slide 31

Rounded and 3D Rectangles import java.awt.*; import java.applet.*; open class Rectangles expands 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 32

Rectangle Results Komar Associates

Slide 33

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

Slide 34

Arcs Applet import java.awt.*; import java.applet.*; open class Arcs augments Applet { open void pain

Recommended
View more...