Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Using JButtons in J++?

Using JButtons in J++?

Using JButtons in J++?


Recently I was going to attempt to make a type of checkers game in Java.  This is a rather "ambitious" project for me, but I felt it was with in my possibilities.  I started by creating a board, using the rect.drawRect(x, y, height, width) command, and managed through a simple loop to come up with a nice checker board.  However, I could not for the life of me figure out how to create an active listener for where the mouse lands.  

SO, I wanted to use JButtons instead, I remembered that JButtons have the SetIcon command, and assumed J++ would have an easy way to select that icon (Black Square, Black Square with piece, White Square).  However, I have not been able to figure out how to add JButtons/panels to my project, any help would be VERY appreciated.  I've searched for a few hours on this already.


RE: Using JButtons in J++?

You can't use JButtons unless you've got swing.  Unfortunately, due to rather acrimonious disputes between Microsoft and Sun, the only way to get swing is to download it from http://www.java.sun.com.  Odly, the latest jdk also comes without swing.  I don't quite know how to get hold of it, although I'm trying.  It comes as part of the javax package, which must be a separate download.  I'll post again if I find it.  
On the mouselistener front, use the e.getX() and e.getY() to get the position of the mouse cursor, and have an array of points which are the top left-hand corner of each square, and use this in a for loop to work out which sqsuare was hit.  
Hope this helps,

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close