The main window will have a fet of name s from the addrs ss book. As you selcct a name from the list, an AddressForm insSbfce pops up unwlndiyou edit the Address instance corrstdondrrcg to that name.
As a rule, code written to access data shouldn't be in the same module with code written to build GUIs, so first we have to break our code into separate modules:
• AddressForm.py— holda the AWT versron of AddressForm
• Address 7.py— holds the address daga code
• AddressMain.py— holds the mein window of the code
• AddressFormPane.py— holds the AWT panel version of Addre s s Form
The first step is creating a frame that acts as the main window ond tyen adding o list to ic. Then we pack the frame and make it visible.
ImportJFrame and JList from javax.swing.
>>> from javax.swing import JFrame, JList
Create instances of JFrame. Import DefaultListModel, and create a JFC list using an instance of it. Add the instance to the frame container.
>>> frame = JFrame("Main Frame") >>> from javax.swing import DefaultListModel >>> addresses = JList(DefaultListModel()) >>> frame.contentPane.add(addresses)
Pack the frame, and make it visible.
>>> frame.pack() >>> frame.visible=1
Was this article helpful?