Results 1 to 2 of 2
- 10-22-2012, 10:50 AM #1
Member
- Join Date
- Oct 2012
- Posts
- 1
- Rep Power
- 0
actionevent e.getsource() with multiple input options
Hi,
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:
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) .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) }
Thanks in advance
- 10-22-2012, 03:38 PM #2
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 - Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads
-
multiple Data from Jsp that having same name of multiple input tage to servlet
By rahul9323.2007@gmail.com in forum Advanced JavaReplies: 0Last Post: 07-29-2011, 01:00 PM -
Getsource() ?
By HearT.Hunt3r in forum New To JavaReplies: 4Last Post: 07-28-2011, 06:28 PM -
Jcombobox not liking String input for options :|
By skatefreak in forum New To JavaReplies: 4Last Post: 05-11-2009, 12:34 PM -
Getsource()
By mrark in forum New To JavaReplies: 1Last Post: 06-27-2007, 04:46 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks