Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > applet inside an applet

Reply
Thread Tools

applet inside an applet

 
 
Baji
Guest
Posts: n/a
 
      11-22-2005
Dear Friends,
please suggest me a soultion in the following issue. I am new to
java & please bare my poor english.

I have an appplet, inside the applet, if some conditions matches I
am loading a new applet. using the follwing syntax
Applet realApplet;
Class appletClass =
Class.forName("client.class");
realApplet = (Applet)appletClass.newInstance();
realApplet.setStub(this);
setLayout( new GridLayout(1,0));
add(realApplet);
realApplet.init();
realApplet.start();

now I have a method called "ClientMethod" inside the Client.class
now I want to call this ClientMethod from the applet code, how can I
achieve this.

supppose If I say

public String Message(String Msg)
{
realApplet.ClientMethod(Msg);
}

is not working..

Please suggest me a good idea to achive the above.

Thanks in advance.
Bajio.

 
Reply With Quote
 
 
 
 
zero
Guest
Posts: n/a
 
      11-22-2005
"Baji" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) oups.com:

> Dear Friends,
> please suggest me a soultion in the following issue. I am new to
> java & please bare my poor english.
>
> I have an appplet, inside the applet, if some conditions matches
> I
> am loading a new applet. using the follwing syntax
> Applet realApplet;
> Class appletClass =
> Class.forName("client.class");
> realApplet = (Applet)appletClass.newInstance();
> realApplet.setStub(this);
> setLayout( new GridLayout(1,0));
> add(realApplet);
> realApplet.init();
> realApplet.start();
>
> now I have a method called "ClientMethod" inside the Client.class
> now I want to call this ClientMethod from the applet code, how can I
> achieve this.
>
> supppose If I say
>
> public String Message(String Msg)
> {
> realApplet.ClientMethod(Msg);
> }
>
> is not working..
>
> Please suggest me a good idea to achive the above.
>
> Thanks in advance.
> Bajio.
>


If you're new to Java, you shouldn't be messing with reflection (which
is what you're doing when trying to create realApplet in this code). I
don't see a reason to create an applet inside an applet, and even if
there is a legitimate reason I certainly wouldn't recommend it to
someone new to Java. In fact, you shouldn't be bothering with applets
at all when you're new to Java.

Important side-note: never start a method name with a capital letter.
Use clientMethod instead of ClientMethod. Only class names should start
with a capital.

That all being said, what you are trying to do is invoke method
clientMethod on an Applet object. But, class Applet does not have a
method with name clientMethod. You probably have a ClientApplet extends
Applet or similar class, which does contain clientMethod. So then you
need an object of class ClientApplet, not Applet.

ClientApplet realApplet = (ClientApplet)appletClass.newInstance();

realApplet.clientMethod("test");

PS: strictly speaking, if you put an applet inside one of your own
components, you would need to create a complete, valid applet container
- ie something that calls applet methods init, start, stop, destroy, ...
at the appropriate times. I doubt you want to get into that, so you
should try to find an alternative to your "applet inside an applet"
approach.
 
Reply With Quote
 
 
 
 
Baji
Guest
Posts: n/a
 
      11-23-2005
Hi,
thanks for your reply, I am into Microsoft Technologies (VC++), but my
project deals with a java appplet communicating to my VC++ server
component. I am not so efficient in java programming, But I am very
sorry if am wrong in the way i have wirtten that mail.

you are right, I have clientApplet which extends applet and is having a
method called "clientMethod". even I have implemented all the methods
such as init, start , stop, destroy. etc,. I am able to call all these
methods of realApplet.

but I am unable to call an user defined method called "client Method".
realApplet.clientMethod("test"); I dont know why, I am getting
compilation errors such as undefined, if you want I can send you the
error am getting.

please suggest me a solution for this.

warm regards,
Baji.

 
Reply With Quote
 
zero
Guest
Posts: n/a
 
      11-23-2005
"Baji" <(E-Mail Removed)> wrote in news:1132722352.451902.73770
@g49g2000cwa.googlegroups.com:

> Hi,
> thanks for your reply, I am into Microsoft Technologies (VC++), but my
> project deals with a java appplet communicating to my VC++ server
> component. I am not so efficient in java programming, But I am very
> sorry if am wrong in the way i have wirtten that mail.
>
> you are right, I have clientApplet which extends applet and is having a
> method called "clientMethod". even I have implemented all the methods
> such as init, start , stop, destroy. etc,. I am able to call all these
> methods of realApplet.
>
> but I am unable to call an user defined method called "client Method".
> realApplet.clientMethod("test"); I dont know why, I am getting
> compilation errors such as undefined, if you want I can send you the
> error am getting.
>
> please suggest me a solution for this.
>
> warm regards,
> Baji.
>


Are you instantiating realApplet as an instance of ClientApplet? The exact
error message would be helpful, as well as the exact code that generates
the error. Specifically, I need to see the ClientApplet code (you can trim
the parts that do work) and the code that instantiates the realApplet
object.
 
Reply With Quote
 
Baji
Guest
Posts: n/a
 
      11-23-2005
Let me explain you what exactly I am trying to do:

I am creating a dummy applet which connects to my server written in
vc++. This server checks the validity of the connection(user), I can
say the IP of the user. If the User is valid to view the original
applet then I will instantiate the original 3rd Party applet.
if the user has no access to view the applet I will give some error
message.

Following is the code. I have cut shorted the code.

/********************************************/

import java.applet.Applet;
import java.applet.AppletStub;
import java.awt.*;
import java.net.*;
import java.io.*;
import java.util.*;

public class DummyClass extends Applet implements Runnable, AppletStub
{
Thread appletThread;
Applet realApplet;

public void init()
{
/* code for connecting to server written in vc++ , basically a
socket connection */
}

public void paint(Graphics g)
{
/* general implimentaion */
}

public void run()
{

/* get the response from the vc++ sever, read the buffer & check
the validity of connection */

if(!bError && bException) /* if the user is valid */
{
Class appletClass = Class.forName("Client");
/* Client is the original applet */
ClientApplet realApplet =
(ClientApplet)appletClass.newInstance();
realApplet.setStub(this);
setLayout( new GridLayout(1,0));
add(realApplet);
realApplet.init();
realApplet.start();
}
else
{
/* give error message */
}
this.repaint();
validate();
} //end of run

public void start()
{
appletThread = new Thread(this);
appletThread.start();
System.out.println("Inside Start");
}


public void stop()
{
if(realApplet != null)
{
realApplet = null;
}

appletThread = null;
}

public void appletResize( int width, int height )
{
resize( width, height );
}
synchronized void pause(int millis)
{
try
{
wait(millis);
}
catch (InterruptedException e)
{}
}

// There is a user defined method called "handleMessage" in the
above realApplet, now
// I want to call that method as stated below. I dont have the code
for the realApplet,
// it is of some 3 rd party.

public void handleMessage(String Msg)
{
if(realApplet != null)
{
realApplet.handleMessage("Msg");
}
}
}


/***********************************/
Following is the error I am getting when compiled.
/***********************************/
DummyClass.java:269: cannot resolve symbol
symbol : method handleMessage (java.lang.String)
location: class java.applet.Applet realApplet.handleMessage("Msg");


I dont know what is going on when I call a userdefined method of the
applet. I was able to call the same thing from java script in an asp
pag, that time I will be loading a single applet in the asp page.

warm regards,
Baji.

 
Reply With Quote
 
zero
Guest
Posts: n/a
 
      11-23-2005
"Baji" <(E-Mail Removed)> wrote in news:1132753824.096040.206560
@g44g2000cwa.googlegroups.com:

> Let me explain you what exactly I am trying to do:
>
> I am creating a dummy applet which connects to my server written in
> vc++. This server checks the validity of the connection(user), I can
> say the IP of the user. If the User is valid to view the original
> applet then I will instantiate the original 3rd Party applet.
> if the user has no access to view the applet I will give some error
> message.
>
> Following is the code. I have cut shorted the code.
>
> /********************************************/
>
> import java.applet.Applet;
> import java.applet.AppletStub;
> import java.awt.*;
> import java.net.*;
> import java.io.*;
> import java.util.*;
>
> public class DummyClass extends Applet implements Runnable, AppletStub
> {
> Thread appletThread;
> Applet realApplet;
>


<snip>

>
> public void run()
> {


<snip>

> ClientApplet realApplet =
> (ClientApplet)appletClass.newInstance();


<snip>

> } //end of run
>


<snip>

> public void handleMessage(String Msg)
> {
> if(realApplet != null)
> {
> realApplet.handleMessage("Msg");
> }
> }


<snip>


Ok, your problem now is a scope problem. If you've worked with VC++ you
should already know all the scope rules, so I won't bore you with them (if
you're fuzzy about the rules, look them up anywhere, they're pretty much
the same for all OO languages).

In this case, you are creating the ClientApplet object inside the run()
scope. But you have another realApplet object at class scope, which is an
instance of Applet - NOT ClientApplet. It is this one that is used in
handleMessage(). Not only is it an instance of Applet instead of
ClientApplet, it is also null because it is not instantiated anywhere.

In short, remove "ClientApplet" in
ClientApplet realApplet = (ClientApplet)appletClass.newInstance();
and change
Applet realApplet
to
ClientApplet realApplet

As an aside, you might want to look into using ASP.NET, JSP, PHP, ... to
avoid the "applet inside an applet" construct. The serverside scripting
could check the user's credentials, and if he has permission, insert the
<applet> tag into the html. If he doesn't have permission, insert an error
message instead of the applet. This could still use your vc++ server, or
it could use the scripting language's own authentication methods.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      11-23-2005
On Wed, 23 Nov 2005 16:41:13 GMT, zero <(E-Mail Removed)> wrote, quoted or
indirectly quoted someone who said :

>Ok, your problem now is a scope problem. If you've worked with VC++ you
>should already know all the scope rules, so I won't bore you with them (if
>you're fuzzy about the rules, look them up anywhere, they're pretty much
>the same for all OO languages).


see http://mindprod.com/jgloss/scope.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Baji
Guest
Posts: n/a
 
      11-24-2005
Thanks for your Suggestions. Let me try that, will update you again.
but why you are suggesting me to user some alternative for the "applet
insdie an applet construct"

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      11-24-2005
Baji wrote:

> Thanks for your Suggestions. Let me try that, will update you again.
> but why you are suggesting me to user some alternative for the "applet
> insdie an applet construct"


It is good advice. GUI'd programs, and then Applets, are
not easy, and many people unfamiliar with Java get into
all sorts of troubles when writing them.
<http://www.physci.org/codes/javafaq.jsp#appfirst>

Hosting an applet inside another applet, (Reflection aside)
is harder again by an order of magnitude.

Ultimately, you can achieve much the same effect by having the
first applet use AppletContext.showDocument(URL) to go to the
second applet (on a different page).

Note that if you do not want to do that because the user sees
the 'secret' URL, you are pretty much lost anyway, as the (Java
aware) end user could discover the second applet, and write a
simple page of their own to call and use it.

--
Andrew Thompson
physci, javasaver, 1point1c, lensescapes - athompson.info/andrew
Currently accepting short and long term contracts - on Earth.
 
Reply With Quote
 
Baji
Guest
Posts: n/a
 
      11-25-2005
Hi Andrew,
Thanks for your mail. My main concern with the security, user
should not be able to know anything abou the realApplet. One more thing
is yesterday I tried the things you have explained about the scope
probhlem, but I was unable to solve the probhlem, I am getting the same
error.
I am trying for the same. Please let me know if you have anyother
valuable suggestions.

Thanks & Regards,
Baji.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Configuring an inside nat group on inside interface jaalcock@gmail.com Cisco 2 04-11-2006 02:16 AM
inside-outside-inside issue on PIX 506E Dan Rice Cisco 9 02-04-2005 12:04 AM
Problem with inside to inside traffic after upgrading PIX 515 Cisco 5 06-15-2004 06:34 AM
Dynamic temp. datagrid col.gen. -Session access inside a class inside a UserCtrl Andy Eshtry ASP .Net 0 03-01-2004 11:48 PM
Re: Can We Use EXEC CGI Inside a JavaScript Applet Inside an HTML File? David Dorward HTML 1 06-28-2003 09:30 AM



Advertisments