0

I'm currently on NetBeans lessons on how to create Java programs with GUI. I've noticed in several GUI controls the text field and the combobox, the "Action" and the "Name" properties are always present. What is the purpose of these properties and how can I use them? For example, I'll use a text field here:

JTextField aTextField = new JTextField();
String act = "aksyon";
JTextField.setActionCommand(act);

What is the difference of setActionCommand() from setAction()? I thank you in advance for your help.

ryndgmn
  • 17
  • 5
  • If you're teaching yourself GUI programming in java, you really should be learning javafx. – Steve Siebert Nov 05 '14 at 13:57
  • I've already seen a sample code utilizing JavaFx but I'm not yet at JavaFx lessons. I hope to reach and start studying that lesson soon. – ryndgmn Nov 05 '14 at 14:37
  • The reason I mention is that, while JavaFX provides backwards compatibility support for swing components, is should be considered only for situations where you have existing swing applications (prior investment) and you want to gently start moving things over to FX. But, if you're starting fresh...I would "skip" (ignore) swing tutorials (unless you determine you **need** to use swing) and just start learning JavaFX instead. – Steve Siebert Nov 05 '14 at 16:20
  • Thank you for your advice sir. I'll browse first the lessons on JavaFx on Oracle's website and after assessing its worth learning than Swing, I'll skip my current study on Swing then move to JavaFx lessons. – ryndgmn Nov 06 '14 at 01:28

1 Answers1

1

ActionCommand is the key used to determine the command String for the ActionEvent that will be created when an Action is going to be notified as the result of residing in a Keymap associated with a JComponent.

public void setActionCommand(String command)

Sets the command name for the action event fired by this button. By default this action command is set to match the label of the button. read more here

Sagar Pudi
  • 4,634
  • 3
  • 32
  • 51
  • 1
    Ah ok for example, if I have a button named myButton and its label is Show, I can use the label of the button, for example, to initiate an action? Like: if(myButton.getAcionCommand() == "Show") //then do some actions – ryndgmn Nov 05 '14 at 14:44