You are here: Home / Topics / Program with param tag in applet tag in Java

Program with param tag in applet tag in Java

Filed under: Java on 2023-09-20 06:38:12

//  Program with param tag in applet tag.

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

/*
<applet code="Applet06" width="300" height="50">
<param name="message" value="Java makes the Web move!">
</applet>
*/

public class  Applet06 extends Applet implements 
Runnable 
{
String msg;
Thread t = null;
boolean flag;

public void init() 
{
 setBackground(Color.yellow);
 setForeground(Color.red);
}

public void start() 
{
 msg = getParameter("message");
 if(msg == null) msg = "Message not found.";
 msg = " " + msg;
 t = new Thread(this);
 flag = false;
 t.start();
}

public void run() 
{
 char ch;
 for( ; ; ) 
 {
  try 
  {
   repaint();
   Thread.sleep(250);
   ch = msg.charAt(0);
   msg = msg.substring(1, msg.length());
   msg += ch;
   if( flag )
    break;
  } 
  catch(InterruptedException e) 
  { }
 }
}

public void stop() 
{
 flag = true;
 t = null;
}

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


Output:

D:\Java>appletviewer Applet06.java

About Author:
M
Mr. Dubey     View Profile
Founder and CEO of MCQ Buddy. I just like to help others. This portal helps students in getting study material free.