Altering Applet Lifecycles

Hi all,
We've coded a large application and I've deployed it as an applet over the web. The problem is when a user clicks the refresh button or the back button on the browser. The applet's destroy method is called and then the init method and the applet is reloaded. Is there any way to stop an applet from being unloaded when you refresh or move off a page. We would like the applet to continue running in memory and maintain its state to repaint itself for when the user returns to the applet page.
If the browser was closed we would obviously want to unload the applet at that point.
Thanks in advance,
Phillip Urrea

Sorry, I meant to mention that I'm using the Java Plugin 1.3.1_02

Similar Messages

  • Altering Applet Security

    -I have been lead to belive that the security policy file for an applet simply sits in the same (default)
    directory with the applet, on the web server (eg. Apache). Can someone else reply to confirm this or
    otherwise?
    Besides that, I also observe that the programmer available api in java 1.6 there is a Permission file,
    which may be instantiated with relevant String data, which may then be sent to
    a PermissionCollection class.
    I furthermore know that I can do privileged actions past the default security policy,
    using the appropriate doPrivileged method inside AccessController with an adapted
    *(implemented) PrivilegedAction style class.*
    I am in fact trying to alter these security policies without applet signing or using a policy file,
    which to some extent is possible (say with AccessController).
    Can someone else please tell me how I can instantiate a Permission object with non-default
    security settings for a java applet, and have my java runtime observe these new settings
    and let me act accordingly with them, even outside the default java sandbox?
    (How to do policy file changes without the policy file or applet signing at all)?

    I have been lead to belive that the security policy file for an applet simply sits in the same (default) directory with the applet
    Re: Java Applet Sandbox options., you have been misled about this.
    -Nevertheless, it is a way to performed security forbidden actionsNo. It is a way to perform actions that aren't permitted to the current codebase but that are permitted to a codebase lower down on the call stack.
    -When I do use a custom policy file on an applet, (say when using apache webserver), and I don't want to sign the applet,
    my policy file will be actioned if it is left in the same default directory as my applet jar. Correct?
    Re: Java Applet Sandbox options., no. This is pure fiction. The policy file is at the client, installed with the JDK, controlled by the client. That's the whole point of the mechanism.
    I understand that in java code, I can create a Permisson object (or multiple ones) with the correct subclass of Permission
    and the correct intended String settings inside that Permission object.You can but it won't do you any good.
    How do I submit a permission object to the static policy object method, or event a default ProtectionDomain object?
    Re: Java Applet Sandbox options., you don't.
    so that the java runtime detects them and updates actionable security options? Where is the class to do this,
    and where is the class/method to call to get the system's present instance of that class?
    Re: Java Applet Sandbox options., they don't exist. If they did, the entire mechanism would be pointless. Re: Java Applet Sandbox options., the Permission and PermissionCollection classes are there for use by the security manager.
    How many times do you need to be told all this exactly?

  • Applet needs browser to be restarted ?!?

    Hi again.. thats the problem:
    1) I open FireFox2
    2) i go to the Applet Page and make it start -> OK it works...
    3) i close the Applet Page -> shutdown seems to be clear...
    4) i go to the Applet Page and make it start -> it loads very quickly but it is unresponsive
    5) i close all FireFox2 instances
    6) i go to the Applet Page and make it start -> OK it works again..
    the same is for IE7... any ideas?
    thanks in advice.

    You seem to be running afoul of the applet lifecycle somehow.
    Perhaps something that should be in start() you've placed in init() or in the constructor.

  • Applet reloaded : IE 7/8 problem only

    Hello all,
    I have this very weird issue with an applet : it does not stop reloading.
    More precisely, in IE, my applet is loaded in an ajax loaded DOM element. When I remove the DOM element : stop() is first invoked by the browser, but start() follows just after... !!!
    I have tried System.exit() in the destroy method, but depending on the browser and the java version, that may kill the browser itself.
    Has anyone encountered the same issue ? How can one properly dispose of the applet instance ?
    Thanks in advance for your replies.
    Anthony C.

    You may find the solution here:
    http://java.sun.com/docs/books/tutorial/deployment/applet/lifeCycle.html

  • Constructor in applet?

    hi.....
    Can we do provide constructor in an applet for initialization or can applet support constructor?
    regards.

    What?
    Applets need to have a no-arg constructor, and they also have an init() method and a start() method. There's some documentation online, probably within the tutorials on java.sun.com as well, that describe the applet lifecycle. You should read it.

  • Servlet/applet/socket problem

    Hi there,
    my problem is this...
    i create a page with an servlet whicht shows an applet. this applet connects to a server through an socket. it works fine, but, when i change the page and the applet is not longer on the screen, the socket connection will be not killed! i dont know why. but i must kill it when the applet is not longer on the screen...whats wrong? can you help me?
    matthias

    Are you overriding the destroy() method in your Applet? This will be called when the applet is about to be unloaded from the browser. Or, as a slightly different alternative, you can override the stop() method, which is called when the applet is scrolled off the screen. Usually when stop() is used, start() is overriden as well to allow the applet to resume when it is scrolled back into view. For more info, read up on the applet lifecycle.

  • Is it possible to rewrite  any applet to aplications ?

    I am wondering, is it possible to rewrite any applet to aplications ?
    dows everything works ? then ?
    look at this applet and please rewrite it to aplication if it works, I have tried but some sound did not work. and lots of other thigs went wrong.
    import java.awt.*;
    import java.util.*;
    import java.applet.*;
    public class PongBall
         // Variablen
         private int x_pos;               // x - Position des Balles
         private int y_pos;               // y - Position des Balles
         private int x_speed;          // Geschwindigkeit in x - Richtung
         private int y_speed;          // Geschwindigkeit in y - Richtung
         // Positionen
         private int ball_top;          // Obergrenze des Balles
         private int ball_bottom;     // Untergrenze des Balles
         private int ball_left;          // Linke Grenze des Balles
         private int ball_right;          // Rechte Grenze des Balles
         private int comp_top;          // Oberkante des Computerpaddels
         private int comp_bottom;     // Unterkante des Computerpaddels
         private int comp_right;          // Rechte Seite des Computerpaddels
         // Spielfeld (Radius des Balles mit eingerechnet)
         private static final int right_out = 390;
         private static final int left_out = 10;
         private static final int down_out =290;
         private static final int up_out = 10;
         private static final int radius = 10;               // Ballradius
         public PongBall (int x_pos, int y_pos)
              this.x_pos = x_pos;
              this.y_pos = y_pos;
              x_speed = 3;
              y_speed = 3;
         public void move ()
              x_pos += x_speed;
              y_pos += y_speed;
              isBallOut();
         public void isBallOut ()
              // Ball bewegt sich nach links
              if (x_speed < 0)
                   if (x_pos < left_out)
                        // Geschwindigkeit umdrehen
                        x_speed = - x_speed;
              // Ball bewegt sich nach rechts
              else if (x_speed > 0)
                   if (x_pos > right_out)
                        // Geschwindigkeit umdrehen
                        x_speed = - x_speed;
              // Ball bewegt sich nach oben
              if (y_speed < 0)
                   if (y_pos < up_out)
                        y_speed = - y_speed;
              // Ball bewegt sich nach unten
              else if (y_speed > 0)
                   if (y_pos > down_out)
                        y_speed = - y_speed;
         public void testForCollisionComputer (ComputerKI computer)
              // Initialisierung der Ballpositionen
              ball_top = y_pos - radius;
              ball_bottom = y_pos + radius;
              ball_left = x_pos - radius;
              ball_right = x_pos + radius;
              // Initialisierung der momentanen Positionen des Paddels
              comp_top = computer.getYPos();
              comp_bottom = computer.getYPos() + computer.getYSize();
              comp_right = computer.getXPos() + computer.getXSize();
              // Ist die Y - Position des Balles zwischen den Paddelpositionen?
              if ((ball_top >= comp_top - radius) && (ball_bottom <= comp_bottom + radius))
                   // Ist Paddel in der N�he?
                   if (ball_left <= comp_right)
                        // Normales Bouncen
                        x_speed = - x_speed;
         public int getXSpeed ()
              return x_speed;
         public int getYPos ()
              return y_pos;
         public void paint (Graphics g)
              g.setColor (Color.red);
              g.fillOval (x_pos - radius, y_pos - radius, 2 * radius, 2 * radius);
    import java.awt.*;
    import java.util.*;
    import java.applet.*;
    import java.net.*;
    public class Main extends Applet implements Runnable
         // Variablen
         // Thread
         Thread thread;
         // Ball
         PongBall ball;
         // Computerpaddel
         ComputerKI computer;
         // Doppelpufferung
         private Image dbImage;
         private Graphics dbg;
         public void init(){
              setBackground (Color.black);
              ball = new PongBall (200,200);
              computer = new ComputerKI (200, ball);
         public void start(){
              thread = new Thread (this);
              thread.start();
         public void stop(){
              thread.stop();
         public void run(){
              // Erniedrigen der ThreadPriority um zeichnen zu erleichtern
              Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
              while (true)
                   // Neumalen des Fensters
                   repaint();
                   ball.move();
                   computer.move();
                   if (ball.getXSpeed() < 0){
                        ball.testForCollisionComputer(computer);
                   try
                        // Stoppen des Threads f�r 10 Millisekunden
                        Thread.sleep (10);
                   catch (InterruptedException ex)
                        break;
                   // Zur�cksetzen der ThreadPriority auf Maximalwert
                   Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
         public void paint(Graphics g){
              ball.paint(g);
              computer.paint (g);
         /** Update - Methode, Realisierung der Doppelpufferung zur Reduzierung des Bildschirmflackerns */
         public void update (Graphics g)
              // Initialisierung des DoubleBuffers
              if (dbImage == null)
                   dbImage = createImage (this.getSize().width, this.getSize().height);
                   dbg = dbImage.getGraphics ();
              // Bildschirm im Hintergrund l�schen
              dbg.setColor (getBackground ());
              dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
              // Auf gel�schten Hintergrund Vordergrund zeichnen
              dbg.setColor (getForeground());
              paint (dbg);
              // Nun fertig gezeichnetes Bild Offscreen auf dem richtigen Bildschirm anzeigen
              g.drawImage (dbImage, 0, 0, this);
    import java.awt.*;
    import java.util.*;
    import java.applet.*;
    class ComputerKI
         /** Diese Klasse Implementiert die Bewegungen des Computers und zeichnet auch die
         Computerpaddel */
         // Deklaration der Variablen
         private int y_pos;                         // y - Position des Paddels
         private int y_speed;                    // Geschwindigkeit in y - Richtung
         private int real_y_pos;                    // Speichert die wirkliche Paddelposition (Mitte)
         // Konstanten
         private static final int x_pos = 15;     // x - Position des Paddels
         private static final int size_x = 10;     // Gr��e des Paddels in x - Richtung
         private static final int size_y = 50;     // Gr��e des Paddels in y - Richtung
         // Ball
         private static PongBall ball;
         // Construktor
         public ComputerKI (int y_pos, PongBall ball)
              this.y_pos = y_pos;
              y_speed = 4;
              this.ball = ball;
         /** Diese Methode bewegt das Paddel */
         public void move ()
              // Mitte des Paddels
              real_y_pos = y_pos + (size_y / 2);
              // Wenn sich Ball von Paddel wegbewegt, werden die Paddel in die Mitte zur�ckbewegt
              if (ball.getXSpeed() > 0)
                   // Paddel oberhalb der Mitte
                   if (real_y_pos < 148)
                        y_pos += y_speed;
                   // Paddel unterhalb der Mitte
                   else if (real_y_pos > 152)
                        y_pos -= y_speed;
              else if (ball.getXSpeed() < 0)
                   // Solange Paddel nicht auf H�he des Balles ist wird es bewegt
                   if ( real_y_pos != ball.getYPos())
                        // Ball oberhalb von Paddel
                        if (ball.getYPos() < real_y_pos)
                             y_pos -= y_speed;
                        // Ball unterhalb von Paddel
                        else if (ball.getYPos() > real_y_pos)
                             y_pos += y_speed;
         public int getXPos()
              return x_pos;
         public int getYPos()
              return y_pos;
         public int getXSize()
              return size_x;
         public int getYSize()
              return size_y;
         /** Diese Methode zeichnet das Paddel */
         public void paint (Graphics g)
              g.setColor (Color.blue);
              g.fillRect (x_pos, y_pos, size_x, size_y);
    }

    I tryed .. but couldent make it...
    there where not suck thing as MyStub and MyApplet..
    I know I sould replace it with something else.. but I
    did not know WHAT !!
    please help.
    MyStub stub = new MyStub();
    Applet a = new MyApplet();Ok this will be a bit longer post, but it contains fully functional example, simply copy-paste 200 lines of code to single .java file in your favourite IDE and explore it a bit.
    Please take note of that this is only example. It's design have several flaws:
    - user interface is tightly coupled wih applet stub/context. in real world application IMHO applet stub/context belong to application model (where 'application' means "MyAppletContainer") whereas JDesktop and JInternalFrame are part of view (from MVC pattern).
    - applet lifecycle is implmeneted very carelessly. in this example applet is initialzied and started uppon adding to JDesktop and stoped when JInternalFrame is removed from desktop
    - codeBase and documentBase properties of AppletStub are not set. see javadoc pages mentioned few lines below, for more information about this two properties.
    - some methods in applet context throws UnsupportedOperationException (e.g. getAudioClip) because they are beyond scope of simple example or not really necessary (e.g. mentioned getAudioClip). Another approach is return null instead or leave empty body for methods with void return type.
    Before studying sample code you should take a look on applet stub/context declaration in java api. visit url: http://java.sun.com/j2se/1.5.0/docs/api/java/applet/AppletStub.html and http://java.sun.com/j2se/1.5.0/docs/api/java/applet/AppletContext.html
    Because this sample is nothing else than briefly scratched one possible implementation of these two interfaces.
    Sample:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.beans.*;
    import java.io.*;
    import java.net.URL;
    import java.util.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class Main {
        public static void main(String[] args) throws Exception {
            final MyContext context = new MyContext();
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    context.setVisible(true);
        /** Create sample applet */
        public static Applet createApplet() {
            JApplet applet = new JApplet() {
                public void init() {
                    showStatus("Another applet initialized");
            applet.add(new JLabel("I am applet"));
            return applet;               
    /** Single applet stub */
    class MyStub extends JInternalFrame implements AppletStub {       
        /** Create new applet stub*/
        public MyStub(Applet applet, MyContext context) {
            // Setup applet
            this.applet = applet;
            this.context = context;
            applet.setStub(this);
            add(applet);
        /** Owned applet */
        Applet applet;
        /** Context who own this stub */
        MyContext context;
        /** Applet document base */
        URL documentBase;
        /** Applet code base */
        URL codeBase;   
        /** Applet parameters */
        final Map<String, String> param =
                new HashMap<String, String>();   
        /** ##AppletStub##
         * Applet is active whenever frame
         * is selected for example.
        public boolean isActive() {
            return ((JInternalFrame)this).isSelected();
        /** ##AppletStub## */
        public URL getDocumentBase() {
            return documentBase;
        /** ##AppletStub## */
        public URL getCodeBase() {
            return codeBase;
        /** ##AppletStub## */
        public AppletContext getAppletContext() {
            return context;
        /** ##AppletStub## */
        public void appletResize(int width, int height) {
            // allow resize as needed
            setSize(width,height);
        /**##AppletStub## */
        public String getParameter(String name) {
            return param.get(name);
    /** Main application frame and applet context */
    class MyContext extends JFrame implements AppletContext {
        /** Named InputStreams */
        private Map<String,InputStream> streams =
                new HashMap<String, InputStream>();
        /** All applet stubs */
        private Map<String, MyStub> applets =
                new HashMap<String, MyStub>();
        /** Applets as enumeration */
        private Vector<Applet> appletsEnum =
                new Vector<Applet>();
        /** Ui applet container */
        private JDesktopPane jAppletPane =
                new JDesktopPane();
        /** Status line */
        private JLabel jAppletStatus =
                new JLabel("Add first applet");
        /** Create context */
        public MyContext() throws PropertyVetoException {
            // Create ui
            setSize(600,400);
            setDefaultCloseOperation(EXIT_ON_CLOSE);       
            setLayout(new BorderLayout());
            add(jAppletPane, BorderLayout.CENTER);
            add(jAppletStatus, BorderLayout.SOUTH);
            add(new JButton(new AbstractAction("Add applet") {
                public void actionPerformed(ActionEvent e) {
                    doAddApplet();
            }), BorderLayout.NORTH);
            // Very simple applet lifecycle implementation
            // Applet is initialized and started when added and
            // stopped and destroyed when removed from content pane
            jAppletPane.addContainerListener( new ContainerListener() {
                public void componentAdded(ContainerEvent e) {
                    Component c = e.getChild();
                    if (!(c instanceof MyStub))
                        return ;
                    Applet applet = ((MyStub)c).applet;
                    applet.init();
                    applet.start();
                public void componentRemoved(ContainerEvent e) {
                    Component c = e.getChild();
                    if (!(c instanceof MyStub))
                        return ;
                    Applet applet = ((MyStub)c).applet;
                    applet.stop();
                    applet.destroy();
        /** Add applet action body */
        private void doAddApplet() {
            // Create some arbitrary applet and name
            Applet applet = Main.createApplet();
            String appletName = "Applet "+System.currentTimeMillis();
            // Add applet and its stub to this container
            MyStub stub = new MyStub(applet, this);
            applets.put(appletName, stub);
            appletsEnum.add(applet);
            // Add to ui
            jAppletPane.add(stub);
            stub.setSize(400,300);
            stub.setVisible(true);
        /** ##AppletContext## */
        public Iterator<String> getStreamKeys() {
            return streams.keySet().iterator();
        /** ##AppletContext## */
        public void setStream(String key, InputStream stream)
        throws IOException {
            streams.put(key, stream);
        /** ##AppletContext## */
        public InputStream getStream(String key) {
            return streams.get(key);
        /** ##AppletContext## */
        public Enumeration<Applet> getApplets() {
            return appletsEnum.elements();
        /** ##AppletContext## */
        public Applet getApplet(String name) {
            MyStub stub = applets.get(name);       
            return stub == null? null: stub.applet;
        /** ##AppletContext## */
        public Image getImage(URL url) {
            try {
                return ImageIO.read(url);
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this,
                        "IOException: "+ex.getMessage());
                return null;
        /** ##AppletContext## */
        public AudioClip getAudioClip(URL url) {
            throw new UnsupportedOperationException();
        /** ##AppletContext## */
        public void showStatus(String status) {
            jAppletStatus.setText(status);
        /** ##AppletContext## */
        public void showDocument(URL url, String target) {
            throw new UnsupportedOperationException();
        /** ##AppletContext## */
        public void showDocument(URL url) {
            showDocument(url, null);
    }Hope this will help a bit.
    ~~
    Adam
    Message was edited by:
    a3cchan
    When I've modified Main.createApplet() to create Your Pong applet I was able to create and run your applet in my simple container with just little glitches (mostly related to my simplistic implementation of ui).
    If you wish to 'convert' applet to swing application, You don't have use JDesktop. Add single applet to the frame instead. It should be quite simple from given example.

  • JBDC problem in Java 1.3 Applet

    I am using win2000, oracle 9i, JDBC driver for Oracle 8.17, Java 1.3.
    When I programmed a JDBC application, works fine. When I transfers that to applet, I got "java.NoClassDefFound: oracle.jdbc.driver.OracleDriver()"
    But it is configured in the CLASSPATH and applications can find it.
    This is the relative code:
    DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
    BTW whne I use Visual cafe and configure that in Environment setting. It works.
    So tthe proble seems to be: [JAVA]/bin/ appletViewer.exe didn't go to the windows OS to look at the CLASSPATH, right? (But it can find the classes in the same package!)
    Thanks for any comments.
    null

    You'll only see something in the console/log if something is put there. :)
    It will capture any output to System.out and System.err, includiing stack traces. But if your application doesn't put messages on these channels, and no exceptions are thrown, you won't see anything (of value) in the log.
    You had mentioned your application is 'freezing'. This could be caused by a number of things that wouldn't result in a stack trace. It could be a thread deadlock/starvation. You could be blocking on a resource that isn't getting loaded. There may be a badly implemented Applet lifecycle method that's causing the browser JVM to choke.
    Without being able to replicate this, or change the code, I'm afraid you're in for some major headaches. :(

  • Applet as EJB client error

    hello
    Is it possible to invoke EJB's from signed applets ?
    I have signed weblogic.jar and jar of my applet.
    APPLET CODE="MyApplet.class" ARCHIVE="MyAppletArchive.jar,weblogic.jar"
    WIDTH=600 HEIGHT=400
    When applet tries to invoke EJB it throws exception:
    java.lang.ClassNotFoundException: weblogic.jndi.internal.ServerNamingNode_WLStub
    I think that applet cannot load stub class from server because of security restrictions.
    Do you know how to solve the problem ?
    thanx
    Maris

    Hello Maris,
    This particular issue that you are facing is mentioned in the WLS documentation.
    Basically, you have to take caution when running ejbc (-disableHotCodeGen), and
    avoiding the ClassNotFoundException by accessing the InitialContext in only the
    thread that deals with applet lifecycle methods (such as start, stop, init, destroy).
    Please see the following link for more information:
    http://e-docs.bea.com/wls/docs70/applets/usingapplets.html#1075866
    Best regards,
    Ryan LeCompte
    [email protected]
    http://www.louisiana.edu/~rml7669
    "Maris Orbidans" <[email protected]> wrote:
    >
    hello
    Is it possible to invoke EJB's from signed applets ?
    I have signed weblogic.jar and jar of my applet.
    APPLET CODE="MyApplet.class" ARCHIVE="MyAppletArchive.jar,weblogic.jar"
    WIDTH=600 HEIGHT=400
    When applet tries to invoke EJB it throws exception:
    java.lang.ClassNotFoundException: weblogic.jndi.internal.ServerNamingNode_WLStub
    I think that applet cannot load stub class from server because of security
    restrictions.
    Do you know how to solve the problem ?
    thanx
    Maris

  • What can be done to make these code examples work on web Browsers?

    I have tried numerous versions of ?Hello World? examples over the web to display the text on a web page. All the examples work on my local machine in the application viewer, but they don?t work when from a web browser. I have tried both Firefox and IE.
    Some of them include:
    [http://java.sun.com/docs/books/tutorial/uiswing/examples/start/HelloWorldSwingProject/src/start/HelloWorldSwing.java|http://java.sun.com/docs/books/tutorial/uiswing/examples/start/HelloWorldSwingProject/src/start/HelloWorldSwing.java]
    Firefox error:
    java.lang.reflect.InvocationTargetException
         at com.sun.deploy.util.DeployAWTUtil.invokeAndWait(Unknown Source)
         at sun.plugin2.applet.Plugin2Manager.runOnEDT(Unknown Source)
         at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
         at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.ClassCastException: start.HelloWorldSwing cannot be cast to java.applet.Applet
         at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
         at java.awt.event.InvocationEvent.dispatch(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    Exception: java.lang.reflect.InvocationTargetException [http://en.wikipedia.org/wiki/Swing_%28Java%29|http://en.wikipedia.org/wiki/Swing_%28Java%29]
    Error when viewed on Firefox:
    java.lang.reflect.InvocationTargetException
         at com.sun.deploy.util.DeployAWTUtil.invokeAndWait(Unknown Source)
         at sun.plugin2.applet.Plugin2Manager.runOnEDT(Unknown Source)
         at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
         at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.ClassCastException: start.SwingExample cannot be cast to java.applet.Applet
         at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
         at java.awt.event.InvocationEvent.dispatch(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    Exception: java.lang.reflect.InvocationTargetException An Ideal Code if someone could decipher why it fails from a browser is:
    import javax.swing.*;
    public class SwingHelloWorld extends JFrame {
        public SwingHelloWorld(String name) {
          super(name);
          this.setDefaultCloseOperation(EXIT_ON_CLOSE);
          JLabel label = new JLabel(name);
          // label.setPreferredSize(new Dimension(210, 80));
          this.getContentPane().add(label);
          this.pack();
          this.setVisible(true);
      public static void main(String argv[]) {
            SwingHelloWorld swingHelloWorld = new SwingHelloWorld("This would be great if it worked via a browser!");
    } Error from Firefox:
    java.lang.reflect.InvocationTargetException
         at com.sun.deploy.util.DeployAWTUtil.invokeAndWait(Unknown Source)
         at sun.plugin2.applet.Plugin2Manager.runOnEDT(Unknown Source)
         at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
         at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.RuntimeException: java.lang.InstantiationException: start.SwingHelloWorld
         at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
         at java.awt.event.InvocationEvent.dispatch(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.lang.InstantiationException: start.SwingHelloWorld
         at java.lang.Class.newInstance0(Unknown Source)
         at java.lang.Class.newInstance(Unknown Source)
         ... 9 more
    Exception: java.lang.reflect.InvocationTargetException The latter code is very short and would serve the intended purpose most ideal. It can accept input and allow me to replace the ?System.out.println? function that works so well to display when working with code in the development environment.
    Thanks in advance for any input on this.
    -- L. James
    L. D. James
    Edited by: apollothethird on Mar 8, 2010 5:05 AM

    paulcw wrote:
    As per your suggestion, I changed the &#147;extend&#148; to Applet and changed it to &#147;JApplet&#148;. Making that change will result in code that won?t even compile.Right. You're going to have to change your program to actually work as an applet.
    Either that or use Java Web Start, which is probably the best option.Thanks. The code I presented was my attempt to find examples that represented the advice I thought I was getting (to use JFrame and JLabels). I?m changing the direction of the examples I?m looking for now.
    >
    The current code as published by sun.com actually compiles and displays in the Netbeans programming environment. It looks great. But I?m kind of stuck with the missing link for making it output to the browser.Different things work in different ways. You wrote a standalone application which compiles and runs. Writing an applet is a different thing, and works in a different way. Read the applet tutorials for more information on applet methods and the applet lifecycle.Thanks. I?m reading. I try to execute some of the examples from my reading, but and stuck. So, I?m asking for some clarifications of some of the components I?m stuck with. Having some of my questions answered would help me to understand better the lots of reading and studying that I?m doing.
    I?m taking in all the advice that is given, and I appreciate it a lot.
    >
    Thanks for the hints. Thanks also in advance if you happen to know how to change the extend to Applet or JApplet instead of &#147;JFrame&#148; and it works.This is made clear in the applet tutorials. It's more than just changing the class to extend. Note that Applet/JApplet extends Panel/JPanel, so that changes the way your program is constructed. Basically, you don't have to create your own frame.Also, I don?t want a frame. I?m trying to find a way to make my question clear. I appreciate the time you?re taking to respond to a new user?s scope.
    >
    But again, web start is probably a better choice if you have a running app.
    You should probably abandon the idea that you just have to nudge a program slightly in a new direction to make a wholly new thing. Programming is all about reducing complex problems to a set of concrete solutions.Absolutely. I have some examples that will actually print a string to a browser. However, those examples will print what?s written in the immediate code, with no apparent method (that I can) make into a variable. The ?Hello World? example that I find that has a main class is the ones that are failing. The ones that don?t have a main class will print.
    I have been trying to find a way to pass a variable to this code that will print over the web:
    import javax.swing.JApplet;
    import javax.swing.SwingUtilities;
    import javax.swing.JLabel;
    public class HelloWorld extends JApplet {
        //Called when this applet is loaded into the browser.
        public void init() {
            //Execute a job on the event-dispatching thread; creating this applet's GUI.
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        JLabel lbl = new JLabel("Hello World");
                        add(lbl);
            } catch (Exception e) {
                System.err.println("createGUI didn't complete successfully");
    }However when I try to add a functioning main class and change the ?Hello World? to a string variable, it fails. I understand it fails because I?m having a missing link about how to turn the class into something that can take input.
    I know I?ll be ridiculed for the example I?m about to print, but I?m printing it to give an example of having a variable for my output.
    Look at the code that fails (just to get an idea of what I?m trying to explain):
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package test1;
    * @author teama
    import javax.swing.JApplet;
    import javax.swing.SwingUtilities;
    import javax.swing.JLabel;
    public class HelloWorld extends JApplet {
        //Called when this applet is loaded into the browser.
        public void init() {
            //Execute a job on the event-dispatching thread; creating this applet's GUI.
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run(String myhello) {
                        JLabel lbl = new JLabel(myhello);
                        add(lbl);
            } catch (Exception e) {
                System.err.println("createGUI didn't complete successfully");
            public static void main(String[] args) {
                // This is the output of my calculation
                // HelloWorld.void("Hello World")
                run("My Hello")               
    } -- L. James
    L. D. James

  • Error in host server but not in home PC

    I compiled the AppletButton.class(http://www.dedserius.com/~vanboers/OLDui/overview/example-1dot1/AppletButton.java) using jdk1.5.0_01 and call it from a HTML page without a Windowclass parameter so that testwindow opens.
    When I run the HTML page from my PC, Browser Address
    "C:\Documents and Settings\ing_rivera\Desktop\AppletButton\page.html"
    it works perfectly, so that when I click the button the Testwindow opens.
    But when I run it from my host server "lunarpages.com" & I click the button the message "Please wait while the window comes up..." shows up and the Testwindow never opens.
    By the way the files page.html and AppletButton.class are in the same file in my PC as well as in lunarpages so that shouldn't be the problem, is something else.
    Please help,
    ing_rivera

    Not enough information. You didn't get an error window that has a details button?
    Open the Java Control Panel | Advanced tab | Debugging and select "Show applet lifecycle exceptions", which enables this window.
    You can also see the details of Java problems by selecting IE Tools menu | Sun Java Console.

  • Microsoft Live Meeting Hangs in Mavericks

    Has anyone been able to get Microsoft Live Meeting to work under OS 10.9 Mavericks in Safari?
    I have tried Safari, Chrome, and Firefox, all with no success.
    Safari gets to a point where it says it is downloading the web console and it never gets beyond that point.
    I know I can do it under Parallels but I would prefer to do it on the Mac natively if possible.
    thanks

    I had the same problem on 10.9.2 (13C48) / Safari 7.0.2 and Java 7_51. A combination of this post and using Firefox got it working. To summarise:
    Go to 'Systems Preferences > Java'. The Java preferences opens as a seperate window
    Under General tab, select setting Run applets: in their own process (some MAC computers does not have this option, please proceed to the next step)
    Go to the ‘Advanced’ tab.
- Look for the option “Mixed code (sandboxed vs. trusted) security verification”.
    Select “Enable - hide warning and run with protection”.
    Under “Java Console” section, check “Show Console”
    Under “Debugging” section, check the following: “Enable tracing”, “Enable logging”, and “Show applet lifecycle exceptions”
    Restart Firefox if it's open
    Once this is enabled when you follow the steps to join you will get a debugging window that pops up and gives you a window into seeing all the code you never cared about but you can just ignore this. Also be sure to click the “allow” button on a small window that pops up asking if you want to allow the applet to run.
    Happy use of Live Meeting!

  • Compostion, aggregation & association

    Hello All,
    I have to clear a concept to myself, so am asking this question to you guyz. Plz don't hesitate to give me your clear views over it.
    Lets consider the following three relationships:
    a. Car ------ Engine     (Composition)
    b. Car ------ Stereo     (Aggregation)
    c. Car ------ Driver     (Association)I just can't make the proper symbols of relationships so i have mentioned the said relationships in brackets. ok, now I have just 2 questions:
    1- To implement physically, will there be any difference in the implementation of b & c relationships ?
    2- What should be the difference in class design of a & b relationships so that we could easily understand the concept of "Composition" and "Aggregation" ? (I mean how a developer enforce the idea that 'Engine' object should be constructed when 'Car' object is going in the process of being constructed)
    One thing: i need some detailed and full of examples discussion on second question. I hope you people will like this thread and make it as healthy as possible. Will wait for some serious thoughts over it.
    thanks.

    UML 1.5 section 2.5.4.1has a reasonable description of aggregate and composite:
    An association may represent an aggregation (i.e., a whole/part relationship). In this case, the association-end attached to the whole element is designated, and the other association-end of the association represents the parts of the aggregation. Only binary associations may be aggregations. Composite aggregation is a strong form of aggregation, which requires that a part instance be included in at most one composite at a time and that the composite object has sole responsibility for the disposition of its parts. This means that the composite object is responsible for the creation and destruction of the parts. In implementation terms, it is responsible for their memory allocation. If a composite object is destroyed, it must destroy all of its parts. It may remove a part and give it to another composite object, which then assumes responsibility for it. If the multiplicity from a part to composite is zero-to-one, the composite may remove the part, and the part may assume responsibility for itself, otherwise it may not live apart from a composite.
    WRT your questions:
    1- Possibly. You can represent the ends of associations as references in the classes:class Car {
      Engine engine;
      Stereo stereo;
      Driver driver;
    class Driver {
      Car car;
    }Or you can represent association relations as separate link objects:class Car {
      Engine engine;
      Stereo stereo;
    class Driver {
    class CarDriverLink {
      Car car;
      Driver driver;
    }The second case is useful when additional information about the link is required (say the car pool manager needs to keep a list of authorised associations), or for lazy access. This is called reification.
    It is also perfectly valid to maintain redundant information, so that the ends of the link also have references to the link, or the opposite end, for navigation purposes.
    It isn't as common to reify aggregations, as this alters the lifecycle semantics of ownership, unless the reified relation link is owned by the aggregate, rather than a third party:class Car {
      List <CarEngineLink> engines;
    class CarEngineLink {
      Car car;
      Engine engine;
    }So in the basic case, there isn't a difference, but in more complex aggregations the ownership semantics can be made explicit.
    2- As the JVM takes care of freeing memory, then it is no longer the aggregate's resposibility to deallocate the memory for the part. However, if a reference to the part is kept outside of the aggregate beyond the aggregate's lifecycle, then the relationship is one of aggreagation not composition. In other words, the structural implementation is the same, but the behavioural implementation will differ.
    If a car has to have one engine and that engine cannot be changed in the lifecycle of the car, you can use final to enforce the constraint and throw a null pointer exception if null is passed in; however, that is a cardinality and mutability constraint, which is orthogonal to composition/aggregation.
    Pete

  • 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>

  • Error while migrating Applet Swing components from JRE1.5.13 to JRE 1.6.05

    We have planned to migrate the Applet screens from JRE 1.5.13 to JRE 1.6.05 browser,
    but the APPLET files are still compiled using JDK 1.5.
    If any of you have had experience in this migration ,let me know the issues
    you have encountered.
    One problem which i understood through one of the thread
    from this site is performance is really bad with JRE 1.6 browsers.
    Please share the other issues which i need to take care.
    Thanks in advance

    >
    We have planned to migrate the Applet screens from JRE 1.5.13 to JRE 1.6.05 browser,
    but the APPLET files are still compiled using JDK 1.5. >Then the applet should work in 1.6 without alteration. (Barring bugs that cropped up in 1.6, or changes to 1.6 that revealed broken code from applets compiled for earlier versions.)
    Your best way to check is to test the applet (as is, without any changes or recompilation) using a browser running a 1.6 JRE.
    Is the applet publicly available? If so, what is the URL? (I have a couple of browsers here, all using 1.6.)
    >
    One problem which i understood through one of the thread
    from this site is performance is really bad with JRE 1.6 browsers.>Which thread, do you have a link?

Maybe you are looking for