June 2002
Beginner to intermediate
640 pages
14h 24m
English
Every AWT component has a method called getGraphics(), which returns the instance of the graphics object associated with it. The graphics object allows you to draw on the component. With the java.awt.Graphics object you can draw arcs, images, lines, ovals, polylines, and such. We can't cover all of the possibilities, only enough to whet your appetite. Later we'll build a drawing package that works with text, rectangles, circles, and ovals. For now, let's do an interactive session that introduces drawing on a component.
Import a frame, and create an instance of it. We'll use it to do our drawing.
>>> from javax.swing import JFrame, JPanel >>> frame = JFrame("Drawing", size=(400,400), visible=1) >>> graphics = frame.contentPane.graphics ...Read now
Unlock full access