Friday, April 12, 2013

Text Animation program

This is a simple Text Animation program. When the program starts the text "Happy New Year" moves from different locations on the frame window. To make the text move, we a need a label object to display this text. Then locations of the label object are changed by using a while loop.

TextAnimation source code:

1 import java.awt.*;
2 import javax.swing.*;

3 class  Animation extends JFrame{
4 JLabel lblText;
5 Animation(){
6 setTitle("Text Animation");
7 setLayout(null);
8       lblText=new JLabel("<html><p style='color: #ff00ff; font-size:20pt'>Happy New Year</p></html>");
9       lblText.setSize(200,50);
10 setSize(800,500);
11 setResizable(false);
12 setDefaultCloseOperation(EXIT_ON_CLOSE);
13 add(lblText);
14   setVisible(true);
15 doAnimation();

16   public void doAnimation(){
int x=1;
int y=5;
if(x>800) x=1;
if(y>500) y=5;


}catch(InterruptedException ie){System.out.println("Interrupted...");}


17 public class TextAnimation{

public static void main(String args[]){
      new Animation();


Text Animation program in Java

Code Explanation:

1 Introduce classes in awt package to the program.
2 Introduce classes in swing package to the program.
The two packages are required in drawing the program interface. In this program, we need only one frame window and a label to show the text to be animated.
3 The Animation class contains Java code to draw the program interface and do animation.
4 Declare a JLabel lblText.
5 Animation is the constructor of the Animation class. When an object of Animation class is created, the code in this constructor is executed to draw program interface and do animation.
6 Set frame window title.
7 Set the layout of the frame window to null so that you can customize the location of the components on it.
8 Create the JLabel object LblText. This object contain the text "Happy New Year" to be animated.
9 Define size of the JLabel object lblText (width=200, height=50).
10 Define the size of frame window (width=850, height=450).
11 Disable frame resizing.
12 Allow the frame window to close when the user clicks the close button.
13 Add the JLabel lblText object to the frame window.
14 Make sure the frame window visible.
15 Invoke the doAnimation method to animate the lblText object.
16 The doAnimation method contains code to animate the JLabel object lblText. The animation on the object is performed by changing its location (x,y). A while is used to change the location of the object by increasing the values of x-axis and y-axis of the object by 20. When these values are nearly equal to the width and height of the frame window, they are reset to the initial values (x=1,y=5). The sleep method of the Thread class is invoked to delay the action of the lblText object (chaning from one location to another location). We delay the action by 200 milliseconds (sleep(200)).
17 The TextAnimation class has the main method to start the program.
compass app flashLight app


  1. Like your way of seeing things! Still you may do some things to expand on it. Thanks for sharing with us!


  2. Take a gander at workmanship classes at your neighborhood junior college in the event that you need to enhance your drawing aptitudes. In the event that you need an easy route to draw a toon me confront you should simply locate the correct PC download program that does the majority of the diligent work for you. There are a few unique items that draw toons and most are free. this contact form

  3. leaving the OS to do the last modification as the application is hurrying to mean the PC the summons. Java

  4. This article is about the pharmacology field and bunches of individuals working in this field. The general population who are as of now working in this field ought to see all the fundamental things and endeavor to enhance this field and assignment writing australia help me a lot to find out good info. This is the great wellspring of helping material.

  5. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. Multimedia 3d Animation Thrissur

  6. Your article is very helpful.You can visit my website:flip diving full game

  7. I Love your article. You can visit my website : skinslio

  8. I love animation and want to join these animation programs,
    Dissertation Help UK

  9. OMGGG...I am surprised to see thik horse riding tales hack thanks for the effort you ppl take to get this resources.

  10. My engagement ring is platinum and I couldn't be happier. It is so shiny however the downside is that it's pretty expensive and costs more to size than gold. There are scratches although not very noticeable seaport hack

  11. They seem to be easy but infact requires a lot of time and hardwork . Great work world of tanks blitz hack

  12. Your jewelry is amazing. These could be used for embellishments for other craft items as well. Great ideas. horse riding tales hack

  13. I am thinking that in this time you should give a try to this new app chomp SMS Apk : which is now most trending app in the world.

  14. I'm really impressed and explained simply with lost of content bowling crew hack

  15. his is very useful and it is is a great share!! Brawlhalla Mobile Hack

  16. is is very useful and it is is a great share!! Brawlhalla Mobile Hack

  17. Get affordable and faster webhosting on hostgator via hostgator coupon codes. Register now to get faster webpage loading.