Results 1 to 2 of 2
  1. #1
    scottsational is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Angry Switching images based on a list or actionlistener

    It was in the code, I am trying to display different images depending on which item is highlighted in a list. I will settle for a button used to collect the SelectedIndex(); but that did not work either. I want four different images to show up in the same place on different actions.

    PHP Code:
     
    
     public void init() {
    
            if(r==i1)
            {
                //switch on selection
                img=this.getImage(this.getCodeBase(), "socks.jpg");
            }
    
            else if(r==i2)
            {
                img=this.getImage(this.getCodeBase(), "shoes.jpg");
            }
            else if(r==i3)
            {
                img=this.getImage(this.getCodeBase(), "pants.jpg");
            }
            else if(r==i4)
            {
                img=this.getImage(this.getCodeBase(), "bike.jpg");
    
            }
    }
    
      public void actionPerformed(ActionEvent e) {
    
            
            
            if(e.getSource()==btndisp)
            {
                lst1.add("Sucess!");
                r=lst1.getSelectedItem();
                lst1.add(r);
                
    
                //this simply won't display
                img=this.getImage(this.getCodeBase(), "socks.jpg");
                
                
                    
                lst1.add(r);
            }
    }
    
    public void paint(Graphics g)
        {
            g.drawImage(img,220,140,120,100,this);
        }
        
        public void update(Graphics gg)
    {
        paint(gg);
    }
    
    }
    Last edited by scottsational; 01-30-2013 at 05:44 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Trying to get a list that goes on to show images
    By ciara in forum CLDC and MIDP
    Replies: 4
    Last Post: 12-05-2012, 07:26 PM
  2. Text matching based on a list/array ?
    By jtzako in forum New To Java
    Replies: 2
    Last Post: 08-31-2012, 10:47 AM
  3. populating a list box based on another without refreshing the page
    By zahir in forum JavaServer Pages (JSP) and JSTL
    Replies: 8
    Last Post: 07-25-2011, 02:09 PM
  4. Replies: 0
    Last Post: 11-05-2010, 10:35 AM
  5. Replies: 0
    Last Post: 03-25-2008, 01:45 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •