posted 7 years ago
Im doing something wrong here, i think my problem its at the step " Initialize the field clickImage with a new ImageIcon that is based on Image3". My understanding is that the constructor does the initialization, so after i create
the constructor, i cant go outside of it and say field = new object... , i tried to initialize inside of the constructor but i got errors. The instructions do not say anything about initializing the fields on the ctor, it only says to change the tittle. So i also tried not initializing the fields on the ctor, and initializing at the same time as the fields are declared but it doesn't like this approach either. Can i get a hint about how to resolve this.
1- Create two final fields: imgButton of type JButton clickImage of type Icon
2- In the constructor do the following:
3- Set the title to Lab Button
4- Create two local variables of type Icon: image1 and image2.
5- Initialize them with a new ImageIcon base on Image1 and Image2 - like this:
Icon image1 = new ImageIcon(getClass().getResource("Image1.png"));
6- Initialize the field clickImage with a new ImageIcon that is based on Image3
7- Initialize the field imgButton with a new JButton that accepts image1 as the only argument
8- Call the method setRolloverIcon on imgButton and pass image2 as roll-over icon
9- Add the imgButton to this (ImageButton, which is a JFrame)