• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to know which button being clicked?

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic