Immage needs help

Discussion in 'Java' started by shoa, Jul 8, 2003.

  1. shoa

    shoa Guest

    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
     
    shoa, Jul 8, 2003
    #1
    1. Advertising

  2. shoa

    Ike Guest

    you need to use:

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

    "shoa" <> wrote in message
    news:...
    > 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
    >
    >
    >
    >
     
    Ike, Jul 8, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. thomas

    new to VHDL needs help

    thomas, Jun 9, 2005, in forum: VHDL
    Replies:
    2
    Views:
    582
    thomas
    Jun 9, 2005
  2. =?Utf-8?B?bWFoc2E=?=

    immage in datalist

    =?Utf-8?B?bWFoc2E=?=, May 2, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    369
    =?Utf-8?B?bWFoc2E=?=
    May 3, 2004
  3. Replies:
    43
    Views:
    1,346
    Oliver Wong
    Dec 9, 2005
  4. ricvec
    Replies:
    6
    Views:
    327
  5. Zayd Connor
    Replies:
    8
    Views:
    123
    Zayd Connor
    Apr 6, 2009
Loading...

Share This Page