Advertisements
Home > Java > Java Program to display a moving banner on the applet window – Q47

Java Program to display a moving banner on the applet window – Q47


Q47: Java Program to display a moving banner on the applet window.

import java.applet.*;
import java.awt.*;

public class Ap_Banner extends Applet implements Runnable{
	
	String msg = "My name is Manoj Pandey";
	Thread th;
	int state;
	boolean stopflag;
	
	public void init(){
		setBackground(Color.blue);
		setForeground(Color.yellow);
	}
	
	public void start(){
		th = new Thread(this);
		stopflag = false;
		th.start();
	}
	
	public void run(){
		char ch;
		for(;;){
			try{
				repaint();
				Thread.sleep(500);
				ch = msg.charAt(0);
				msg = msg.substring(1, msg.length());
				msg += ch;
				if(stopflag) break;
			}
			catch(InterruptedException e){
			}
		}
	}
	
	public void sleep(){
		stopflag = true;
		th = null;
	}
	
	public void paint(Graphics g){
		g.drawString(msg, 50, 50);
	}
}

… from College notes (BCA/MCA assignments):


Advertisements
Categories: Java Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: