To convert from AWT to AFC, instances of java.awt.Button should be transformed into instances of com.ms.ui.UIPushButton.
Button extends Component: be sure to see its changes.
UIPushButton is one of AFC's five classes that implement button types, and the one that mirrors java.awt.Button. UIPushButton provides several advantages over Button.
The class UIRepeatButton (which extends UIPushButton) allows you to continually generate events while the button remains pressed.
In java.awt.Button, you can only create buttons associated with text labels. In AFC, though, buttons can also be created with UIComponents, which means you can make buttons of text, images, or combinations thereof. For example, instead of
Button b = new Button("foo");
you can have
UIPushButton b = new UIPushButton(new UIText("foo"));
UIPushButton c = new UIPushButton(new UIGraphic(myImage));You also have other options to make the button hottracked, and to have it start as raised and/or toggled.
Other benefits come directly from the changes to Component and Container: see the documentation for more information.
This is the set of changes you need to make to port all Button methods to UIPushButton methods. Any method not listed here or below does not need to be changed.
AWT Code | AFC Code | Comments |
Button(String) | UIPushButton(String) | This is a direct port, but you have other options: you could add styles and use UIComponents instead of Strings--see above. |
Button() | UIPushButton() | You could add styles--see above. |
getLabel() | getName() | |
setLabel(String) | setName(String) |
Some methods in java.awt.Button are not directly supported in com.ms.ui.UIPushButton. Those methods and suggested changes are described here.
AWT Code/Suggested AFC Code | Comments |
paramString() getName() |
paramString usually just returns the
name of the button, so getName should be sufficient. |
setActionCommand(String) setName(String) |
In AFC, the String that would have
been passed by setActionCommand is always the name of the object, so setName is the same information: however, setName will also change the label of the UIPushButton. |
getActionCommand() getName() |
In AFC, the String sent when an action
event occurs is the name, so this should return the same result. |