Results 1 to 4 of 4
  1. #1
    shall is offline Senior Member
    Join Date
    Apr 2012
    Posts
    199
    Rep Power
    0

    Default How to change image layer property

    Hello,

    I created a puzzle in gimp with each of the pieces contained on a different layer. I exported the pieces to individual files and wrote a java program to assemble and move those pieces. When I move the puzzle pieces, I notice that some of the pieces move on top of other pieces while other pieces move behind. I think the reason for this is because I created the pieces on different layers.

    How can I make it so that all pieces move on top of each other.

    Thanks,
    Stephen
    Last edited by shall; 05-31-2012 at 05:26 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: How to change image layer property

    Haven't a clue. You haven't so much as indicated which GUI toolkit is involved.

    To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: How to change image layer property

    Are you saying that when a piece is moved its layer should be changed to be on top of all the others?
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    shall is offline Senior Member
    Join Date
    Apr 2012
    Posts
    199
    Rep Power
    0

    Default Re: How to change image layer property

    Quote Originally Posted by Norm View Post
    Are you saying that when a piece is moved its layer should be changed to be on top of all the others?
    Yes,

    See the code below for a SSCCE.

    puzzlePieceImage2 overlaps puzzlePieceImage1. How can I make it so puzzlePieceImage1 overlaps puzzlePieceImage2.

    I wasn't able to attached a zip file which contains the code and images. I clicked on manage attachments and a blank window appeared. Is there something wrong with the forum's attachment functionality?

    Java Code:
    package imagelayerex;
    
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.net.URI;
    import java.net.URISyntaxException;
    import java.net.URL;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.imageio.ImageIO;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    
    public class ImageLayerEx {
    
        private void createGUI() throws URISyntaxException, IOException {
            JFrame puzzleFrame = new JFrame();
    
            puzzleFrame.setPreferredSize(new Dimension(800, 800));
    
            PuzzlePanel puzzlePanel = new PuzzlePanel();
    
            puzzlePanel.setPreferredSize(new Dimension(800, 800));
    
            puzzleFrame.add(puzzlePanel);
    
            puzzleFrame.pack();
    
            puzzleFrame.setVisible(true);
        }
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) throws URISyntaxException, IOException {
    
            final ImageLayerEx imgLayerEx = new ImageLayerEx();
    
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    try {
                        imgLayerEx.createGUI();
                    } catch (URISyntaxException ex) {
                        Logger.getLogger(ImageLayerEx.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (IOException ex) {
                        Logger.getLogger(ImageLayerEx.class.getName()).log(Level.SEVERE, null, ex);
                    }
    
                }
            });
        }
    }
    
    class PuzzlePanel extends JPanel {
    
        private BufferedImage puzzlePieceImage1;
        private BufferedImage puzzlePieceImage2;
    
        public PuzzlePanel() throws URISyntaxException, IOException {
            
            loadPuzzlePieces();
        }
    
        private void loadPuzzlePieces() throws URISyntaxException, IOException {
    
            URL imageURL = this.getClass().getResource("PuzzlePieces");
    
            URI imageURI = imageURL.toURI();
    
            File puzzelPiecesImageDirectory = new File(imageURI);
    
            File[] listOfFiles = puzzelPiecesImageDirectory.listFiles();
    
            puzzlePieceImage1 = ImageIO.read(listOfFiles[0]);
            puzzlePieceImage2 = ImageIO.read(listOfFiles[1]);
        }
    
        @Override
        public void paintComponent(Graphics g) {
    
            g.drawImage(puzzlePieceImage1, 400, 400, this);
            g.drawImage(puzzlePieceImage2, 450, 450, this);
        }
    }

Similar Threads

  1. Layer customizing
    By atrodeyo in forum New To Java
    Replies: 4
    Last Post: 04-24-2012, 05:02 AM
  2. Geomajas WMS layer 1.9.0
    By java software in forum Java Software
    Replies: 0
    Last Post: 02-05-2012, 06:21 PM
  3. Replies: 0
    Last Post: 09-23-2010, 06:47 PM
  4. Transparent layer
    By disabled in forum SWT / JFace
    Replies: 0
    Last Post: 03-20-2010, 04:04 PM
  5. Replies: 0
    Last Post: 06-25-2009, 05:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •