Q:

Java Applet program to display moving text or content

0

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

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now