> I am trying to display an image by clicking a button.
> Can anyone tell me what is wrong with my code that it doesnt work.
> public void actionPerformed(ActionEvent ae)
> {
> System.out.println("Button Pressed");
> try
> {
> image = Toolkit.getDefaultToolkit().getImage("1.gif");
Add "repaint();" right here, it might work.
> }
> catch(NullPointerException e)
> {
> }
> }
Better, load the image in your constructor (this way there won't be a
loading delay when the button is pushed). Then use a boolean flag to
determine whether or not the button has been pushed. Make sure you
repaint() after changing the flag.