Solved

Animating pics for a splashpage

Posted on 2004-04-10
8
173 Views
Last Modified: 2010-03-31


How could 4 pics lined up in a row on a canvas or whatever move one pic from the row at a time moving from left to right into the background moving around and then bring them back into the row one at a time moving from right to left ending up where it started. It should be timed to complete itself in about 5 secs.

I want to have this as a splashpage for my program. I don't know how this need to be done.
0
Comment
Question by:Drop_of_Rain
8 Comments
 
LVL 15

Expert Comment

by:Javatm
ID: 10798898
> How could 4 pics lined up in a row on a canvas or whatever move one pic from the row at a time.

This can be very tricky if you want to use java to handle this. As a suggestion just handle your animation
using animation programs like Macromedia fireworks, or flash or whatever animation tools that is
available for you and convert them into  GIF files.

After that thats the time you could call those GIF graphics into your splash screen

Here is the code for splash screen :

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Splash extends JWindow {

 public MyScreen() {

  JLabel l1 = new JLabel(new ImageIcon("C:/YourFolder/YourPic.gif"));

  this.getContentPane().add(l1, BorderLayout.CENTER);

  // This is for the screen resolution and dimension
 
  Dimension sd  = Toolkit.getDefaultToolkit().getScreenSize();
  setLocation(sd.width / 2 - 300 / 2,
  sd.height / 2 - 200 / 2);

  setSize(300, 200);
  setVisible(true);

  int delay1 = 3000; //milliseconds

  ActionListener updater1 = new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
  System.exit(0);
  }
  };

  new Timer(delay1, updater1).start();
  }

  public static void main( String args[] )
   {
      MyScreen app = new MyScreen();
   }
}

Hope that helps . . .
Javatm
0
 
LVL 15

Accepted Solution

by:
Javatm earned 250 total points
ID: 10798955
Sorry forgot to change so things :

/**
 * Created by : Javatm
 * Date  : 04/11/2004
 * Time : 7:27 AM
 */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Splash extends JWindow {

 public Splash() {

  JLabel l1 = new JLabel(new ImageIcon("C:/YourFolder/YourPic.gif"));

  this.getContentPane().add(l1, BorderLayout.CENTER);

  // This is for the screen resolution and dimension
 
  Dimension sd  = Toolkit.getDefaultToolkit().getScreenSize();
  setLocation(sd.width / 2 - 300 / 2,
  sd.height / 2 - 200 / 2);

  setSize(300, 200);
  setVisible(true);

  int delay1 = 3000; //milliseconds

  ActionListener updater1 = new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
  System.exit(0);
  }
  };

  new Timer(delay1, updater1).start();
  }

  public static void main( String args[] )
   {
   Splash app = new Splash();
   }
}

Hope that helps . . .
Javatm
0
 
LVL 92

Assisted Solution

by:objects
objects earned 250 total points
ID: 10799412
Heres an article discussing how to animate an image:
http://www.javaworld.com/javaworld/jw-03-1996/jw-03-animation.html
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:Drop_of_Rain
ID: 10799784
Thanks for the code. I already had the splash page code. I'm going to leave this one open for a while
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10801509
You need to create a couple of things;
1. An Animator class
2. An AnimationPath class

The Animator class will have the information about frame rate, duration etc. and will ask registered UI elements to move according to the AnimationPath instance associated with it.

The AnimationPath class describes the path which an animated object should follow. It could also contain rotation information etc.
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10803957
import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;

public class SplashPage extends JFrame
{
      private JLabel label1, label2, label3, label4;
      
      public SplashPage()
      {
            super();
            
            initialize();            
      }
      
      private void initialize()
      {
            JPanel panel = (JPanel)getContentPane();
            panel.setLayout(null);
            
            label1 = new JLabel("Image 1");
            //label1.setIcon(new ImageIcon("<file name with path>"));
            label1.setSize(100,100);
            label1.setLocation(10,10);
            label1.setBackground(Color.cyan);
            label1.setOpaque(true);
            
            panel.add(label1);

            label2 = new JLabel("Image 2");
            //label2.setIcon(new ImageIcon("<file name with path>"));
            label2.setSize(100,100);
            label2.setLocation(120,10);
            label2.setBackground(Color.gray);
            label2.setOpaque(true);
            
            panel.add(label2);

            label3 = new JLabel("Image 3");
            //label3.setIcon(new ImageIcon("<file name with path>"));
            label3.setSize(100,100);
            label3.setLocation(230,10);
            label3.setBackground(Color.magenta);
            label3.setOpaque(true);
            
            panel.add(label3);
            
            label4 = new JLabel("Image 4");
            //label4.setIcon(new ImageIcon("<file name with path>"));
            label4.setSize(100,100);
            label4.setLocation(340,10);
            label4.setBackground(Color.pink);
            label4.setOpaque(true);
            
            panel.add(label4);
            
            label1.setBorder(new LineBorder(Color.black));
            label2.setBorder(new LineBorder(Color.black));
            label3.setBorder(new LineBorder(Color.black));
            label4.setBorder(new LineBorder(Color.black));
            
            setSize(450, 300);
            setVisible(true);
            
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            
            new SplashThread();
      }
      
      class SplashThread extends Thread
      {
            public SplashThread()
            {
                  start();
            }
            
            public void run()
            {
                  JLabel label = null;
                  
                  for (int i = 0; i < 4; i++)
                  {
                        switch (i)
                        {
                              case 0:
                                    label = label1;
                                    break;
                                    
                              case 1:
                                    label = label2;
                                    break;
                                    
                              case 2:
                                    label = label3;
                                    break;            
                                    
                              case 3:
                                    label = label3;
                                    break;
                        }
                        
                        int startX = label.getX();
                        int startY = label.getY();
                        
                        for (int x = startX; x < 330; x += 10)
                        {
                              label.setLocation(x, startY);
                        }
                        
                        label.setLocation(startX, startY);
                  }
            }
      }
      
      public static void main(String[] args)
      {
            new SplashPage();
      }
}


This would help you having some idea on building the splash page


Regards,
Muruga
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question