import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
publicclass Main {
publicstaticvoid main(String[] argv) throws Exception {
Action action = new AbstractAction("Button Label") {
// This method is called when the button is pressed
publicvoid actionPerformed(ActionEvent evt) {
// Perform action...
}
};
// Create the button from the action
JButton button = new JButton(action);
}
}