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;
try{
while(x<800){
lblText.setLocation(x,y);
Thread.sleep(200);
x+=20;
y+=20;
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();
}
}
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.
![]() |
![]() |
Like your way of seeing things! Still you may do some things to expand on it. Thanks for sharing with us!
ReplyDeleteHIMT
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
ReplyDeleteleaving the OS to do the last modification as the application is hurrying to mean the PC the summons. Java
ReplyDeleteThis 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.
ReplyDeletefreeflix apk
ReplyDeletesolarmovie
ReplyDelete1movies
ReplyDeletesports whatsapp groups
ReplyDeleteI 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
ReplyDeleteYour article is very helpful.You can visit my website:flip diving full game
ReplyDeleteI Love your article. You can visit my website : skinslio
ReplyDeleteI love animation and want to join these animation programs,
ReplyDeleteDissertation Help UK
anniversary wishes for parents
ReplyDeleteanniversary wishes for wife
anniversary wishes for husband
wedding anniversary wishes for husband
wedding anniversary wishes for wife
OMGGG...I am surprised to see thik horse riding tales hack thanks for the effort you ppl take to get this resources.
ReplyDeleteMy 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
ReplyDeleteThey seem to be easy but infact requires a lot of time and hardwork . Great work world of tanks blitz hack
ReplyDeleteYour jewelry is amazing. These could be used for embellishments for other craft items as well. Great ideas. horse riding tales hack
ReplyDeleteOhh My God Your Still missing this app Final Fantasy Crystal Chronicles Remastered Edition Apk
ReplyDeleteI 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.
ReplyDelete