• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using getIcon

 
Larry Reynolds
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the great help! I guess my BASIC background shows through.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic