Download presentation
Presentation is loading. Please wait.
Published byAgnes Sanders Modified over 9 years ago
1
1 Graphical User Components (II) Outline JTextArea Creating a Customized Subclass of JPanel JPanel Subclass that Handles Its Own Events Windows: Additional Notes Using Menus with Frames
2
2 JTextArea –Area for manipulating multiple lines of text –extends JTextComponent..\..\..\212-winter-2005\week11\textarea_18
3
3 Creating a Customized Subclass of JPanel Extend JPanel to create new components –Dedicated drawing area Method paintComponent of class JComponent..\..\week11\panel_demo_17
4
4 Windows: Additional Notes JFrame –Windows with title bar and border –Subclass of java.awt.Frame Subclass of java.awt.Window –Heavyweight component –Three operations when user closes window DISPOSE_ON_CLOSE DO_NOTHING_ON_CLOSE HIDE_ON_CLOSE
5
5 Using Menus with Frames Menus –Allows for performing actions with cluttering GUI –Contained by menu bar JMenuBar –Comprised of menu items JMenuItem..\..\week12\Menu_1
6
6 Introduction Graphics Contexts and Graphics Objects Color Control Font Control Drawing Lines, Rectangles and Ovals Drawing Arcs Drawing Polygons and Polylines Graphics and Java 2D
7
7 12.1 Introduction Java’s graphics capabilities –Drawing 2D shapes –Controlling colors –Controlling fonts Java 2D API –More sophisticated graphics capabilities Drawing custom 2D shapes Filling shapes with colors and patterns
8
8 Classes and interfaces used in this chapter from Java’s original graphics capabilities and from the Java2D API. Classes and interfaces from the Java2D API that appear in package java.awt Object Color Component Font FontMetrics Graphics Polygon Graphics2D interface java.awt.Paint interface java.awt.Shape interface java.awt.Stroke Classes from the Java2D API that appear in package java.awt.geom GradientPaint BasicStroke TexturePaint RectangularShape GeneralPath Line2D RoundRectangle2D Arc2D Ellipse2D Rectangle2D
9
9 Introduction Java’s coordinate system –Scheme for identifying all points on screen –Upper-left corner has coordinates (0,0) –Coordinate point composed of x-coordinate and y-coordinate
10
10 Java coordinate system. Units are measured in pixels
11
11 Graphics Contexts and Graphics Objects Graphics context –Enables drawing on screen –Graphics object manages graphics context Controls how information is drawn –Class Graphics is abstract Cannot be instantiated Contributes to Java’s portability –Class Component method paint takes Graphics object public void paint( Graphics g ) –Called through method repaint
12
12 Color Control Class Color –Defines methods and constants for manipulating colors –Colors are created from red, green and blue components RGB values
13
13 Color constants and their RGB values
14
14 Color methods and color-related Graphics methods..\..\week12\Color_2..\..\week12\Color_3
15
15 Font Control Class Font –Contains methods and constants for font control –Font constructor takes three arguments Font name –Monospaced, SansSerif, Serif, etc. Font style –Font.PLAIN, Font.ITALIC and Font.BOLD Font size –Measured in points (1/72 of inch)
16
16 Font -related methods and constants
17
17 Font -related methods and constants..\..\week12\Fond_4
18
18 Font Control Font metrics –Height –Descent (amount character dips below baseline) –Ascent (amount character rises above baseline) –Leading (difference between descent and ascent)
19
19 Font metrics
20
20 FontMetrics and Graphics methods for obtaining font metrics..\..\week12\FontMetrics_5
21
21 Drawing Lines, Rectangles and Ovals Class Graphics –Provides methods for drawing lines, rectangles and ovals All drawing methods require parameters width and height
22
22 Graphics methods that draw lines, rectangles and ovals
23
23 Graphics methods that draw lines, rectangles and ovals..\..\week12\Lines_6
24
24 Arc width and arc height for rounded rectangles
25
25 Oval bounded by a rectangle
26
26 Drawing Arcs Arc –Portion of oval –Measured in degrees –Sweeps the number of degrees in arc angle –Sweep starts at starting angle Counterclockwise sweep is measure in positive degrees Clockwise sweep is measure in negative degrees
27
27 Positive and negative arc angles 90° 0°180° 270° 90° 0°180° 270° Positive anglesNegative angles
28
28 Graphics methods for drawing arcs..\..\week12\Arc_7
29
29 Drawing Polygons and Polylines Class Polygon –Polygons Multisided shapes –Polylines Series of connected points
30
30 Graphics methods for drawing polygons and class Polygon methods
31
31 Graphics methods for drawing polygons and class Polygon methods..\..\week12\Polygons_8
32
32 12.8 Java2D API Java 2D API –Provides advanced 2D graphics capabilities 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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.