Here, you will learn about adding event i.e. the rollover and click icon to a JButton component of swing in java. Rollover means moving mouse pointer above the icon on the button. This program shows an icon or image on the button if the mouse pointer moves above the Button then your icon or image should be changed. When you click on the button then another image or icon should be shown on the button.
This program displays a button on a frame. Button shows different icons like: cut, copy and paste on different events. At first, the button shows the "cut" icon and when the mouse pointer moves above the button then the button shows the "copy" icon and when you click on the button then the "paste" icon is seen. Following are the screenshot of the application:
This the "cut" image which occurs by default
when the program is rum from the command prompt.
This is the "copy" image which occurs by
default when user will rollover the image or button.
And this is the "paste" image which occurs by
default when user clicks on the button.
These events are managed by the program using some APIs or methods as follows:
This is the method of the JButton class which is used to set the icon or image to a button for display when the mouse pointer rolls over the icon or the button. The icon or image is passed through the method as a parameter.
This is the method of the JButton class which is used to set the icon or image to a object for displaying when the button is clicked. The icon or image is specified in the method argument as a parameter.
Here is the code of program:
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.