100% found this document useful (1 vote)
194 views

Advanced Java Slip1A)

This java program scrolls text from left to right and vice versa continuously in an applet. It uses a thread to increment the x position of the text by 10 each iteration, changing direction when it reaches the width or edge of the applet. The run method continuously repaints and calls the mpostion method, while the paint method draws the string at the current x,y position.

Uploaded by

Aniket Tajane
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
194 views

Advanced Java Slip1A)

This java program scrolls text from left to right and vice versa continuously in an applet. It uses a thread to increment the x position of the text by 10 each iteration, changing direction when it reaches the width or edge of the applet. The run method continuously repaints and calls the mpostion method, while the paint method draws the string at the current x,y position.

Uploaded by

Aniket Tajane
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

A) Write a java program to scroll the text from left to right and vice versa

continuously.

Answer :

import java.applet.Applet;

import java.awt.*;

public class Slip1A extends Applet implements Runnable {

int x, y, z;

Thread t;

public void init() {

x = 50;

y = 50;

z = 1;

t = new Thread(this);

t.start();

public void mpostion() {

x = x + 10 * z;

if (x > this.getWidth())

z = -1;

if (x < 0)

z = 1;

public void run() {

while (true) {

repaint();

mpostion();

try {

Thread.sleep(100);

} catch (Exception e) {

}
}

public void paint(Graphics g) {

g.drawString("SVPM", x, y);

/*

* <applet code="Slip1A.class" width="300" height="300">

* </applet>

*/

You might also like