wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Finding pixel colour Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Finding pixel colour" Watch "Finding pixel colour" New topic
Author

Finding pixel colour

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Hi, I've built a mini rubiks cube, but to spin it, you can click anywhere and drag it and to twist it you have to use the JButtons below:
Rubiks Cube
I would like it so... if you press the mouse on an area OUTSIDE of the cube, you can SPIN, and pressing the mouse on an area INSIDE the cube lets you twist(thereby replacing the JButtons).

Instead of using more mathematics to determine if the mouse pointer is outside the cube, is it possible to grab the colour of the pixel at the point where the mouse is pressed?
I know with BuffferedImages you can use getRGB(), but this is just a JPanel with a stuff drawn into it.
Basically, if the colour grabbed is the same as the background colour, then its outside of the cube.

Can anyone help? Thanks very much.
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
I suspect it would be better to design your GUI such that it could support easily determining this mathematically. Regardless, here's one approach that might work though I really despise it:

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Thats interesting, I didn't know you could use 'final' on method arguments and variables too. I guess it makes sense though to allow this.
But obviously arguments or local variables couldn't be static or public or private etc.

I have found another solution by chance.
I needed to know if a shape contains a point, and to my amazement there is a java class called Shape with the methods contain(Point p), contain(x,y) which do the job perfectly.

Thats what I like about java, sometimes its a pain, but others its really helpful.

Thanks for your solution, I'll take a look at it, I could learn from it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Finding pixel colour