This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

mouseReleased() problem  RSS feed

 
willie tin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I need some help here. I'm working on a GUI for a chess game.
I've created a JPanel for the board, and Cell extends JLabel for the cells.
With mousePressed:
I identify the original Cell using evt.getComponent().
Then remove Piece from the Cell
With mouseReleased:
I identify the target Cell.
Then place Piece in this Cell.
The problem is that I'm not able to identify the target cell withi mouseReleased(). Any ideas? Sorry if this is such a silly question.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(untested)

perhaps you could use a MouseMotionListener's mouseDragged to continually
update what the component at x,y is
class variable
JLabel label;

in mouseDragged()
Point pt = new Point(me.getX(),me.getY());
label = (JLabel)p.getComponentAt(pt);

in mouseReleased()
label.doSomething()
 
willie tin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, resolved now.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!