Skip to content
Advertisement

Why is my image not being added? JavaSwing

I made this program, assume I have an extra src folder in my buildpath with the monkiflipppp.gif there. It just runs and has a button, but the button won’t actually do anything… Not sure if I need to add a specific method to the constructor. Essentially I just want the monkiflippp gif to post in different locations every time I click the button.

JavaScript

Here’s my driver in case you’re curious.

JavaScript

Advertisement

Answer

monkiFlipImage is not initialized, simply put you aren’t loading the gif. (monkiFlipImage = ImageIO.read(getClass().getResource("/monkiflipppp.gif"));) You forgot to use addsMonki at all.

I tested your code by adding addsMonki at the first line of the constructor (public addMonki() {) and it works just fine.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement