O'Reilly logo

Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython by Richard Hightower

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required