The Artima Developer Community
Sponsored Link

Java Answers Forum
how to display the picture when the filename is not in order

6 replies on 1 page. Most recent reply: Jun 9, 2008 7:48 PM by norazanita adnan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
norazanita adnan

Posts: 6
Nickname: norazanita
Registered: Jun, 2008

how to display the picture when the filename is not in order Posted: Jun 5, 2008 7:41 PM
Reply to this message Reply
Advertisement
hi..anyone help me on this,

in my picture file, i have a list of image and some of the filename is missing ( or been deleted already)
0001.gif
0002.gif
0010.gif
1001.gif
9800.gif
9999.gif

now i would like to display .I use the JLabel as the container to display my picture and the picture set as ImageIcon.

i can veiw when i press the "next" and " previous" button if the picture file in sequence which is
0001.gif
0002.gif
0003.gif
0004.gif
0005.gif
0006.gif

as i can access using this code


code:
------------------------------------------------------------------ --------------

for (int i = 1; i <= TOTAL_NUMBER_OF_IMAGES; i++) { imageIcon = new ImageIcon("/image/flag" + i + ".gif"); }

----------------------------------------------------------------------------- ---

can someone give me some idea how to show when i click the "next" and "previous" it still show the image when the filename is not in order as above .

thanks...


Rajeev Mutalik

Posts: 57
Nickname: rajmutalik
Registered: Sep, 2002

Re: how to display the picture when the filename is not in order Posted: Jun 5, 2008 11:17 PM
Reply to this message Reply
Store the names of files is any file and read those values one-by-one into array or array list. And then use them to navigate. This way u will display the files in the order in which they are stored in the file.

ImageFile.txt
1.gif
5.gif
4.gif
21.gif
10.gif


Algorithm:

1. Read from file
2. Store all the values in arraylist
3. Read from the array list and display the image file.

Regards,
Rajeev

norazanita adnan

Posts: 6
Nickname: norazanita
Registered: Jun, 2008

Re: how to display the picture when the filename is not in order Posted: Jun 5, 2008 11:53 PM
Reply to this message Reply
im so new in Java...im sorry if im wrong but...why do i have to store the name of the file in the ImageFile.txt? all the image 1.gif ,5.gif , 4.gif ,21.gif, 10.gif been palce in a folder an lets name the folder as MyImage.

Now i have to display all the images in the JLabel when an action been perform ( "Next" or "Previous" been hit and it show one by one).

Can you help me to give some codes snippets to the Algorithm u suggested..

im a java beginners...im not that good in java programming...

Thanks....

Rajeev Mutalik

Posts: 57
Nickname: rajmutalik
Registered: Sep, 2002

Re: how to display the picture when the filename is not in order Posted: Jun 8, 2008 6:11 AM
Reply to this message Reply
Try it out, by urself. Canoot write code for u. Can help u in case u r stuck somewhere.

norazanita adnan

Posts: 6
Nickname: norazanita
Registered: Jun, 2008

Re: how to display the picture when the filename is not in order Posted: Jun 8, 2008 5:37 PM
Reply to this message Reply
problem is..i dont know how to start... :)

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: how to display the picture when the filename is not in order Posted: Jun 9, 2008 4:34 AM
Reply to this message Reply
    //  Code from Java almanac
    private List<String> getFilesAvailable(String directoryName) {
        File dir = ;
        File[] files = dir.listFiles();
        // This filter only returns directories
        FileFilter fileFilter = new FileFilter() {
            public boolean accept(File file) {
                return file.isDirectory();
            }
        };
        List<String> filesAvailable = new ArrayList<String>();
        //  Assuming this is Java 5
        for (File file: new File(directoryName).listFiles(fileFilter);) {
            if (file.getAbsolutePath().contains("image") && file.getAbsolutePath().contains("what_ever_else_you_want")) {
                filesAvailable.add(file.getAbsolutePath());
            }
        }
        return filesAvailable;
    }
 
    //  This is where you use it
    //  You may want to sort it (not quite sure of the nature of your assignment:
    List<String> myListOfFiles = getFilesAvailable("/image/flag/");
    Collections.sort(myListOfFiles);
    ImageIcon [] images = new ImageIcon[myListOfFiles.size();
    int index = 0;
    for (String myFile : myListOfFiles) { 
        imageIcon[index] = new ImageIcon(myFile);
        index++;
    }
 


-----------------------------------------------------------
> ---------------------
>
> for (int i = 1; i <= TOTAL_NUMBER_OF_IMAGES; i++) {
> ) { imageIcon = new ImageIcon("/image/flag" + i +
> ".gif"); }
>
> -----------------------------------------------------------
> ---------------------
>
> can someone give me some idea how to show when i click the
> "next" and "previous" it still show the image when the
> filename is not in order as above .
>
> thanks...

norazanita adnan

Posts: 6
Nickname: norazanita
Registered: Jun, 2008

Re: how to display the picture when the filename is not in order Posted: Jun 9, 2008 7:48 PM
Reply to this message Reply
thanks..it really help me so much...
thanks once again...

Flat View: This topic has 6 replies on 1 page
Topic: java code for replacement algorithm in proxy server Previous Topic   Next Topic Topic: SQL server connecting problem

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use