Archive

Archive for January 24, 2009

Java Program to write an applet with message on Status Bar – Q48

January 24, 2009 Leave a comment

Q48: Java Program to write an applet which displays its code base and document base and show a message on the status bar and display the received parameters which were passed to this applet.

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

public class Ap_Paths extends Applet{
	
	String msg;
	
	public void paint(Graphics g){
	
		URL url_cb = getCodeBase();
		msg = "CodeBase: " + url_cb.toString();
		g.drawString(msg, 20, 30);
		
		URL  url_db = getDocumentBase();
		msg = "Doc. Base: " + url_db.toString();
		g.drawString(msg, 20, 60);
		
	}
}

… from College notes (BCA/MCA assignments):


Advertisement
Categories: Java Tags:

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

January 24, 2009 Leave a comment

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):


Categories: Java Tags: