Question: Lab Button CSIS-1410 In Eclipse create a new package called ImageButton Download the images Image1, Image2 and Image3 from Canvas and import them to the
Lab Button CSIS-1410 In Eclipse create a new package called ImageButton Download the images Image1, Image2 and Image3 from Canvas and import them to the package ImageButton (right-click ImageButton, import . . . ) Notice the different file extensions. Create two public classes: ImageButton and ImageButtonApp ImageButton derives from JFrame In ImageButton do the following: Create two final fields: imgButton of type JButton clickImage of type Icon In the constructor do the following: o Set the title to Lab Button o Create two local variables of type Icon: image1 and image2. Initialize them with a new ImageIcon base on Image1 and Image2 - like this: Icon image1 = new ImageIcon(getClass().getResource("Image1.png")); o Initialize the field clickImage with a new ImageIcon that is based on Image3 o Initialize the field imgButton with a new JButton that accepts image1 as the only argument o Call the method setRolloverIcon on imgButton and pass image2 as roll-over icon o Add the imgButton to this (ImageButton, which is a JFrame) In ImageButtonApp do the following: Crate an instance of ImageButton Make sure that the ImageButton (which is a JFrame) terminates when the user clicks the x-Button to exit Hint: call setDefaultCloseOperation Set the size to 660 x 660 Set visibility to true Compile / Run .. you should see an image that changes every time you roll over the mouse Back in ImageButton do the following: Outside the constructor but still inside class ImageButton create a private class called ButtonClickEventHandler. It implements the interface ActionListener (soon well look at an alternative way using an anonymous inner class) Eclipse can help with the import statement. It can also create a method stub for the method actionPerformed. In actionPerformed replace the TODO comment with the following code: o Disable rollorver on imgButton - Hint: use the method setRolloverEnabled and pass false o Set the image to Image3 - Hint: use the method setIcon and pass the field clickImage At the end of the constructor body do the following: Create an instance of ButtonClickEventHandler and name it buttonEventHandler Associate the buttonEventHandler with the imgButton by calling the method addActionListener and by passing buttonEventHandler as an argument. Compile / Run .. when you click the button the image changes and mouse- rollover no longer works
How do you accomplish this Assignment?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
