Java Guru's ? I Need A Little Help.

DY357LXDY357LX Playing since day 1. Still can't Comm.England Join Date: 2002-10-27 Member: 1651Members, Constellation
<div class="IPBDescription">Going Forward By One File? Hmm.</div> I've been roped into learning a little Java on this course i'm doing
(only 7 weeks left, yay!) and i've been struggling to think of something
decent to code. ( <a href='http://homepage.ntlworld.com/pete.taylor2/docs/java/apps.html' target='_blank'>Seriously</a> )

But last night I had an idea of something I actually want to code, and
as a bonus, it might actually be useful!

What I want to create is an applet which displays an image in the middle
and 2 buttons (could be 1) that goes to the next/previous image.

Now I can figure out how to display images and how to display buttons
and make a button go to the next image but the button code actually
contains the next image name. I.E it'll go to a set image name, but I want
it to go the next image in the folder. Ala *.jpg.

Is this possible, if so how?

I'm not sure if my idea has been explained clearly here, if not, simply
say so and i'll try and clear it up.

Comments

  • SkulkBaitSkulkBait Join Date: 2003-02-11 Member: 13423Members
    edited March 2005
    Well, I have to look through the Java API to find the specific methods, but basically what you'll be doing is creating an array of strings that contains the image filenames. You'll generate the aray using a method that lists the contents of a folder.

    Edit:
    Ok, looked up the nessesary method, and it even came with a bit of code to make my job even easier:

    <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1--> File dir = new File("directoryName");
       
       String[] children = dir.list();
       if (children == null) {
           // Either dir does not exist or is not a directory
       } else {
           for (int i=0; i<children.length; i++) {
               // Get filename of file or directory
               String filename = children[i];
           }
       }
       
       // It is also possible to filter the list of returned files.
       // This example does not return any files that start with `.'.
       FilenameFilter filter = new FilenameFilter() {
           public boolean accept(File dir, String name) {
               return !name.startsWith(".");
           }
       };
       children = dir.list(filter);
       
       
       // The list of files can also be retrieved as File objects
       File[] files = dir.listFiles();<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->

    Then, just use the next and previous buttons to navigate through the array of names (or file objects).
  • DY357LXDY357LX Playing since day 1. Still can&#39;t Comm. England Join Date: 2002-10-27 Member: 1651Members, Constellation
    Wait wait wait, I don't want to use image file-names.
    (Yes my first post was very rough and easily mis-understood.)

    I want the "next" button to go to the next file with the right
    file-extention (in this case .jpg) in the predetermined folder
    (probably ..\images\ for some simple web stuff.)

    OK example time, if you click this link
    <a href='http://media.xbox.gamespy.com/media/676/676367/img_2575470.html?fromint=1' target='_blank'>GameSpy BiA Gallery</a>
    You'll see that the bottom of the page contains a "Gallery"
    and "Next" button. If you put your mouse over the "Next"
    button you can see what URL it's going to take you to.
    This is all fine and dandy but if GameSpy wanted to add more
    images they'd have to add more code for the new buttons
    going to the new images. (Sort of.)

    I want my Applet to go to the next .jpg so that all I ever
    have to do is upload .jpgs to a certain folder. (I'll probably
    have to name them 01.jpg, 02.jpg, and so on.)


    Does that make sense or am I talking smack? <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo-->
  • SkulkBaitSkulkBait Join Date: 2003-02-11 Member: 13423Members
    edited March 2005
    I don't see how what you described is different from what I described. Check out the code in the edit.

    Edit: If you require that the filename (or file object) list be updated every so often, just add a timer to regenerate the list. I forget the API calls to do that in Java, but it should be easy enough to find.
  • ThaldarinThaldarin Alonzi&#33; Join Date: 2003-07-15 Member: 18173Members, Constellation
    Not really a useful post but, do that scrolling text thing really fast, smaller text, fill the screen and green and you can make a nice little Matrix type themed screensaver or something <!--emo&:D--><img src='http://www.unknownworlds.com/forums/html/emoticons/biggrin-fix.gif' border='0' style='vertical-align:middle' alt='biggrin-fix.gif' /><!--endemo-->
Sign In or Register to comment.