Illustrations and Java 2D.

Uploaded on:
Illustrations and Java 2D Presentation Java's representation capacities Drawing 2D shapes Controlling hues Controlling textual styles Java 2D Programming interface More refined design abilities Drawing custom 2D shapes Filling shapes with hues and examples Object Shading Segment Arc2D Text style FontMetrics
Slide 1

Illustrations and Java 2D

Slide 2

Introduction Java’s design capacities Drawing 2D shapes Controlling hues Controlling text styles Java 2D API More advanced representation abilities Drawing custom 2D shapes Filling shapes with hues and examples

Slide 3

Object Color Component Arc2D Font FontMetrics Graphics BasicStroke Polygon Classes and interfaces from the Java2D API that show up in bundle java.awt Classes from the Java2D API that show up in bundle java.awt.geom interface java.awt.Paint interface java.awt.Shape GeneralPath interface java.awt.Stroke Line2D RectangularShape Graphics2D Ellipse2D GradientPaint Rectangle2D TexturePaint RoundRectangle2D Introduction: Classes and Interfaces

Slide 4

Introduction Java’s coordinate framework Scheme for distinguishing all focuses on screen Upper-left corner has arranges (0,0) Coordinate point made out of x-direction and y-coordinate

Slide 5

Graphics Contexts and Graphics Objects Graphics connection Enables drawing on screen Graphics item oversees illustrations setting Controls how data is drawn Class Graphics is dynamic Cannot be instantiated Contributes to Java’s conveyability Class Component technique paint takes Graphics object open void paint( Graphics g ) Called through system repaint

Slide 6

Color Control Class Color Defines strategies and constants for controlling hues Colors are made from red, green and blue parts RGB values

Slide 7

Color consistent and quality

Slide 8

Color routines & shading related Graphic routines

Slide 9

1/ 2/Choosing hues with JColorChooser. 3 import java.awt.*; 4 import java.awt.event.*; 5 import javax.swing.*; 6 7 open class ShowColors expands JFrame { 8 private JButton changeColorButton; 9 private Color shading = Color.LIGHT_GRAY ; 10 private Container compartment; 11 12/set up GUI 13 open ShowColors() 14 { 15 super ( "Using JColorChooser" ); 16 17 holder = getContentPane(); 18 container.setLayout( new FlowLayout() ); 19 20/set up changeColorButton and register its occasion handler 21 changeColorButton = new JButton( "Change Color" ); 22 changeColorButton.addActionListener( 23

Slide 10

JColorChooser permits client to look over among a few hues static system showDialog shows the shading chooser dialog 24 new ActionListener() {/unknown inward class 25 26/show JColorChooser when client snaps catch 27 open void actionPerformed( ActionEvent occasion ) 28 { 29 shading = JColorChooser.showDialog( 30 ShowColors. this , "Choose a color" , shading ); 31 32/set default shading, if no shading is returned 33 if ( shading == invalid ) 34 shading = Color.LIGHT_GRAY ; 35 36/change substance sheet\'s experience shading 37 container.setBackground( shading ); 38 } 39 }/end unknown internal class 40 );/end call to addActionListener 41 42 container.add( changeColorButton ); 43 44 setSize( 400 , 130 ); 45 setVisible( genuine ); 46 }/end ShowColor2 constructor

Slide 11

47/execute application 48 open static void principle( String args[] ) 49 { 50 ShowColors application = new ShowColors(); 51 application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); 52 } 53 }/end class ShowColors2

Slide 12

Font Control Class Font Contains systems and constants for textual style control Font constructor takes three contentions Font name Monospaced , SansSerif , Serif , and so on. Textual style Font.PLAIN , Font.ITALIC and Font.BOLD Font size Measured in focuses (1/72 of inch)

Slide 13

Font-related routines and constants

Slide 14

Font-related techniques and constants/set text 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 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 textual 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 );/set textual style to Serif (Times), striking/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 );

Slide 15

Java 2D API Java 2D API Provides progressed 2D design abilities java.awt java.awt.image java.awt.color java.awt.font java.awt.geom java.awt.print java.awt.image.renderable Uses class java.awt.Graphics2D Extends class java.awt.Graphics

Slide 16

Java 2D API when utilizing Swing overide paintComponent rather than paint .

Slide 17

Java 2D API Java 2D shapes Package java.awt.geom Ellipse2D.Double Rectangle2D.Double RoundRectangle2D.Double Arc3D.Double Lines2D.Double

Slide 18

Java 2D API The Java 2D API presents java.awt.Graphics2D , another kind of Graphics item. Graphics2D extends the Graphics class to give access to the improved illustrations and rendering components of the Java 2D API. To utilize Java 2D API highlights, you cast the Graphics item went into a segment\'s rendering system to a Graphics2D object. open void Paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; ... }

Slide 19

Java 2D Drawing Process: Step 1 Cast Graphics item to Graphics 2D open void paintComponent(Graphics g) { super.paingComponent(g);/Typical Swing Graphics2d g2d = (Graphics2d) g; g2d.doSomeStuff(...); ... } Note All systems that arrival Graphics in Java 1.1 return Graphics2D in Java 2 paint, paintComponent getGraphics

Slide 20

Java 2D Drawing Process: Step 2 Set pen parameters g2d. setPaint (fillColorOrPattern); g2d. setStroke (penThicknessOrPattern); g2d. setComposite (someAlphaComposite); g2d. setFont (someFont); g2d. interpret (...); g2d. turn (...); g2d. scale (...); g2d. shear (...); g2d. setTransform (someAffineTransform);

Slide 21

Java 2D Drawing Process: Step 3 Create a Shape object. Rectangle2D.Double rect = ...; Ellepse2D.Double oval = ...; Polygon poly = ...; GeneralPath way = ...;/fulfills Shape interface SomeShapeYouDefined shape = ...; Note Most shapes are in the java.awt.geom bundle There is a relating Shape class for a large portion of the draw Xxx strategies for Graphics

Slide 22

Java 2D Drawing Process: Step 4 Draw a sketched out or filled adaptation of the Shape g2d. draw (someShape); g2d. fill (someShape); The legacy routines are still upheld drawString drawLine, drawRect, fillRect

Slide 23


View more...