Properties

Sometimes properties are more complex than basic Java types—for example, a property can be a type of class. You can set properties that expect class instances with tuples that correspond to the constructor of the property type. (This only works for things like java.awt.Dimension.)

An example of this is the setSize() method of javax.swing.JFrame. The size property expects an instance of class Size, whose constructor expects width and height integer arguments.

The following code recaps what we've learned so far about using properties. We'll show how to create a frame and set its size property with a tuple, and we'll show the frame's visible property. Don't worry that you don't know JFC/Swing. I'll walk you through it.

Import the JFrame ...

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.