Converting from the AWT to Swing

   

If you are presented with the task of creating a Swing program that replaces an existing AWT program, it's important that you first learn some Swing basics (like you will learn in the next chapter). Then, convert the AWT program to its Swing-based equivalent, and then add new capabilities and/or remove/replace existing capabilities. When you are ready to convert from the AWT to Swing, keep the following tips in mind:

  • Back up your code.

  • Remove all java.awt package/subpackage references.

  • Remove all java.applet package references (for applets only).

  • Add an import javax.swing.*; directive.

  • Watch out for threading problems. (Chapter 16, "Building a GUI: Swing Style," explains Swing's threading issues and discusses workarounds.)

  • Convert AWT components to Swing equivalents.

  • Rewrite calls that add components to containers.

  • Move all painting code out of any paint and update methods .

  • Let the compiler find any other required changes.

  • Run the converted program.

  • Make any additional improvements offered by Swing (such as using its capability to right justify a JTextField component's text, which is not possible in a TextField component).

  • Clean up any AWT code hacks and bug workarounds

These tips are summarized ”and paraphrased ”from the conversion tips offered by the online Java Tutorial located at http://www.javasoft.com/tutorial. For more details, please visit this tutorial and check out its AWT to Swing conversion section.

Troubleshooting Tip

If you're converting an AWT program that uses list and text components to Swing, you might notice that when you run the Swing version of this program, its list and text components don't have scrollbars. See "List and Text Component Scrollbar Differences," in the "Troubleshooting" section for more information.


   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net