Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Java
Expertise: Intermediate
Mar 16, 1998



Building the Right Environment to Support AI, Machine Learning and Deep Learning

A Button Constructor for Java 1.1

With JDK 1.1, you can define an action command String for a Button that is independent of the text displayed in the Button. At the least, this enables you to separate the testing for which Button has been pressed from the spelling of the label. At best, it helps keep the code smaller if you add multiple-language support. With 1.1's event model, it is unlikely that you will create a Button without nominating a listener for the action event. But the unchanged set of Button constructors does not encourage the use of either of these features. The following simple extension to the Button class should help.
 import java.awt.*;
import java.awt.event.*;

public class Button11 extends Button {
	public Button11(String         caption,
	                String         command,
	                ActionListener waiting) {
		if (command != null) setActionCommand (command);
		if (waiting != null) addActionListener(waiting);
Tom Yarker
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date