To create a button you would put the button on the JFrame, or select it if it's already there, then right click the component and select Edit Text to put the right text on the button top. To add code to handle the actionEvent that is generated when a button is clicked, do the following.
- Choose a good variable name. Right click the component and select Change Variable Name... to set the variable name to something meaningful.
- Listener. Right click the component and select Event > Action > actionPerformed. This will generate a listener, and generate the top and bottom lines of a "handler" method that is called by the listener when the button is clicked.
- Handler method. The name of this methods is the name of the JButton variable that you chose in a previous step, followed by "ActionPerformed", so choose a good name for the button. Write code to do what you want inside this method. Typically this code will have some interaction with the model and other components.
No comments:
Post a Comment