• 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

Finding pixel colour

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic