Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

converting an object to a specific component?  RSS feed

 
Paul Chamsay
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have this GUI app that I'm working on right now and I'm wondering if it's possible to convert an object from the method e.getSource() to a JButton? I need something like a getText() method to get the text of a button ..

It's actually something like a keypad that I'm working on ..

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, getSource() returns the object that called the event. You just have to cast it.

final JButton button = (JButton)e.getSource();
 
Paul Chamsay
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Duh!

Thanks Gregg, that got the program done.
 
Campbell Ritchie
Sheriff
Posts: 53774
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why have you got all those if statements? Can't you get the text from the JButton and append it to the password directly? And why are you using == for comparing reference types?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!