Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Line Animation in Java 
 

In this example we are creating an animated line. The color of line is changing alternatively.

 

Features

Technology
  Tech. Home
  GPS
  OSI
  WiMAX
  VoIP
  WiFi
  HSDPA
  LBS
  Vehicle Tracking
  SCADA
  Tech. What is?
Jobs At RoseIndia.net!
 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Line Animation in Java

                         

In this example we are creating an animated line. The color of  line is changing alternatively.

We use drawLine() to draw a line and setColor() method to set the color of the line. We pass four values in drawLine() method in which three  last values are fixed while value of  first x  is changing. The rang of the value is -500 to 600. The color of the line is changing by setColor() method. To remove old color and set new one or  in other words to refresh the color of line we are using repaint() method. To display the output we are creating new html files in which we are calling the .class file (of the source file) by using applet tag. We define the height and width of the window for output.

Here is the code of the program :

import java.awt.*;
import java.applet.*;
import javax.swing.*;
import java.awt.*;
public class AnimationLine extends JApplet
{     
     public void init() 
     {
     getContentPane().add(new AnimationLinePanel())
     setSize(800,500);
     }
     public class AnimationLinePanel extends JPanel
     {
     int linex,linem = 1
     public AnimationLinePanel()
     {
     setBackground(Color.black)
     }
     public void paintComponent(Graphics page)
     {
     super.paintComponent(page);
     page.setColor(Color.red)
     page.drawLine(linem,200,310,400)
     if(linex > 500)
   {
     linem = -500;
   page.setColor(Color.green)
   page.drawLine(linem,200,310,400);             
   }
     if(linex < 0)
   {
     linem = 600;
   page.setColor(Color.yellow)
   page.drawLine(linem,200,310,400);         
   }
     linex += linem; 
     repaint()
     }
     }

<html>
<body>
<APPLET ALIGN=
"CENTER" CODE="AnimationLine.class" 
WIDTH=
"800" HEIGHT="500">
</APPLET>
</body>
</html>

OutPut of The Example:

Download this example.

Download this example.

                         

» View all related tutorials
Related Tags: c gui com ide browser class stl ui applet io methods classes method sed apple nested override vi component panel

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

This code is use to create a line animation using java code.

Posted by Samujeet on Tuesday, 02.12.08 @ 13:26pm | #47993

Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.