Java itemListener question

Discussion in 'OT Technology' started by [DWI], Sep 19, 2003.

  1. [DWI]

    [DWI] Master of Nothing

    Joined:
    Aug 6, 2000
    Messages:
    21,936
    Likes Received:
    0
    Location:
    Maine
    when you have several itemlisteners (lets say you have a couple choices) what does the code look like to set up a different routines for each choice? I've only worked with single choices in a layour before. Thx
     
  2. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    In your listener method, check the source object. If it came from a certain object then execute certain code. That's what I always do for any event.

    Code:
    public void actionPerformed(ActionEvent event)
    {
      if(event.getSource().equals(timer))
      {
    	// do something
      }
      else if(event.getSource().equals(createSubmit))
      {
    	// do something else
      }
    }
    
     

Share This Page