/* Program In Java To Display A text and to scroll the text from right to left, display the text as colored */
import java.awt.*;
import java.applet.*;
public class HoriScroll extends Applet implements Runnable
{
String message = "Lionel Cyril ....";
int x,y;
Dimension size;
public void init()
{
//set initial co-ordinates for message
x = 10;
y = 50;
//creates new thread
Thread t = new Thread(this);
t.start();
}
public void run()
{
while (true)
{
try
{
/*initialize size to contain the current size of the applet window */
size = getSize();
/* if co-ordinate of the text is greater than reset the width of the applet the x coordinate to 10 else increment x */
if(x>size.width)
x = 0;
x++;
Thread.sleep(50);
}
catch(InterruptedException e)
{
}
repaint();
}
}
public void paint(Graphics g)
{
g.setFont(new Font("Monotype Corsiva",Font.BOLD,24));
g.setColor(Color.red);
g.drawString(message,x,y);
}
}
/*< applet height="500" width="500" code="HoriScroll">< /applet>*/
Labels: Advanced Java, Applet, Thread
Subscribe to:
Post Comments (Atom)
hey ,
hi I am Pallavi a B.tech student I am not interested in programming though, I like communication and networking and hardware...but I guess its coz I did not get good teachers for programming ...saw ur blog it rocks \m/ can you please help me with programmin specially in java please please please
thanks regards
pallavi
ps my email :pallavidevpriya@gmail.com