Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Immage needs help

Reply
Thread Tools

Immage needs help

 
 
shoa
Guest
Posts: n/a
 
      07-08-2003
Hello all

In the panel I want to display an image on it in one state and no image in
another state:

class MyPanel extends JPanel {
Image logo;
public MyPanel (){

logo = Toolkit.getDefaultToolkit().getImage("logo.gif");
}

public void paint(Graphics g){
if (getCurrentState() == -1) //state one , display image
g.drawImage(logo,0,0,this.getWidth(), this.getHeight(),
this);
else if (getCurrentState()==0) //state two, display this
panel with cyan color
{g.setColor(Color.cyan);
g.drawRect(0,0, this.getWidth(), this.getHeight());
}

}
}

Then I inset this panel to a frame and have a button. From this button, I
set the currentState to -1 and 0 and call the function myPanel.repaint();

However, myPanel does not change when I press the button. The myPanel only
changes the Image when I hide and show again the frame (by clicking minimum
and maximum button).
Could you please help
thank you
S.Hoa



 
Reply With Quote
 
 
 
 
Ike
Guest
Posts: n/a
 
      07-08-2003
you need to use:

public void paintComponent(Graphics g){
super.paintComponent(g);
.. . .//your code from paint() here
} //-Ike

"shoa" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello all
>
> In the panel I want to display an image on it in one state and no image in
> another state:
>
> class MyPanel extends JPanel {
> Image logo;
> public MyPanel (){
>
> logo = Toolkit.getDefaultToolkit().getImage("logo.gif");
> }
>
> public void paint(Graphics g){
> if (getCurrentState() == -1) //state one , display image
> g.drawImage(logo,0,0,this.getWidth(),

this.getHeight(),
> this);
> else if (getCurrentState()==0) //state two, display this
> panel with cyan color
> {g.setColor(Color.cyan);
> g.drawRect(0,0, this.getWidth(), this.getHeight());
> }
>
> }
> }
>
> Then I inset this panel to a frame and have a button. From this button, I
> set the currentState to -1 and 0 and call the function myPanel.repaint();
>
> However, myPanel does not change when I press the button. The myPanel only
> changes the Image when I hide and show again the frame (by clicking

minimum
> and maximum button).
> Could you please help
> thank you
> S.Hoa
>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get texture immage path from Appearance ricvec Java 6 08-08-2007 12:20 PM
Please Help!!Daughter needs help with java code Miggy23@gmail.com Java 43 12-09-2005 04:31 PM
Help idiot needs help setting up Linksys wag54g wireless network Ronnie Wireless Networking 2 03-28-2005 08:32 PM
immage in datalist =?Utf-8?B?bWFoc2E=?= ASP .Net 2 05-03-2004 04:01 AM
HELP! SA guy needs security help Win98se JohnF Computer Support 5 12-25-2003 02:58 PM



Advertisments