Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Superimposing image with grid

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,
I have a problem.I want to superimpose an image on a grid.Pleas help me how to build a grid with constant width and height and grid cells with constant size.When I superimpose an image on this grid it should be devided into cells.When I click at the intersection of cells on this image grid I should be able to catch the position that is x,y coordinates.
I want to use a Jpanel in the JFrame as container for this image grid.
Can anyone help me in solving this problem.

Nageswara Rao K.S.
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can do this... But your explaination really needs to be more specific... Do you need to actually split the image into smaller pieces? Do you just need to draw the grid on top of the image? Do you just need to capture the coordinates? Do you need to capture something in addition to the coordinates ( like the piece of the image that is at this coordinate )? Answers to these questions would help us to know what you really need this thing to do...

Here are some pointers that may help you with what you have described so far...

Subclass Canvas... give it an Image attribute, and some attributes to control the grid, let's say gridWidth, gridHeight, gridX, and GridY... make methods to get and set the Image and the grid attributes... override the getPreferredSize() method to make it the correct size in the GUI... in the paint() method draw the Image, then use the drawLine() method in Graphics to draw the grid, using the grid attributes you have set before. Add a mouseListener to the component. Let this mouseListener test if it is on a grid intersection, if it is, call a method that does whatever you need with the current mouse coordinates. The above assumes that all you need to do is capture the coordinates. It would be much more difficult to actually cut the image into parts ( but still possible to do ), but you did not specify if you needed to do this or not... If you do I will try to help you out with that problem too...

nageswara rao
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your suggestion.
But I don't want to create a new image.I want to superimpose an existing image on a grid structure.If you mean it as splitting the image into cells I want the same.
Nageswara rao
If tomatoes are a fruit, then ketchup must be a jam. Taste this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic