Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Harry Hunter   on Jun 19 In Java Category.

  
Question Answered By: Freya Brown   on Jun 19

> 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.

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on awt help required Or get search suggestion and latest updates.


Tagged: