Question: Write a program to create a moving string by applet.
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class MovingString extends
Applet implements Runnable
{
String msg="Hey it's
me Gargi....";
Thread t=null;
public void init()
{
setBackground(Color.cyan);
setBackground(Color.red);
t=new Thread(this);
t.start();
}
public void run()
{
char ch;
for( ; ;)
{
try
{
repaint();
Thread.sleep(400);
ch=msg.charAt(0);
msg=msg.substring(1,msg.length());
msg+=ch;
}
catch(InterruptedException e)
{
}
}
}
public void paint(Graphics g)
{
g.drawString(msg,50,50);
}
}
/*<applet
code=ScrollingText.class WIDTH=400 HEIGHT=200>
</applet>*/
OUTPUT:Keyword:
How to recover the classnotfoundexception in Java?
What are the top most requirements or expectations of client for develop Java web application?
Java program question paper in 2020
java applet
creating applet in java
Comments
Post a Comment