Ryan Fernandes
Ryan Fernandes

Reputation: 8526

convert awt to swing automatically

From what I know and have been reading, converting from awt to swing seems to be quite mechanical. With the exception of the different threading model, most of swing components generally map well with the awt ones.

Was looking for a tool to do this conversion automatically. Understandably, this may not be a 100% conversion, but at least the mechanical process should be fairly automated. Would any one know of a such a tool ?

Upvotes: 4

Views: 1675

Answers (2)

Andrew Thompson
Andrew Thompson

Reputation: 168825

Why a script changing AWT to Swing component names will not be sufficient.

  • Swing components must be constructed & updated on the EDT. This restriction does not apply to AWT.
  • Pre 1.5(?) components needed to be added to Swing top level containers using getContentPane().add()
  • Scrolling is different between an AWT TextArea (built-in) & Swing JTextArea (wrapped in a JScrollPane)
  • Constructors may vary. E.G. no JTextArea(String,int,int,int)
  • In non TLCs. Override paint(Graphics) in AWT, paintComponent(Graphics) in Swing.
  • There is no direct equivalent of Canvas.
  • A CheckBox might be translated to a JCheckBox, but a CheckBox in a CheckBoxGroup should be converted to a JRadioButton in a ButtonGroup.

Advantages of Swing it will miss.

  • JFrame has a defaultCloseOperation(int), which can (often) replace the AWT WindowListener.

Upvotes: 3

othman
othman

Reputation: 4556

there is a good article http://java.sys-con.com/node/36335

by reading this article it should be fairly easy to build this awt to swing tool yourself. you could write a search/replace script to change the names of the AWT components to the corresponding Swing ones.

Upvotes: 0

Related Questions