Bina Nusantara Learning Outcomes In the end of this session, students must be able to: –Understand the basic principal of Java2D Graphics –Apply correct Java syntax to use Java2D Graphics
Outline Font 2D Graphics Java 2D Graphics Bina Nusantara
Font - Characters Bina Nusantara Characters (Alphabets) WordsSentencesLanguage Digits (123) Letters (ABC) Symbols
Character Codes Bina Nusantara Character Code ASCII ISO Latin 1 Unicode ISO American Standard Code for Information Interchange, 7 bits, commonly used in the US and abroad alias ISO , 8 bits, commonly used for computer processing 16 bits, include characters from all known languages and alphabets in the world (multilingual text and character encoding) 32 bits, defines UCS (Universal Character Set) A group of characters, each assigned with a unique numerical code
Characters & Glyphs CharactersGlyphsFonts Bina Nusantara represented in a visual display organized in one set One character can be represented as several glyphs Two or more characters can be represented in one glyphs AAAAA
Fonts Size –measured in points ( 1 point = 1/72 inch) Style –Bold, Italic, Underline, superscript, subscript, etc Classification Bina Nusantara Bitmap Glyphs are represented in bitmap (raster) blocky and less legible if enlarge PostScript developed by Adobe scalable require Adobe Type Manager (ATM) software to look smooth good for design and publishing not cross platform compatible TrueType jointly developed by Apple and Microsoft scalable not cross platform compatible everyone can make a new TT font OpenType jointly developed by Apple and Microsoft scalable not supported by all application cross platform compatible
Font Spacing Bina Nusantara all characters have the same width used for typewriter/newspaper characters’ width varies with the shape easier to read used for textbook
Font Bina Nusantara Font is accessible as long as installed in your computer. Font use only setFont and drawString.
Graphics Bina Nusantara Graphic Primitives Shapes Images Text Rendering Engine Java graphics2D Output Devices Screens Printers An engine to display graphic primitives on output devices
Graphics Coordinates Shapes Stroke Fill Composite Antialiasing Bina Nusantara
Coordinates User space – The space in which graphics primitives are specified Device space – The coordinate system of an output device such as a screen, window, or a printer Bina Nusantara X Y 0
Coordinates Bina Nusantara Graphic Primitives Rendering Engine Output Devices User SpaceDevice Spacetransform user space into device space
Coordinates Bina Nusantara An example to know the coordinate of mouse click in an image. Use MouseListener. Full code is downloadable in Additional Material.
Shapes Point Lines Rectangular Shapes Quadratic and Cubic Curves Bina Nusantara
Shapes Bina Nusantara An example showing how to make an Ellipse Shape
Stroke An outline of lines /dashing patterns on a graphic primitive Bina Nusantara SolidRound DotDashLong Dash Dot Thickness & Color
Stroke Bina Nusantara We add these codes to the previous code of shape, and we get strokes. Full code is downloadable in Additional Material.
Fill Interior of a graphic primitive Bina Nusantara SolidGradientTexture/ Pattern Image
Fill Bina Nusantara We add these codes to the previous code of shape, and we get gradient paint to fill. Full code is downloadable in Additional Material.
Composite Adding new objects on existing objects Bina Nusantara Composite
Bina Nusantara We add two shapes and for the second one we apply AlphaComposite to blend them together. Full code is downloadable in Additional Material.
Antialiasing Bina Nusantara AliasingAntialiasing
Bina Nusantara Antialiasing is used to smooth the curve of the font. In this example, “W” is smooth enough, even though it is enlarged.
References Java2D: An Introduction and Tutorial D Drawing Character Sets / Character Encoding Issues HTML Document Representation http://www.w3.org/TR/html4/charset.html#h- 5.2 Unicode Character Encoding Model A tutorial on character code issues Fonts: Bitmap, PostScript, and TrueType Compared Base Monospace Overview of the Java 2D API Concepts Java2D: An Introduction and Tutorial Bina Nusantara