Applet not working in browser, works with appletviewer

Hi,
I'm trying to use an Applet program from the tutorials which keeps on displaying time in the HTML page:
import java.awt.Graphics;
import java.util.*;
import java.text.DateFormat;
import java.applet.Applet;
public class home_page extends Applet implements Runnable {
    private Thread clockThread = null;
    public void init()
    public void start() {
        if (clockThread == null) {
            clockThread = new Thread(this, "Clock");
            clockThread.start();
    public void run() {
        Thread myThread = Thread.currentThread();
        while (clockThread == myThread) {
            repaint();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e){
            // the VM doesn't want us to sleep anymore,
            // so get back to work
    public void paint(Graphics g) {
        // get the time and convert it to a date
        Calendar cal = Calendar.getInstance();
        Date date = cal.getTime();
        // format it and display it
        DateFormat dateFormatter = DateFormat.getTimeInstance();
        g.drawString(dateFormatter.format(date), 5, 20);
    // overrides Applet's stop method, not Thread's
    public void stop() {
        clockThread = null;
}When i use this program in the browser, i cannot see the clock but i'm able to see only a gray box. I'm using the applet tag within the HTML page.
I can see the same compiled applet running successfully with appletviewer program.
Please help me out of this predicament.
-Manish

I have recently had the same problem, after lots of searching, I found that only Java 1.1 is supported by browsers, leaving out everything else including swing. So if you cant play the applet through your browser you need to download the appropriate patch i think about 5mbs.
You should find one at java.sun.com/getjava/download.html
Mine worked fine afterwards

Similar Messages

  • Applet not viewable in browser

    Hi
    applet not viewable in browser any website that uses java code seems not to run on my browser though it runs normally well on my friends computer. The browser shows a screen area in grey colour with an error message like "Exception: java.lang.ClassNotFoundException:GUIDemo.class" (im using Win NT4 and IE 5.5) checked the tools/internet options/advanced seettings the browser support is enabled. tried installing the newer version of JRE still not working ..Please guide about any settings that need to be modified or how can i fix this problem ..
    Regards
    anant
    [email protected]

    Hi
    Just a thought, but what broswer are you and your friend using? Are they different by any chance?
    There is an inconsistency between browsers and java, and unfortunately it can result in the error you saw.
    Basically, bog standard Internet Explorer uses its own JVM, whereas Netscape, Mozilla, Opera etc tend to use the java plug-in. To make matters worse, if you install the plug-in on a machine that has Internet Explorer installed, it over-rules the Microsoft version to make itself the default (but this can be undone by looking in the Options menu for Java-plugin and un-ticking the box). Give that a try first.
    Another cause that I have encountered was when using NT on a network, which had been configured not to accept Java Applets at all! Are you on such a network, or stand alone?
    Hope that helps.

  • Applet with Image not working in Browser, works fine in Appletviewer

    Hi,
    I encountered a problem , running my Applet in a browser. (IE and Firefox, ame problem).
    When I use an ImageIcon, it doesnot work. in a browser.(When I remove the icon, it's oke)
    In Appletviewer it works fine. In the browser I first got a security-exception.
    I dealed with that by signing the jar (with the test certificate).
    Now the browser's java console is not showin any faults, but the applet is showing no picture at all.
    Only the text of the label is shown.
    Can someone help me?
    I downgraded the class to a very simple form, shown underneath. This runs fine in Appletviewer, but not in a Browser.
    Best Regards
    Remco

    I have recently had the same problem, after lots of searching, I found that only Java 1.1 is supported by browsers, leaving out everything else including swing. So if you cant play the applet through your browser you need to download the appropriate patch i think about 5mbs.
    You should find one at java.sun.com/getjava/download.html
    Mine worked fine afterwards

  • Applet not running in browser?

    Hi
    What is the reason why an applet will be running in appletviewer but not in a browser???

    Hi,
    Try out with this html file:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
    <html>
    <head>
    <title>Example</title>
    <script language="JavaScript">
    function MyToolBar()
    window.open("Login.html","LoginPage","toolbar=0,menubar=0,scrollbar=0,resizable=0,directories=0,width='110%',height='150%'");
    </script>
    </head>
    <body>
    <blockquote>
    <!--"CONVERTED_APPLET"-->
    <!-- CONVERTER VERSION 1.1 -->
    <SCRIPT LANGUAGE="JavaScript"><!--
    var info = navigator.userAgent; var ns = false;
    var ie = (info.indexOf("MSIE") > 0 && info.indexOf("Win") > 0 && info.indexOf("Windows 3.1") < 0);
    //--></SCRIPT>
    <COMMENT><SCRIPT LANGUAGE="JavaScript1.1"><!--
    var ns = (navigator.appName.indexOf("Netscape") >= 0 && ((info.indexOf("Win") > 0 && info.indexOf("Win16") < 0 && java.lang.System.getProperty("os.version").indexOf("3.5") < 0) | | (info.indexOf("Sun") > 0) | | (_info.indexOf("Linux") > 0)));
    //--></SCRIPT></COMMENT>
    <SCRIPT LANGUAGE="JavaScript"><!--
    if (_ie == true) document.writeln('<Center><OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = "100%" HEIGHT = "150%" codebase="http://java.sun.com/products/plugin/1.1.2/jinstall-112-win32.cab#Version=1,1,2,0"><NOEMBED><XMP>');
    else if (_ns == true) document.writeln('<EMBED type="application/x-java-applet;version=1.1.2" java_CODE = "MyApplet.class" WIDTH = "110%" HEIGHT = "150%" pluginspage="http://java.sun.com/products/plugin/1.1.2/plugin-install.html"><NOEMBED><XMP>');
    //--></SCRIPT>
    <APPLET CODE = "MyApplet.class" WIDTH = "110%" HEIGHT = "150%" ></XMP>
    <PARAM NAME = CODE VALUE = "MyApplet.class" >
    </APPLET>
    </NOEMBED></EMBED></OBJECT></Center>
    <!--
    <APPLET CODE = "MyApplet.class" WIDTH = "110%" HEIGHT = "150%" >
    </APPLET>
    -->
    </body>
    </html>
    Hope this will help you.
    Anil
    Developer Technical Support
    Sun Microsystems Inc,
    http://www.sun.com/developers/support

  • Applet not runing in Browser,although it runs in appletviewer.

    Hello! I have created an applet which connects to an Oracle Database executes some queries and after some processing on the data selected it returns the results. When i run the applet using appletviewer everything works fine.(appletviewer -J-Djava.security.policy=C:\folder\mypolicy.java.policy C:\folder\applet2.html is the command i used).
    The code of the HTML file i used is:
    <html>
    <head>
    </head>
    <body>
    <applet code=applet2 archive=applet2.jar width=600 height=600>
    </applet>
    </body>
    </html>
    However when i run the html page(Mozilla Firefox) i get a white page with a frame where Java starts to load and then nothing happens. The frame remains white and i don't see the results that i see when i use appletviewer. I really don't know what is wrong and i would appreciate any answers cause i am new to this.
    Thanx in advance...
    Edited by: lefos987 on May 26, 2009 2:03 PM

    lefos987 wrote:
    appletviewer -J-Djava.security.policy=C:\folder\mypolicy.java.policy C:\folder\applet2.htmlWhen you run it via a browser, how do you propose to get the browser to acknowledge the custom security policy? You can't pass command line arguments to it.
    However when i run the html page(Mozilla Firefox) i get a white page with a frame where Java starts to load and then nothing happens.It likely threw an exception, which you can get the detail of via the browser if you look for something like "Show Java Console".
    Another note: The applet viewer runs in a different security model than browsers do, so if your applet is trying to access resources on the client machine, the browser isn't going to let that happen. In this case, probably it shouldn't be an applet in the first place.

  • Applet not showing in browser OR appletviewer window not appearing

    hi
    1. I have small java code - hello.java
    import java.awt.Graphics;
    public class hello extends java.applet.Applet
    public void paint(Graphics g)
    g.drawString("Hello java...................",600,300);
    which correctly compiled
    2. then I wrote an html file - hello.htm
    <HTML>
    <HEAD>
    <TITLE>HELLO</TITLE>
    </HEAD>
    <BODY>
    <appllet code="hello.class" width=400 height=400>hello not supported
    </appllet>
    </BODY>
    </HTML>
    3. but F:\javacode>appletviewer hello.htm not showing appletviwer window
    command prompt move to F:\javacode>
    4. opend the hello.htm through browser, "hello not supported " appearing instead of applet
    5. both files in same folder
    6. I am using IE8 & firefox (XP sp2)
    wh

    Quite apart from which a String drawn at [600, 300] wouldn't be visible in an Applet of width 400.
    db
    edit
    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
    Edited by: DarrylBurke

  • Firefox not connecting other browser working fine

    I have tried all possible troubleshooting method describe in your site but unable to connect internet. I am using Norton Internet Security V 20.1.2. Please help me.

    hello, normally such issues are caused by a firewall/security software which doesn't recognize & therefore blocks new firefox versions: [[Fix problems connecting to websites after updating Firefox]]

  • Applet not opening in browser  Help needed

    Hi experts,
    I have Java installed in my machine in the path C:\Program Files\Java
    While trying to open the link http://www.radinks.com/upload/applet.php in browser, I am being asked to install the missing plugin and that plugin is java.
    I do not know why this happens and I am stuck with this problem for sometime.
    Any help in this regard will be well appreciated with dukes.
    Thanks in advance,
    Kind Regards,
    Anees

    faheemhameed wrote:
    I have the same issue. But this is on Internet Explorer 8. Firefox is fine.Given the [web page does not validate|http://validator.w3.org/check?uri=http%3A%2F%2Fwww.radinks.com%2Fupload%2Fapplet.php&charset=(detect+automatically)&doctype=Inline&group=0] *(<- link),* I am not surprised it fails in some browsers while working in others. Checking the source of the page itself, I notice the applet is embedded in the page using an OBJECT element only, and that possibly also explains why it works in some browsers but not others.
    The best bet of the author of the web page is to defer writing the applet element to the [deployJava.js|http://java.sun.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html#deplToolkit] *(<- link)* that is provided by Sun.
    Unfortunately there is little that you can do about it, unless you want to attempt creating a page to load off your hard disk, that is valid and workable for IE. I cannot guarantee it will work, but try this variant..
    The altered web page, which can be tested at [http://pscode.org/test/radinks/applet.html].
    <html>
    <body>
    <applet
      code="com.radinks.dnd.DNDAppletPlus"
      archive="dndplus.jar"
      codebase="http://www.radinks.com/upload/"
      width= "290"
      height= "290"
      alt="Java is recognised, but disabled!">
        <param name="url" value = "http://67.131.250.110/upload.php">
        <param name="message" value="http://www.radinks.com/upload/init.html">
        <param name="name" value="Rad Upload Plus">
        <param name="max_upload" value="10000">
        <param name="encode_path" value="yes">
        <param name="translate_path" value="yes">
        <param name="full_path" value="yes">
    This browser does not recognise the Java APPLET element.  Get Java from www.java.com.
    </applet>
    </body>
    </html>

  • Applet to Applet communication in one browser process with 2 windows

    Applet to Applet communication in Same IE process bu in different IE windows
    I have two IE windows
    (1) base window
    (2) child window (created through wondow.open() and hence share the same IE process and same JVM)
    Now I have two applets in one in base window and other is in child window and I want to do applet to applet communication. Since both applets are in different windows so AppletContext will not work and I tried to use custom AppletRegistory class to keep each Applet in static Hashtable. Now here comes the problem, Each applet gets different copy of this static Hashtable. i have tried hard to find the reason why a static varible has multiple copies running in the same JVM. Then my friend told me about something called class loader which is according to him is different for each window. I have tried this with two different iframes but in same window and it works fine and the reason being is that they share the same JVM. But why this fails for different windows althougt they also have same JVM?
    I am using JRE v5 update 7 and IE6 on WIN XP SP2.
    Thanks in advance..

    Try this example :
    Files used :
    1). AppletCom.html
    2). First.java
    3). Second.java
    1).AppletCom.html
    <HTML>
    <BODY bgcolor="#FFFFFF" link="#0000A0" vlink="#000080">
    <LI><H2><I>Inter applet communication Applet</I></H2>
    <applet code=First.class name="theFirst" width=250 height=100></applet>
    <applet code=Second.class width=350 height=100></applet>
    <BR>
    Source First.java Second.java
    <P>
    <HR>
    <i>Last updated 8/5/97 Martin Eggenberger</i>
    <HR>
    </BODY>
    </HTML>
    2). First.java
    import java.awt.*;
    <applet code="First" width="200" height="200">
    </applet>
    public class First extends java.applet.Applet {
    //Variables for UI
    Label lblOutput;
    public void init() {
    //Create the UI
    add(new Label("The First applet."));
    lblOutput = new Label("Click on a button in the Second applet.");
    add(lblOutput);
    public Color getcc()
    return Color.pink;
    public String getnm(int a,int b)
    int cnt=a+b;
    String str;
    str="Sum is :_________"+cnt;
    return str;
    public boolean handleEvent(Event event) {
    if ("One".equals(event.arg)) {
    lblOutput.setText("You clicked: One");
    return true;
    } else if ("Two".equals(event.arg)) {
    lblOutput.setText("You clicked: Two");
    return true;
    } else if ("Three".equals(event.arg)) {
    lblOutput.setText("You clicked: Three");
    return true;
    return super.handleEvent(event); }
    3). Second.java
    import java.awt.*;
    import java.applet.*;
    <applet code="Second.java" width="200" height="200">
    </applet>
    public class Second extends java.applet.Applet {
    //Declare the UI variables
    Button btnOne;
    Button btnTwo;
    Button btnThree;
         Applet f;
    Label lb;
    public void init() {
    //Build the UI
    btnOne = new Button("One");
    add(btnOne);
    btnTwo = new Button("Two");
    add(btnTwo);
    btnThree = new Button("Three");
    add(btnThree);
    lb=new Label("SUNO RE KAHANI TERI MERI SHHHHHHH");
    add(lb);
    setLayout(new FlowLayout());
    // lb.setSize(100,100);
    public boolean handleEvent(Event event) {
    if (event.id == Event.ACTION_EVENT && event.target == btnOne) {
         f = getAppletContext().getApplet(new String("theFirst"));
    First applet1=(First)f;
    // int cnt=applet1.givenum(22,25);
    // String str="Sum is:"+cnt+" Fine";
    String str=applet1.getnm(22,25);
    lb.setText(str);
    Color cl=applet1.getcc();
    setBackground(cl);
    return f.handleEvent(event);
    } else if (event.id == Event.ACTION_EVENT && event.target == btnTwo) {
    f = getAppletContext().getApplet(new String("theFirst"));
    return f.handleEvent(event);
    } else if (event.id == Event.ACTION_EVENT && event.target == btnThree) {
    f = getAppletContext().getApplet(new String("theFirst"));
    return f.handleEvent(event);
    return super.handleEvent(event);
    I had this example, so i am sharing it as it is.. instead of giving you any link for tutorial... hope this helps.
    Regards,
    Hiten

  • Applet not showing in browser/only getting a grey box

    Hell to all....
    I am using a trial version of MS J++ and every time i execute to the browser i dont see my output all i get is a lil grey box on left side with header rules (<hr> tage in HTML) surounding the box. Can anyone help me out???
    if you need my code i will post it.
    Thanks in advance!

    OK ABUSE, check this out
    this is what i'm trying to do....The boss just wants me to connect to our database...and that's it....all i want to do is to see if i can connect to our database....so all the code is suspose to do is say database connected if it did and if it didn't then it should say connection failure...here is the code once again this is the code and that's it....
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.applet.Applet;
    public class Test extends Applet
    public static final String DB_URL = "jdbc:microsoft:sqlserver://<IP HOST>";
    private Connection conn;
    public void init(){
         try {
              DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver() );
              //Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
              this.conn = DriverManager.getConnection(DB_URL, "user", "pass");
              Statement stmt = conn.createStatement();
         catch (SQLException e){
              System.out.println("Cannot open database connection: " + e.getMessage());
         System.out.println("Connected to database");
    hope you understand what i'm trying to do....

  • Applet not showing on browser even if its loaded

    I have created an applet which has some textfields and buttons.
    But when i want to see the applet in browser , it says it has been loaded but shows nothing. i have used swing for applet creation.
    help me out of this.

    What browser? What HTML code?
    Email me and I'll send you an article I've written on this subject. It is NOT as simple as it was 10 years ago.
    You'll need to use <APPLET> for macintosh, <EMBED> for MSIE and <OBJECT> for Netscape/Mozilla/Firefox/Opera. Then you'll need to understand 'code=' (see my reply to CleopatraL).

  • Applet - not rendering n Browser - Mozilla / IE - Help

    Hi,
    I have following code in AnotherHello.html in
    <html>
    <body>
    <applet code="AnotherHello.class" width="300" height="150"></applet>
    </body>
    </html>and the following in AnotherHello.java
    import java.awt.*;
    import java.applet.Applet;
    class  AnotherHello extends Applet
         public void paint(Graphics gr)     
              setBackground(Color.lightGray);
              gr.drawString("Hello", (300/2 - 40/2), (150/2 + 40/2));
    }When I run it using Mozilla or IE it only shows the HTML code in the browser, it does not get me the applet on to the screen. Could somebody help me in figuring out the problem.
    Thanks in advance.

    I have only these two browsers so dont know about
    other browsers.
    No it does not run in applet viewer also.
    I have the class file compiled in the same directory
    as in the java and the html file.
    I am able to see applets from various websites in my
    mozilla browser, which would mean that applet is
    enabled.
    I am not sure what could be the problem.
    Please do let me know.Sounds like it should run then. Maybe it is, but what it's drawing is "invisible" - what about removing that setBackground call, or set it to a different color. If you get a different result, then it is running.

  • Applet not refreshing in browser

    I wrote a HelloWorld applet and viewing it through internet explorer. when i modify the code, compile it, then it replaces the original .class file, but when i refresh the browser, it loads the original applet. when i delete the .class file from the directory, the applet still shows up on the browser after i refresh it. whats going on? and how do i update the applet.

    you hafta CLOSE the browser and then re-open it so the VM sarts up again

  • Why will my applet not run in a browser??

    Hi,
    I have recently converted a swing application to an applet for use on the web. The applet works perfectly when executed with appletviewer in the Command Prompt. However - when i open the html file - the browser tries to load the class but can't - the status bar at the bottom says "sample.class not found".
    My browser is capable of running other applets - and the class file does exist in the same folder.
    Can someone help with this??
    Thanks
    R

    If you have swing in your Java code then you need a
    java plug-in. To test if you have a Java plug-in
    installed go to:
    http://home.comcast.net/~millennm/amex.html
    Without the plug-in the AWT link works. But you need
    the plug-in for the Swing link to work.
    The plug-in is at:
    http://java.sun.com/j2se/1.3/download.html","Java_Runti
    e_Environment
    hi, excuse me...
    How can I write a plug-in needless Applet?
    After I browse the sample of the above article, I think that it seems if my Applet didn't use swing , it will not need to download a Java plug-in when it execute in a browser. But my Applet still need to download a plug-in, why?
    Here is my sample code:
    /* sample code start */
    import java.awt.*;
    import java.applet.*;
    public class test1 extends Applet
    public void paint(Graphics g)
    g.drawString("I'm Here!",160,80);
    /* sample code end */
    And here is my html code:
    <!-- html code start -->
    <applet code=test1.class width=320 height=100>
    </applet>
    <!-- html code end -->
    thank you very much.

  • Midi synthesizer applet working with appletviewer , but no in IE browser

    Hi ,
    The following code works OK using appletviewer , but not working with IE browser . The user can play notes from C to G , using the corresponding keyboard keys (only when typing small A,B,C,D,E,F or G , a corresponding midi note would be produced) .
    When running it using appletviewer , the notes are being heard ;
    this isn't the case when running the applet using IE browser (after removing the security warning (of showing active content) - here , the applet simply doesn't respond to the key events .
    The code is :
    import java.awt.event.*;
    import javax.swing.*;
    import javax.sound.midi.*;
    public class RandomNotes extends JApplet implements KeyListener
         private MidiChannel midiChannel;
         private int note ;
         private long timeWhilePress;
         private long timeAfterPress;
         private int firstTime = 0;
         public void start()
              try
                   Synthesizer synthesizer = MidiSystem.getSynthesizer();
                      synthesizer.open();
                  midiChannel = synthesizer.getChannels()[0];
              catch(Exception ex)
                   ex.printStackTrace();
              addKeyListener(this);
         public void keyPressed(KeyEvent e)
              firstTime++;
              switch (e.getKeyChar())
                   case 'c':
                        note = 60;
                        break;
                   case 'd':
                        note = 62;
                        break;
                   case 'e':
                        note = 64;
                        break;
                   case 'f':
                        note = 65;
                        break;
                   case 'g':
                        note = 67;
                        break;
                   case 'a':
                        note = 69;
                        break;
                   case 'b':
                        note = 71;
                        break;
                   default:
                        note = -1;
                        break;
              timeWhilePress = System.currentTimeMillis();
              if (firstTime == 1)
                   midiChannel.noteOn(note, 127);
         public void keyReleased(KeyEvent e)
              timeAfterPress = System.currentTimeMillis();
             try
                   Thread.currentThread().sleep(timeAfterPress - timeWhilePress);
              catch (InterruptedException exception)
                   exception.printStackTrace();     
            midiChannel.noteOff(note);
            firstTime = 0;
         public void keyTyped(KeyEvent e)
    }Why it runs OK using appletviewer and not under IE browser , and how can I correct the problem please , so under IE browser , the applet should respond to key events ?
    Thanks in advance ,
    Lior .

    The problem is related to the Midi itself , not to the keyPressed event - I've just checked it :
    If I add a JOptionPane.showMessageDialog(null,"Lior"); statement
    as the first line of the keyPressed method ,
    then also when running the applet under IE browser , when clicking on any letter character (eg. "j") , I see the "Lior" message appears on screen . So the problem is not with the keyboard event handling , but something related to the Midi itself .
    If you don't mind , I should post this question also in the Java sound forum (unless this is considered a crosspost , then I'll not do that) .
    Thanks in advance ,
    Lior .

Maybe you are looking for

  • Which is Better VBR or 256kps?

    I have two identical downloads of an album (don't ask)...  However, one uses VBR to store the mp3s and the other is straight 256kps.  The VBR goes up and down in bit rate; Sometimes it's over 256kps and other times it goes below 256kps on certain son

  • Vendor Reconcillation Account

    Dear Gurus, While posting invoice , As we know that during the Invoice GR/IR is Debited and Vendors account credited. I want to know how does the system select which vendor account is to be credited?? e.g If A1000 is my vendor do i have to create the

  • ColdFusion.navigate and unvisited tabs

    I have created a cflayout (type = border). Naturally, I have a nifty left side menu, which outputs a query result as a text. In the center layoutarea, I have a new layout of two tabs. The tabs are named projectOverview and projectTickets A link in th

  • Convert float to integer

    how to convert float to integer? and convert it back from integer to float?

  • EP6 to EP7 migration

    I am proposing to migrate from EP6 SP2 to EP7 but I have been told that I first need to migrate to WAS 6.40. Is this necessary? My gut feel is to install EP7 and then just export all the portal objects I need from EP6 SP2 into EP7. Patrick