A Button Constructor for Java 1.1

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) {		super(caption);		if (command != null) setActionCommand (command);		if (waiting != null) addActionListener(waiting);	}}

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist