0

I am new to applet programming. When I run my code in applet viewer its working, but its not working when I ran it in the browser(It shows a blank white web page) Here is my code.

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

    public class BannerApplet extends Applet implements Runnable
     {
        String msg= "A simple moving Banner";
        Thread t=null;
        int state;
        boolean stopFlag;

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

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

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

        }
    }
}

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

       public void paint(Graphics g)
      {
           g.drawString(msg,50,30);
          showStatus("this is a message box");
        }
     }

And here is my html code.

     <!DOCTYPE html>
     <html>
     <title>
        applet window
     </title>`
      <body>
     <applet code="BannerApplet.class" width=300 height=100>
     </applet>
      </body>
    </html>
  • Help me in resolving this issue – Sai Chand Jan 21 '17 at 20:02
  • applets are not supported by some browsers - you should be happy that it runs on the appletviewer you learnt something - then convert it to a regular GUI program – gpasch Jan 21 '17 at 21:15
  • 1) 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/). 2) 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 Jan 22 '17 at 19:53
  • .. 3) 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. – Andrew Thompson Jan 22 '17 at 19:53

1 Answers1

0

No support for Java applet in Chrome since September 2015 (Chrome version 45).

See https://java.com/en/download/faq/chrome.xml

RealHowTo
  • 34,977
  • 11
  • 70
  • 85