Small Image flipping(like a screensaver) app...have easy ? about expansion

Working on code from:
http://www.rscc.cc.tn.us/faculty/bell/Cst218/jhtp16.html
have included it below, just created a directory named images
and copy/past 8 images into that directory, and rename them bug#.gif, starting at bug0, bug1, bug2...up until bug7.gif
Run app, it works, fine, it flips through the images
HOWEVER, of course, while learning/doing I found it inconvenient to have to rename all of the images, and thought of screensaver programs that flips images for you, and was trying to figure out what I'd have to do to make it possible to just load an arbitrary amount/named image files to be able to flip them.
I figure some kind of JFileChooser would have to be integrated, and then somehow, each file would have to be imported into an Array or Vector set.....
See...that's an entirely different program....but would be interested in the above, and how I could change the code to allow ANY named image, not just images named "bug" , be apart of the array.
Somehow, read the entire directory, and import each image into the Array, or a Vector/whatever.....
While I understand this program ..my "programming brain" /skills are not developed enough to implement the system..hence posting :)
Thank you for your time...
//http://www.rscc.cc.tn.us/faculty/bell/Cst218/jhtp16.html
// LogoAnimator.java
// Animation a series of images
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LogoAnimator extends JPanel
                          implements ActionListener {
   protected ImageIcon images[];
   protected int totalImages = 8,   //changed from 30 to 8
                 currentImage = 0,
                 animationDelay = 1500; // 50 millisecond delay
   protected Timer animationTimer;
   public LogoAnimator()
      setSize( getPreferredSize() );
      images = new ImageIcon[ totalImages ];
      for ( int i = 0; i < images.length; ++i )
         images[ i ] =
            new ImageIcon( "images/bug" + i + ".gif" );  //?!?! here, in this program, each file would have to be named "bug#"
      startAnimation();
   public void paintComponent( Graphics g )
      super.paintComponent( g );
      if ( images[ currentImage ].getImageLoadStatus() ==
           MediaTracker.COMPLETE ) {
         images[ currentImage ].paintIcon( this, g, 0, 0 );
         currentImage = ( currentImage + 1 ) % totalImages;
   public void actionPerformed( ActionEvent e )
      repaint();
   public void startAnimation()
      if ( animationTimer == null ) {
         currentImage = 0;
         animationTimer = new Timer( animationDelay, this );
         animationTimer.start();
      else  // continue from last image displayed
         if ( ! animationTimer.isRunning() )
            animationTimer.restart();
   public void stopAnimation()
      animationTimer.stop();
   public Dimension getMinimumSize()
      return getPreferredSize();
   public Dimension getPreferredSize()
      return new Dimension( 160, 80 );
   public static void main( String args[] )
      LogoAnimator anim = new LogoAnimator();
      JFrame app = new JFrame( "Animator test" );
      app.getContentPane().add( anim, BorderLayout.CENTER );
      app.addWindowListener(
         new WindowAdapter() {
            public void windowClosing( WindowEvent e )
               System.exit( 0 );
      // The constants 10 and 30 are used below to size the
      // window 10 pixels wider than the animation and
      // 30 pixels taller than the animation.
      app.setSize( anim.getPreferredSize().width + 10,
                   anim.getPreferredSize().height + 30 );
      app.show();
}

This is set up to compile and run in j2se 1.4
You can swap the comments in three marked areas to compile and run in j2se 1.5
If using earlier versions than j2se 1.4 you'll need to replace the image loading code (2 lines, marked)
with earlier code, such as ImageIcon (j2se 1.2) or the earlier Toolkit methods with MediaTracker.
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.List;
import javax.imageio.ImageIO;
import javax.imageio.stream.FileImageInputStream;
import javax.swing.*;
public class SlideShow
    SlidePanel slidePanel;
    JFileChooser fileChooser;
    JComboBox slides;
    JFrame f;
    public SlideShow()
        slidePanel = new SlidePanel();
        f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(getSlidePanel(), "North");
        f.getContentPane().add(slidePanel);
        f.getContentPane().add(getControlPanel(), "South");
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
    private JPanel getSlidePanel()
        fileChooser = new JFileChooser("images/");
        slides = new JComboBox();
        Dimension d = slides.getPreferredSize();
        d.width = 125;
        slides.setPreferredSize(d);
        final JButton
            open   = new JButton("open"),
            remove = new JButton("remove");
        ActionListener l = new ActionListener()
            public void actionPerformed(ActionEvent e)
                JButton button = (JButton)e.getSource();
                if(button == open)
                    showDialog();
                if(button == remove)
                    removeSlide();
        open.addActionListener(l);
        remove.addActionListener(l);
        JPanel panel = new JPanel();
        panel.add(open);
        panel.add(slides);
        panel.add(remove);
        return panel;
    private JPanel getControlPanel()
        final JButton
            start = new JButton("start"),
            stop  = new JButton("stop");
        ActionListener l = new ActionListener()
            public void actionPerformed(ActionEvent e)
                JButton button = (JButton)e.getSource();
                if(button == start)
                    slidePanel.start();
                if(button == stop)
                    slidePanel.stop();
        start.addActionListener(l);
        stop.addActionListener(l);
        JPanel panel = new JPanel();
        panel.add(start);
        panel.add(stop);
        return panel;
    private void showDialog()
        if(fileChooser.showOpenDialog(f) == JFileChooser.APPROVE_OPTION)
            File file = fileChooser.getSelectedFile();
            if(hasValidExtension(file))
                Slide slide = new Slide(file);
                slides.addItem(slide);
                slides.setSelectedItem(slide);
                slidePanel.addImage(slide.getFile());
    private boolean hasValidExtension(File file)
        String[] okayExtensions = { "gif", "jpg", "png" };
        String path = file.getPath();
        String ext = path.substring(path.lastIndexOf(".") + 1).toLowerCase();
        for(int j = 0; j < okayExtensions.length; j++)
            if(ext.equals(okayExtensions[j]))
                return true;
        return false;
    private void removeSlide()
        Slide slide = (Slide)slides.getSelectedItem();
        int index = slides.getSelectedIndex();
        slides.removeItem(slide);
        slidePanel.removeImage(index);
    public static void main(String[] args)
        new SlideShow();
class Slide
    File file;
    public Slide(File file)
        this.file = file;
    public File getFile()
        return file;
    public String toString()
        return file.getName();
class SlidePanel extends JPanel
    //List<BufferedImage> images;  // j2se 1.5
    List images;                   // j2se 1.4
    int count;
    boolean keepRunning;
    Thread animator;
    public SlidePanel()
        //images = Collections.synchronizedList(new ArrayList<BufferedImage>());  // 1.5
        images = Collections.synchronizedList(new ArrayList());  // j2se 1.4
        count = 0;
        keepRunning = false;
        setBackground(Color.white);
    protected void paintComponent(Graphics g)
        super.paintComponent(g);
        int w = getWidth();
        int h = getHeight();
        if(images.size() > 0)
            //BufferedImage image = images.get(count);               // j2se 1.5
            BufferedImage image = (BufferedImage)images.get(count);  // j2se 1.4
            int imageWidth = image.getWidth();
            int imageHeight = image.getHeight();
            int x = (w - imageWidth)/2;
            int y = (h - imageHeight)/2;
            g.drawImage(image, x, y, this);
    private Runnable animate = new Runnable()
        public void run()
            while(keepRunning)
                if(images.size() == 0)
                    stop();
                    break;
                count = (count + 1) % images.size();
                repaint();
                try
                    Thread.sleep(1000);
                catch(InterruptedException ie)
                    System.err.println("animate interrupt: " + ie.getMessage());
            repaint();
    public void start()
        if(!keepRunning)
            keepRunning = true;
            animator = new Thread(animate);
            animator.start();
    public void stop()
        if(keepRunning)
            keepRunning = false;
            animator = null;
    public void addImage(File file)
        try
            FileImageInputStream fiis = new FileImageInputStream(file);  // j2se 1.4+
            images.add(ImageIO.read(fiis));                              //    "
        catch(FileNotFoundException fnfe)
            System.err.println("file: " + fnfe.getMessage());
        catch(IOException ioe)
            System.err.println("read: " + ioe.getMessage());
    public void removeImage(int index)
        images.remove(index);
}

Similar Messages

  • I've downloaded some free apps on my iphone 4 and some of them have ads. I was just wondering, are those ads free as well, or are they using my internet when they pop up like that? i have to mention, i never click them.

    I've downloaded some free apps on my iphone 4 and some of them have ads. I was just wondering, are those ads free as well, or are they using my internet when they pop up like that? i have to mention, i never click them.

    Yes, they will use a very small amount of your internet bandwidth to display.

  • Okay so i recorded a song but each part comes out as like take 1, i have 10 takes. how can i put them all together as one take, to make one song all in one take not small pieces of a song.

    okay so i recorded a song but each part comes out as like take 1, i have 10 takes. how can i put them all together as one take, to make one song all in one take not small pieces of a song. like i hit record and sang the entire song but when i hit play it was in pieces not just one song like it was in ten takes. is there any way i can blend it all into one take, to make one clear song?

    You're not very clear in stating your problem. Maybe it's terminology: "takes" in recording lingo (and in GB lingo) are different version of exactly the same part in a song, so you only want one of them in the end. Please tell us exactly what you did and what it is that you don't like.

  • I can't backup my iPhone 5. It says I don't have enough storage. So I've deleted like 6-7 apps and its still says I don't have enough storage. And it also says the say thing when I want to buy new apps or music. What can I do?

    I can't backup my iPhone 5. It says I don't have enough storage. So I've deleted like 6-7 apps and its still says I don't have enough storage. And it also says the same thing when I want to buy new apps or music. Also my messages won't send; I have to turn my phone off and resend then just to they can send. I can't even take any pictures because it says I have no storage.(I currently have 1,658 photos and 72 videos by the way.) What can I do? I just my phone in late December. I didn't think it would act up this bad before I even had it for a year. Please help.

    Your phone needs more storage, buying storage on iCloud.com doesn't change that.
    Delete some of the stuff off of your phone, it's full.

  • I want to move a selection (a person) into an image of a brick wall and have it look like the person was painted on the wall. Can it be done? Using CC on iMac. Thanks

    I want to move a selection (a person) into an image of a brick wall and have it look like the person was painted on the wall. Can it be done? Using CC on iMac. Thanks

    Yes of course its Photoshop. Cut the person out copy to clipboard paste onto toe brick wall document  and texture the layer using a displacement map for the brick wall. Look for Photoshop tutorials on using a displacement map.

  • I have a debit card but would like to download apps from the store. how do I do that? I can't possibly get a credit card just for this. please help.

    Hi,
    I have an iTouch. I'd like to download some free apps. but I have a debit card but would like to download apps from the store. how do I do that? I can't possibly get a credit card just for this. please help.

    I really do not think it is the iPad or your network connection. Other users have reported this very same issue. Try this and see if it works for you - it may not work - but it's easy to try - harmless - and it has worked in the past for others.
    Try signing out of your account and restart your iPad.
    Go to Settings>Store>Apple ID and tap the ID and sign out. Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button. Go back to Settings>Store> Apple ID and sign in again.

  • Need a dual time zone clock app that runs like a screensaver

    I have a first generation iPhone and I am wondering if any of the many world time zone clocks available as apps have the ability to run over or replace, until touched, the iPhone screen itself, which contains numerous app logos. Hope that makes sense. Thoughts?

    What about adding another to Dashboard?
    There are some for $20 but not menu bar:
    http://www.versiontracker.com/dyn/moreinfo/macosx/12763
    Doesn't sound like what you were looking for though.

  • How come my Iphone 4 keeps saying not enough storage to take any more pictures and can't get updates yet I keep deleting apps and photos off my phone and my itunes on my computer and yet I feel like I don't have many apps or that many photos?

    How come my Iphone 4 keeps saying not enough storagespace to take any more pictures and can't get updates yet I keep deleting apps and photos off my phone and my itunes on my computer and yet I feel like I don't have many apps or that many photos?

    Check Settings > General > Usage to display what's taking all your space.

  • Since downloading os 7 update some of my apps have  waiting under them like they are going to update. Any ideas?

    Since downloading os 7 update some of my apps have  waiting under them like they are going to update. Any ideas?

    Sync with your usual computer.

  • Problem with image flip in ID CS3

    I have a document with a series of similar pages, for example a common background image and then coupons of varying value amounts on successive pages. On the "coupon" portion of the page, there is a small picture of the product. Sometimes the product image will print fine, sometimes upside down, sometimes upside down and backwards. Typically the first page of the document will print or distill fine, and then one or all of the following pages will have a flipped image. Printing each page one by one corrects the problem, since then each page is "page one". The problem occurs when printing to the color laser device as well as when distilling a pdf. When inspecting the document, it appears to be properly constructed. This is just one sort of example, but usually it is any sort of layered, complex file with multiple images. One of my staff said he has seen this happen before at his previous employment, with large InDesign files. Any thoughts on how we can prevent this from happening. We are all on mac and printing to an industrial strength commercial output, but I don't think it's the output device, since it happens when we distill a pdf as well. Thanks

    Al and Michael,
    In answer to your questions,
    we sometimes when making a low res pdf for client viewing do an export 
    from Indesign to a customized "small file" ppd variant that collects 
    the fonts.
    Usually we print to postscript and use a ppd created by one of our 
    film houses, Vertis, that is the customized ppd we use to export to 
    our epson proofer SWOP that generates a pdfx1a. If you would like I 
    can send you these ppds. Please let me know.
    Sometimes when the file is complex using the print to file and distill 
    does not work, we get some stitching and boxes so when we use the 
    pdfx1a export from Indesign sometimes that works. We have learned that 
    it is not exact science. That is another issue, since the files that 
    have the stitching issues are not the same files that have the image 
    flips.
    The equipment and versions we are using:
    Mac g5 computer (non intel)
    OsX v10.5.6
    InDesign CS3 v5.04
    Acrobat Distiller Professional 8.1.3
    Since the problem occurs in the same documents both when outputting to 
    the device and creating a pdf intermittently I would not be so certain 
    that the issue is caused by the output device, however,
    it is a Canon Image Press C1
    Boot ROM version 55.03
    Device System 63.01
    and the server running it is a
    EFI Fiery System 8
    Version 1.01
    I see some PPDs that are for the Canon that are EF4M2068 with 
    different extensions. Don't know if I am looking in the right place.
    The Canon people are also looking into this however like I said I am 
    suspicious that there may be something in our file construction since 
    we run a lot of documents here and it seems to be confined to just a 
    few of them.
    Any insight you can give me would be greatly appreciated.
    thanks,
    paula kelman
    print production supervisor
    fkm
    713 867 3192
    [email protected]
    In addition to what Michael asks, what ppd is being used when you 
    print to postscript for distilling? Or are you actually exporting the 
    pdf?
    Al

  • How to handle small images e.g icons

    I'm developing iPhone apps and when I design the icons in either photoshop or illustrator I always have the same problem. When working with very small images like 100px x 100px and smaller it's very hard to get a good resolution of the creation. For example when I make an icon in illustrator with a size of 76x76 the resolution obviously is good in illustrator since it's vector, but when I export the image it's first enlarged. And when I change the size back to 76x76 (using photoshop: image > image size) the resolution sucks. When I try to make the icon in photoshop from the beginning everything I draw gets blurry.
         When designing large icons like 1000x1000 I never encounter this problem neither in photoshop nor illustrator. How am I supposed to do when working with small images?
    Thanks

    All of them? ?? 
    How many did you actually check among the 13,900,000 hits returned by the Google search?

  • OpenGL Best Only for Small Images in CS5?

    I've been using Photoshop CS5 daily from shortly after the day it was released on my Windows 7 x64 system.  I have a decent dual processor dual core w/hyperthreading workstation with 8 GB of RAM and a VisionTek ATI Radeon HD 4670 video card with 1GB of onboard video RAM.  Mostly I've been editing relatively small images (10 to 20 megapixels), though I've successfully made some pretty big panoramas.
    Outside of a few glitches, most of which were solved with 12.0.1 (i.e., things like crashing or stuck processes after shutdown), I've had very good results with Photoshop CS5.
    I tried the various OpenGL settings, and since the "Basic" setting seems to stress OpenGL the least while still providing me access to the new OpenGL features (e.g., brush gestures), I have chosen that setting.  Keep in mind this decision was also influenced by the sheer number of OpenGL-related issues being reported here.
    However, in the past day I have been working on a rather larger image...  Not huge, as Large images go, but large enough that it has caused me some unexpected Photoshop trouble.  Basically, it's a set of 7 digital camera images of 10 megapixels arranged in a 12 x 36 inch layout at 600 ppi.  Overall image size is 21,600 x 7200 pixels x 16 bits/channel.  The image on disk is roughly a gigabyte.  Here's a small version so you can see what I'm talking about...
    I had this image in 2 layers - the images with transparent surround and outer bevel layer style, and the background blue.  The customer wanted the images spread out a bit more so I undertook to do so - by lassoing sets of the images and moving them apart.
    Here's where the trouble began.  Some of the work involved zooming in, to say 250% or closer, to check alignment and to nudge things as needed.
    While working on this image I find Photoshop gets quite sluggish, though it's not hard on the disk drive.
    After I moved everything into place and did File - Save, my system simply froze as the progress bar reached 1 pixel shy of a full bar.  That required a hard reset of the computer.  No events were logged in the Windows System or Application logs.
    I redid the work, and second time I did File - Save As... the dialog never came up.  Photoshop just disappeared.  Again, no errors logged.
    Today I ran through the edit again, this time with OpenGL turned off.  I found:
    1.  The system was nowhere near as sluggish when displaying the image at high magnifications.  I could move things around easier.
    2.  I was able to complete the same edits again (the 3rd time) and File - Save As... successfully.
    Today I upgraded my ATI drivers to Catalyst 10.6, re-enabled OpenGL in Photoshop, and went through the same edits on the same file a 4th time.
    1.  Same sluggishness as before when zoomed in.
    2.  After moving the images around, when I went to use the Spot Healing Brush Photoshop crashed:  Unhandled Exception, 0xC0000005:  Access violation reading location 0x00000000007e8ebb0.
    I don't have Photoshop debugging symbols, but this is what the Call Stack showed in the debugger:
    I will continue to experiment with this to see if I can isolate what's causing it, but the one key thing here is that it works with OpenGL turned off, and it fails in several ways with OpenGL turned on with a powerful, relatively modern video card.
    -Noel

    Thanks for your responses.
    I'm investigating the Normal and Advanced settings with this same image as time permits.
    So far I've been able to complete the same edits and save the file successfully with OpenGL set to Normal.  Notably as well Photoshop was VERY much more responsive.
    It's a very small sample size, but one might be forgiven for concluding that Photoshop has had the most testing with the OpenGL setting at default.  I do plan to continue testing with this image, as it seems to be a good one for stressing the system and reproducing one or more problems.
    I may have been wrong in my judgment that the Basic OpenGL setting stresses the system less.
    As far as why I'm working with a 16 bit image and at this high a resolution, I am specifically pushing Photoshop hard since with a 64 bit system these things should be possible, and I haven't gotten a lot of experience working on big images with 12.0.1.  While this particular image does not require it (especially for a 12 x 36 print) I often DO work on 1 gigabyte or more astroimages, and I just haven't had a good big one to work on lately.
    -Noel

  • When I publish from ibooks author will the pages flip like my other books

    When I publish from ibooks author will the pages flip like my other books the preview only slides side to side

    Pages continue to slide rather than flip for the horizontal orientation.  In the vertical orientation, the text scrolls up-and-down like a web page (again as shown in iBooks Author if you change the previewed orientation).  I'm not sure why Apple went with the different GUI for their textbooks, but its the same for the ones authored by the big publishers.  If you want to see what the format is like on the iPad, there's a short free textbook (Wilson's Life on Earth) and sample chapters from others available from the iBookstore.
    On a side note, one interesting thing about using texts in the two different orientations is that the formating changes as well.  Figures that show up as larger embedded images in the horizontal layout are smaller images in the left margin in the vertical layout, at least in Wilson's book.

  • Adding blog / news list layout small image

    Is it possible to generate a small image of the image attached to a news or blog and include it in the list layout?
    I'm trying to accomplish something similar that is available for the product, in the blog or news module.
    Does anyone have any suggestions?
    thank you,

    Hi mfj102,
    Please see this thread which discusses this topic: http://forums.adobe.com/message/5853967. As mentioned, the best method would be to re-create a blog using the web app functionality.
    Cheers.

  • Flattened pixmap mask description wrong for small images -- Bug?

    I've been working with images loaded from disk lately, and it seems to me the description for the mask element of the flattened pixmap cluster is incorrect when the image size is small. The online help reads:
    mask is an array of bytes in which each bit describes mask
    information for a pixel. The first byte describes the first eight pixels, the
    second byte describes the next eight pixels, and so on. If a bit is zero,
    LabVIEW draws the corresponding pixel as transparent. If the array is empty,
    LabVIEW draws all pixels without transparency. If the array does not contain a
    bit for each pixel in the image, LabVIEW draws any pixels missing from the array
    without transparency.
    So there should be one bit in the mask for each pixel. Here is what I'm getting:
    image size   # pixels    mask length, bytes (bits)
    1x1               1            2   (16)
    1x2               2            2   (16)
    2x2               4            4   (32)
    4x4              16            8   (64)
    8x8              64           16  (128)
    9x9              81           18  (144)
    32x32          1024          128 (1024)
    33x33          1089          198 (1584)
    It looks like there are two issues here. One, the mask array works on rows of pixels. If the row does not end on a byte, the byte is padded on the right with zeros until the end, then the next row starts. E.g., for the 9x9 image, pixel #9 is byte 2, bit 8; byte 2 is padded with zeros; pixels 10-18 start with byte 3.
    Two, for some reason small images (i think 8 pixels per row or less, but I'm not sure) have every other byte a zero. For example, here is the mask for my 4x4 test image, with every pixel opaque:
       11110000 00000000 11110000 00000000 11110000 00000000 11110000 00000000
    According to thel help text, the mask array should be 2 bytes long, with every bit a 1.
    It seems to me that the first issue is likely intentional, and the help text just isn't entirely clear. The second issue, I'm not sure about. Maybe it was just assumed that pictures would be large and small pictures wouldn't be used?

    Wiebe is correct that every line of the image gets an even number of bytes in it mask.
    The help was misleading, I agree. I have reported this confusion as a bug in the documentation (I do not remeber to CAR#) so it can be explained better.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

Maybe you are looking for

  • TS4002 Does anyone know why it would take messages that have already been downloaded a long time to open?

    My mail in iCloud is taking a very long time to load messages.  ICloud loads but when I click on a message it takes up to a minute to bring the message up.  Any ideas?

  • Can you open freehand files in CS6?

    can you open freehand files in CS6? I have been using both illustrator & freehand for 15 years & have thousands of work files being freehand. It seems very disappointing to have to keep an old version of illustrator just to open these files. I also f

  • Maximum size for SD card for N70

    hi can anybody please tell me the maximum size for SD card for the N70? i only have 64MB at the moment and i want to upgrade. many thanks in advance. itcrowd sheffield, uk

  • How to get started with new smart iPhone?

    OK, we are new to smart phones and just ordered the Verizon iPhone. We are Mac users for years. We have a few songs in iTunes, lots of photos in Aperture and a large calander of events and a large phone book on the Mac. The phones we have are essenti

  • E-Recruiting Requisition Process

    Hello Gurus, I am trying to configure the Requisition Process based on BSP. When I run the application on our Portal it creates a Obcect in HRP5125 and if I check the Trace log via SWEL I can see that the workflow WS51900008 and WS51900010 is running