Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Images in objects

Status
Not open for further replies.

Chrissirhc

Programmer
May 20, 2000
926
GB
Can anyone help?

I am guessing there is a way to wrap an image into an object. And then change the size of the image by changing the size of the object using some set method. What class does this?.

I then want to be able to drag these image objects onto a grid or something where I can drop the image into a region and it will snap to the nearest square in the grid. The grid would be invisible. Does anyone know how to do this?.

Thanks

Chris [sig][/sig]
 
You could possible do this by seperating the GUI into seperate frames, when you allocate an Image object it would be individual to the specific frame. I don't remember the code off hand, i would have to look it up....

later [sig]<p>ackka<br><a href=mailto:tmoses@iname.com>tmoses@iname.com</a><br><a href= my site</a><br>"Do No Harm, Leave No Tracks"<br>
ICMP Summer 2000, 2600 Article<br>
<br>
[/sig]
 
I don't know but that doesn't sound too right excuse my ignorance if it is. Wouldn't you see the frame around the object. I was thinking more imageIcon but figured that thats wrong. What I want to do is take a round blob (say), and put it onto a white background a few times. But I must be able to pick up this blob and move it. Also the blob can only go in specific areas of the canvas which I am drawing on. I want to create lots of predefined areas where these blobs can go. [sig][/sig]
 
There's an applet at


that involves dragging images into an invisible grid area. This may not be close enough to what you are trying to do. If it is of any use, however, the source is at the bottom of this page:


Also that guy is using the older event api instead of the newer which implements the MouseListener interface.

If you wanted to get fancier you could make each image a component using the Component.Canvas class. However, to do this, you have to subclass Canvas and then use the inherited paint method within Canvas. However, the image would have to be passed to each Canvas instance from the Frame or Applet class.

This has the advantage that you can set a member field to a value for tracking purposes then retrieve information from each Canvas instance for tracking purposes using the Reflect class methods.

As to changing the size of the image, if you are using a Graphics object to display the image, there are various versions of the class method drawImage. You could use:

drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)

Which would allow you to change the size of the image depending on, say, a boolean you set in your mouse event listener method.

I hope I'm understanding what you're asking.
[sig]<p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br> [/sig]
 
Thanks I don't really have clue of reflection classes and some of the stuff you have said but I will try to find some information on them. i guess I just need to decide what kind of object I want to use to put the image in. And see what kind of objects you can drag and drop onto canvas's.

Chris [sig][/sig]
 
What I've found works is making an imageIcon
[tt]new ImageIcon(<relative path to image>)[/tt]
an then adding it to a JLabel which you can then set the size of eg;
[tt]
JLabel l = new JLabel(new ImageIcon(pics/bigpic.gif));
l.setPreferredSize(new Dimension(500,500));
[/tt]
this works for gifs and jpegs centering the image i haven't actually tried good luck
X-) [sig]<p>Chris Packham<br><a href=mailto:kriz@i4free.co.nz>kriz@i4free.co.nz</a><br><a href= > </a><br>A thousand mokeys at a thousand machines, it happened, it got called the internet.[/sig]
 

Okay thanks that sounds okay.
Thanks if there are any other ideas like this that would be good. [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top