S
shoa
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
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