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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reworded image tiling question

Status
Not open for further replies.

jmycr

Programmer
Mar 11, 2002
48
0
0
US
I know that this is the third thread that I have made for this, but I thought maybe I could word it better to give people a better understanding of what I am looking for. I was way too wordy before. My apologies.

I have a .gif image of a black and white outline of a tree.
I also have an image of a leaf.

I am looking to allow the user to click on the leaf and then click on the tree and have the leaf just tile onto the tree.

thank u for any responses.
 
If I understand well, you want to do a kind of drag-drop of an image over another one exept that you don't use the drag-n-drop itself but a kind of "state programing" that kind :


INITIAL STATE
|
click on leaf event
|
V
LEAF SELECTED STATE
| |
click on tree event click elsewhere
| |
V V
COPY LEAF TO TREE INITIAL STATE
|
done
|
V
INITIAL STATE

Where "COPY LEAF TO TREE" creates a new Component over the tree image that is filled with leaf image.
Is that what you want to do ?

Water is not bad as long as it remains outside human body ;-)
 
Exactly.

I would like for the leaf to tile over the tree and fill the tree with leaves. Not the entire image that the tree is one. Just inside the tree.

It has a white background with maybe some other things in there; like bushes or things like that but would only tile in where ever the user clicks.

Much like a color fill.

thanx for the quick response.
 
One question more : when clicking on the tree (after leaf select) do you want to paint just one leaf at the position clicked on the tree or do you want to paint many leaves and if so, how many leaves and at what position on the tree ?

Water is not bad as long as it remains outside human body ;-)
 
many leaves with one click until that area is full of leaves.

I hope I am making sence. lol
 
You should use a panel with a specifical "paint" method for your tree. something that should look like this :
Code:
public class ImagePanel extends JPanel {

    private Image image = null;
    public ImagePanel(Image pImage) {
        image = pImage;
    }
    
    public void paint(Graphics g) {
        g.drawImage(image,0,0, g.getColor(), this);
    }
}
Create your tree as an ImagePanel giving it your tree image and with no specific layout.
When you want to copy the leaves, create as many ImagePanel with leaf image as needed and add them to the tree ImagePanel.

Water is not bad as long as it remains outside human body ;-)
 
will the code that u supplied do this?

I am very new to jave.

Sorry for my ignorance and thank u for your reply.
 
What my code will do is to create a new kind of Jpanel with an image as background. You'll then have to code the creation of one of these panels to show your tree and one for each leaf to add using for example a new inheritance for tree like this :
Code:
public class TreeImagePanel extends ImagePanel {

//  change this value depending on your tree and leaf images sizes.
    public static int MAX_LEAVES = 30; 

    public TreeImagePanel(Image pImage) {
        super(pImage);
    }

    public void setLeafImage(Image pImage) {
        // Clear old leaves
        this.removeAll();
        // add new leaves
        for (int i=0; i<MAX_LEAVES; i++) {
            ImagePanel lLeavePanel = new ImagePanel(pImage);
            this.add(lLeavePanel);
        }
    }
}

Now, in France, it's time for week-end so try to code with that and if you can't achieve, I'll be back on Monday...

Water is not bad as long as it remains outside human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top