• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

launch one applet from another

hi..can someone help me as to what i'm doing wrong here..i need to launch one applet from another and have the first applet close.the first applet is launched using a jnlp file using web start..

in the first applet i have

loginButton.addActionListener( new ActionListener() {
                public void actionPerformed( ActionEvent e )   {
          JApplet applet = (JApplet)this.getAppletContext().getApplet( "CRMCalendarApplet" );
          if( applet != null ){
               applet.init();
               applet.start();
          }

    }

  });


in the second applet i have the following in the init method...

   JApplet applet = (JApplet)this.getAppletContext().getApplet( "CRMLoginApplet" );
          if( applet != null ){
                  applet.stop();
                   applet.destroy();      
           }

i get this error when trying to compile the first applet though

CRMLogin.java [131:1] cannot resolve symbol
symbol: method getAppletContext ()
          JApplet applet = (JApplet)this.getAppletContext().getApplet( "CRMCalendarApplet" );




0
trance12
Asked:
trance12
  • 8
  • 7
  • 3
1 Solution
 
aozarovCommented:
change:
(JApplet)this.getAppletContext(...
to
(JApplet)CRMLogin.this.getAppletContext(...
0
 
aozarovCommented:
Also is CRMLogin a JApplet? does it have the getAppletContext method?
0
 
aozarovCommented:
In addtion to: (JApplet)CRMLogin.this.getAppletContext(...
which I think should work for your if CRMLogin is an applet
JApplet)getAppletContext(... should work as well.
The reason that it fails is that you call this.<method> inside an anonymous inner class (ActionListener)
and therefore this referes to the "this" of that inner class (which of course doesn't have the getAppletContext method).
removng this or adding before it CRMLogin should fix this problem and the "this" will refer to the CRMLogin instance.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
trance12Author Commented:
thanks..but it doesnt launch the second applet?


JApplet applet = (JApplet)this.getAppletContext().getApplet( "CRMCalendarApplet" );

the work CRMCalendarApplet witin getApplet..is that the name of the applet class that i need to launch?
0
 
objectsCommented:
>    JApplet applet = (JApplet)this.getAppletContext().getApplet( "CRMCalendarApplet" );

you cannot do that, you instead need to create an instance of a frame and the required components directly.
0
 
trance12Author Commented:
yes..i'm using japplet
0
 
objectsCommented:
for example you would use something like:

        CRMCalendarApplet a = new CRMCalendarApplet();
        a.init();
        a.start();
 
       Frame appletFrame = new Frame("Applet Window");
       appletFrame.add("Center", a);
       appletFrame.setSize(150,150);
       appletFrame.setLocation(100,100);
       appletFrame.show();



0
 
objectsCommented:
Or if you wanted to use the same frame then remove the previous component from the panel amd add the new one
0
 
trance12Author Commented:
>>you cannot do that, you instead need to create an instance of a frame and the required components directly.

i dont understand..i've created  a frame for both the applets...when i hit enter on the first applet, i need it to lauch the 2nd applet..the 2nd applet has a amain class that has the frame structure too
0
 
trance12Author Commented:
yep..i already have this in the 2nd applet main class

 
        CRMCalendarApplet a = new CRMCalendarApplet();
        a.init();
        a.start();
 
       Frame appletFrame = new Frame("CRM Calendar");
       appletFrame.add("Center", a);
       appletFrame.setSize(550,350);
       appletFrame.setLocation(100,100);
       appletFrame.show();
0
 
objectsCommented:
> the 2nd applet has a amain class that has the frame structure too

then call that main

CRMCalendarApplet.main(null);
0
 
trance12Author Commented:
you mean like this??

loginButton.addActionListener( new ActionListener() {
                public void actionPerformed( ActionEvent e )   {
       
                  CRMCalendarApplet.main(null);

           }

  });

0
 
objectsCommented:
yes
0
 
trance12Author Commented:
thanks...it works when i dont use this in the init function of the second applet

JApplet applet = (JApplet)this.getAppletContext().getApplet( "CRMLoginApplet" );
          if( applet != null ){
                  applet.stop();
                   applet.destroy();      
           }

to close the first applet..is there another way to close the first applet when the 2nd applet lauches?
0
 
objectsCommented:
> JApplet applet = (JApplet)this.getAppletContext().getApplet( "CRMLoginApplet" );

Yes as I mention above you should not be doing that


close the frame using the dispose() method.
0
 
trance12Author Commented:
thanks..where should i use the dispose method..in the first applet after calling the second applet or get a reference to the first applet in the init methid of the 2nd applet?.....if in the 2nd applet, then i have to pass the apllet frame as a parameter?
0
 
trance12Author Commented:
what i mean is ..is there a way to close the frame of the first applet in the init function of the 2nd applet?
0
 
objectsCommented:
yolu'd be bost closing it from the same place you open the other one
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 8
  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now