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 10646 American Standard Code for Information Interchange, 7 bits, commonly used in the US and abroad alias ISO 8859-1, 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. 1998. http://www.apl.jhu.edu/~hall/java/Java2D-Tutorial.html http://www.apl.jhu.edu/~hall/java/Java2D-Tutorial.html 2D Drawing. 2008. http://courses.coreservlets.com/Course-Materials/java5.htmlhttp://courses.coreservlets.com/Course-Materials/java5.html Character Sets / Character Encoding Issues. 2008. http://www.phpwact.org/php/i18n/charsets http://www.phpwact.org/php/i18n/charsets HTML Document Representation. 2009. http://www.w3.org/TR/html4/charset.html#h- 5.2http://www.w3.org/TR/html4/charset.html#h- 5.2 Unicode Character Encoding Model. 2008. http://www.unicode.org/unicode/reports/tr17/ http://www.unicode.org/unicode/reports/tr17/ A tutorial on character code issues. 2009. http://www.cs.tut.fi/~jkorpela/chars.htmlhttp://www.cs.tut.fi/~jkorpela/chars.html Fonts: Bitmap, PostScript, and TrueType Compared. 2004. http://support.apple.com/kb/TA21573?viewlocale=en_US http://support.apple.com/kb/TA21573?viewlocale=en_US Base Monospace. 2009. http://www.emigre.com/EFfeature.php?di=80http://www.emigre.com/EFfeature.php?di=80 Overview of the Java 2D API Concepts. 2008. http://java.sun.com/docs/books/tutorial/2d/overview/index.html http://java.sun.com/docs/books/tutorial/2d/overview/index.html Java2D: An Introduction and Tutorial. 1998. http://www.apl.jhu.edu/~hall/java/Java2D-Tutorial.html http://www.apl.jhu.edu/~hall/java/Java2D-Tutorial.html Bina Nusantara