Results 1 to 2 of 2
  1. #1
    attiej is offline Member
    Join Date
    Oct 2012
    Rep Power

    Question actionevent e.getsource() with multiple input options


    I am trying to create a decent looking solution for a problem I have. I can explain in words, but the code will be clearer:

    Java Code:
    public void actionPerformed(ActionEvent e) {		
    		if(e.getSource().equals(ClassA.getButtonOne()) || 
    			e.getSource().equals(ClassB.getButtonOne())) {			
    			???????.setEnabled(false);			(class a or class b)
    Explanation: How can I change e.getSource() into the right class type, so I can perform methods on it? One extra detail: I am sure all methods in the if-statement possess the method I want to excecute, in the example above 'setEnabled'. I can solve the problem by creating multiple if-statements, but that would create duplicate code (especially since there will also be a class C and D in the future) .

    Thanks in advance

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Washington, DC
    Rep Power

    Default Re: actionevent e.getsource() with multiple input options

    You have to cast it. Something like this:

    Java Code:
    Object o = new String("test");
    String s = ((String)o).substring(0,2);
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

Similar Threads

  1. multiple Data from Jsp that having same name of multiple input tage to servlet
    By in forum Advanced Java
    Replies: 0
    Last Post: 07-29-2011, 01:00 PM
  2. Getsource() ?
    By HearT.Hunt3r in forum New To Java
    Replies: 4
    Last Post: 07-28-2011, 06:28 PM
  3. Jcombobox not liking String input for options :|
    By skatefreak in forum New To Java
    Replies: 4
    Last Post: 05-11-2009, 12:34 PM
  4. Getsource()
    By mrark in forum New To Java
    Replies: 1
    Last Post: 06-27-2007, 04:46 PM

Posting Permissions

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