A Quick Graphics Tour
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 ...
Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.