Home » Java programs » Java applet programs

Java Applet program to display moving text or content



Here, we are going to write a java applet program that will display moving text (content) on the screen.
Submitted by Chandra Shekhar, on January 11, 2018

Given a message or a text, co-ordinates and the initial state this will help in moving the text using java applet program.

Applet program to display moving text in java

// This java program will move the text using applet.

package Applet;

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

public class MovingContent extends Applet implements Runnable 
{
	// enter message
	String msg = "Welcome to Includehelp.";
	Thread t = null;
	
	// initialize here.
	int state;
	boolean stopFlag;

	// Set colors and initialize text..
	public void init() 
	{
		setBackground(Color.cyan);
		setForeground(Color.red);
	}

	// Start the text....
	public void start() 
	{
		t = new Thread(this);
		stopFlag = false;
		t.start();
	}

	// Entry point which runs the text.
	public void run() 
	{
		char ch;
		
		// Display text reapeated times.
		for( ; ; ) 
		{
			try 
			{
				repaint();
				Thread.sleep(250);
				ch = msg.charAt(0);
				msg = msg.substring(1, msg.length());
				msg += ch;
				if(stopFlag)
					break;
			}
			catch(InterruptedException e) 
			{
				System.out.println(e);
			}
		}
	}

	// Pause the text.
	public void stop() 
	{
		stopFlag = true;
		t = null;
	}

	// Display the text.
	public void paint(Graphics g) 
	{
		g.drawString(msg, 50, 30);
	}
}

Output

Moving text/content in java applet





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.




Comments and Discussions





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.