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

How to know which button being clicked?  RSS feed

 
ethaniel landfough
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also post my problem in dreamincode.net and stackoverflow but haven't get my problem solved. I'm trying to make N x N grid of JButton with one JTextField in the below where we can input character there then clicked on any of the white button to make the input show up on the button that being clicked. Is there a way to make it like that ( to make it recognize which button being clicked and get the input show up on it)? Thank's...
Because what i have achieved now is any button i clicked, the input will show in the last button being created not in the button that being clicked.

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


note: there's already a Swing class called Box
 
ethaniel landfough
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:

note: there's already a Swing class called Box


Michael Dunn wrote:

note: there's already a Swing class called Box


Thanks.... I really forgot that i can use it like that. Any idea on how to make it so it wouldn't get error message on the back when the button being clicked but no input in the JTextField?? I make it like this, but still got error at the back..


Here is the error that i got :



 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
firstly test whether the textfield is empty.
if so, display an info message
else, proceed with the rest of the method
 
ethaniel landfough
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:firstly test whether the textfield is empty.
if so, display an info message
else, proceed with the rest of the method


Ok.. I think use the wrong thing (==) for the string comparison. I changed it to and it works fine.. :D

What the differrent of using


Or


as for checking if JTextField is empty or not??

And if i want to check the JButton color first, is it possible? So, just the white button colored that show the input. I know using BLACK color is already enough to make the input can't be seen, but not if i change it to yellow.. Something like this maybe??
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> And if i want to check the JButton color first, is it possible?

is there anything preventing you from trying it?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!