How to add a gif Animation to your Java programme

Guys this small tutorial is about how to add an any kind of a animation at the beginning or anywhere of your java programme.This will give a really good look for your project for sure.

So first you’ll have to make your own gif file first.I’ll give show you the way of how to do that kind of a thing 🙂

Step 1 : First you have to create your logo or whatever the thing you want to show using photoshop.

7This is what i have made for my mp3 player 😛

You’ll have to make series of png files according to the animation you want to play.These are the png files i have made and now you may should have a idea about what kind of a animation we are going to make.

1  23 4 5 6 7

So after making all these we can use some online tools for make a gif as we want.

We can use http://www.myspacegens.com web application for that.

  • Keep the the sizes as the original sizes
  • Select a suitable speed for your gif.I selected it as faster 100ms.
  • Then you can add your pngs here and upload

Screen Shot 2558-11-19 at 12.01.31 AM

  • Then it’ll give this kind of a interface where you can change the speed of each slide.

Screen Shot 2558-11-19 at 12.04.57 AM

Change the speeds as you prefer and finally click the submit button and wait for the awesome gif you made.Then just check your gif and download if you are ok with or else you can change the speeds and try again.

Step 2 : So then we’ll go to the netbeans project and add your gif to your java package of your project.

Just like this.”Splash.gif” is what i made for my mp3 player

Screen Shot 2558-11-19 at 12.13.56 AM

After that just right click on the java project(MP3 Player Widget) -> Run -> find the VM Option text field

Type this small code there : -splash:src/AppPackage/Splash.gif

(You can put your name of gif instead of mine(Splash.gif) and please make sure you put the extension .gif)

Step 3 : Go to the files and look for your project -> find the manifest.mf file in the project and open it.

Screen Shot 2558-11-19 at 12.21.47 AM

Then just write this pease of code there at the end  :

SplashScreen-Image : AppPackage/Splash.gif 

So now you can see your small animation is working 😀 Just check it.

If it’s going too fast you can make it slow by sleeping the the running tread like this.


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try{
Thread.sleep(4500);
}catch(Exception e){

}

new MP3PlayerGUI1.setVisible(true);
}

}

Now you can delay your animation by changing the sleep time(ms).

So that’s it with this small tutorial.Hope you’ll apply this awesome feature to your projects as well 😀

Feel free to ask questions if you have regarding any of these steps.Thank you. 🙂

Advertisements

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s