0

This is my applet code for a moving banner .It is working properly but there is one doubt .

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

 /*<html>
  <applet code ="SimpleBanner" width="2000" height="2000"></applet></html>*/

 public class SimpleBanner extends Applet implements Runnable{
    String msg=" A Simple Banner Is Moving";
 boolean flag=false;
 Font f=new Font("TimesRoman",Font.BOLD,50);
 int i=10;
public void init()
{
    setBackground(Color.gray);
   setFont(f);
    setForeground(Color.green);
}
public void start()
{
    Thread t=new Thread(this);
    t.start();
}
public void run()
{
    for(;;)
    {
    try{
        repaint();
        if(flag)
            break;
        Thread.sleep(250);
    }catch(InterruptedException e){}
    }
}
public void paint(Graphics g)
{
    char ch=msg.charAt(0);
    msg=msg.substring(1,msg.length());
    msg+=ch;
    drawString(msg,300,100);
}
public void stop()
{
    flag=true;
}
}

As you can see I am not extending Graphics class and I am using setFont() method defined in Graphics class without its object how this is possible? And if I try to call drawString() method in paint() method without g it is not working.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Shubham Tyagi
  • 181
  • 1
  • 3
  • 14
  • 1) Why use AWT? See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT components in favor of Swing. 2) Why code an applet? If it is due to the teacher specifying it, please refer them to [Why CS teachers should **stop** teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). .. – Andrew Thompson Mar 16 '17 at 02:11
  • .. 3) See [Java Plugin support deprecated](http://www.gizmodo.com.au/2016/01/rest-in-hell-java-plug-in/) and [Moving to a Plugin-Free Web](https://blogs.oracle.com/java-platform-group/entry/moving_to_a_plugin_free). – Andrew Thompson Mar 16 '17 at 02:11

0 Answers0