Welcome to Dream.In.Code
Become a Java Expert!

Join 149,598 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,897 people online right now. Registration is fast and FREE... Join Now!




displaying randomly sorted images

 
Reply to this topicStart new topic

displaying randomly sorted images

cloud2181
7 Oct, 2007 - 01:26 PM
Post #1

New D.I.C Head
*

Joined: 11 Feb, 2005
Posts: 24


My Contributions
hey all currently i'm working on a program that cuts an image into pieces and randomly displays them in another frame. the problem that i'm running into is that when it displays the picture again it's not displaying it random at all. here is a copy of the code


CODE

class MyPanel extends JPanel
    {
        Random gen = new Random();
        int ran = gen.nextInt(cut_number);
        public MyPanel(BufferedImage image[], int col, int row)
        {
            
        System.out.println(ran);
        JPanel panel = new JPanel();
        GridLayout layout = new GridLayout(row , col);
        panel.setLayout(layout);
        panel.setSize(split.getWidth(), split.getHeight());
        }
        
        public void paintComponent(Graphics g){
            for (int x = 0; x < splitArr.length; x++)
                for(int y = 0; y < splitArr.length; y++)
            g.drawImage(splitArr[ran], x,y,(ImageObserver) this);
        }
        
    }


any ideas would be appreciated smile.gif
User is offlineProfile CardPM
+Quote Post

razel
RE: Displaying Randomly Sorted Images
7 Oct, 2007 - 02:32 PM
Post #2

New D.I.C Head
*

Joined: 7 Oct, 2007
Posts: 1


My Contributions
QUOTE(cloud2181 @ 7 Oct, 2007 - 02:26 PM) *

hey all currently i'm working on a program that cuts an image into pieces and randomly displays them in another frame. the problem that i'm running into is that when it displays the picture again it's not displaying it random at all. here is a copy of the code


CODE

class MyPanel extends JPanel
    {
        Random gen = new Random();
        int ran = gen.nextInt(cut_number);
        public MyPanel(BufferedImage image[], int col, int row)
        {
            
        System.out.println(ran);
        JPanel panel = new JPanel();
        GridLayout layout = new GridLayout(row , col);
        panel.setLayout(layout);
        panel.setSize(split.getWidth(), split.getHeight());
        }
        
        public void paintComponent(Graphics g){
            for (int x = 0; x < splitArr.length; x++)
                for(int y = 0; y < splitArr.length; y++)
            g.drawImage(splitArr[ran], x,y,(ImageObserver) this);
        }
        
    }


any ideas would be appreciated smile.gif


Try Updating the value of ran, from where I can see, it is never changed. Try updating it inside your second for loop.

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:36PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month