Select Menu

Combined Post

Mag Posts

Theme images by konradlew. Powered by Blogger.

Blogger templates

Blogger news

Facebook

Advertising

Blogroll

Popular Posts

Combined Posts 2

Mag Post 2

2 Column Post

Simple Post

Simple Post 2

New Carousel

Video Posts

» »Unlabelled » Java code for a SImple Java Banner Applet!


SLVIKI 8:12 PM 0

This is the java code of the simple java banner applet.




/*
 Project 14-1

 A simple banner applet.

 This applet creates a thread that scrolls the message
 contained in msg right to left 
 across the applet's window.
*/

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

/*
<applet code="Banner" width=300 height=50>
</applet>
*/

public class Banner extends Applet implements Runnable {
 String msg = "This is the moving text of this java Banner applet! ";
 Thread t;
 boolean stopFlag;

 // Initialize t to null
 public void init() {
  t = null;
 }

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

 // Entry point for the thread that runs the banner.
 public void run() {
  char ch;

  // Display banner
  for( ; ; ) {
   try {
    repaint();
    Thread.sleep(250);
    ch = msg.charAt(0);
    msg = msg.substring(1, msg.length());
    msg += ch;
    if(stopFlag)
     break;
   } catch (InterruptedException exc) {}
  }
 }

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

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

Here is the sample output of this program.


Enjoy! if you have any questions fell free to ask!

«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply