• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using getIcon

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I creating new buttons using btn[a]=new JButton (image1) where image1 has been defined as an icon using ImageIcon image1=new ImageIcon ("test1.gif").
I would like to be able to retrieve the icon type from the button when pressed but this doesn't seem to work:

public void actionPerformed (ActionEvent e)
if (e.getSource()=btn[1] && btn[1].getIcon<>"image1"){
do this
}

Any help/suggestions would be appreciated.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your syntax isn't exactly Java -- for example using <> for !=, but anyway, you are first doing a case analysis on the source of the action event, then you want to do a case analysis on the current icon for the source? If that state isn't held elsewhere in a cleaner form you can always do this:

By the way, it also may be cleaner to have separate listeners for each button.
 
Larry Reynolds
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the great help! I guess my BASIC background shows through.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic