Good day all!
Please I need someone to help me out by telling me what or how will I call up an Applet from a separate Java file that has a main method in it...thats to say, I will compile and run the Applet code from the other class with a main method in it.

Thanks alot
Loveday

Recommended Answers

All 7 Replies

I will compile and run the Applet code from the other class with a main method

There is an interface: JavaCompiler for compiling a java program from within a java program.
After the code is compiled and the .class file is available, you can create an instance of the class and call its methods the same way a browser would call the methods. For full applet support, you need to provide an AppletContext for the Applet to use.

Can you explain some more what you are trying to do?

There is an interface: JavaCompiler for compiling a java program from within a java program.
After the code is compiled and the .class file is available, you can create an instance of the class and call its methods the same way a browser would call the methods. For full applet support, you need to provide an AppletContext for the Applet to use.

Can you explain some more what you are trying to do?

Thanks for your quick response. Actually, I have two files, an Applet and the other one with a main method, just for the sole purpose of calling up the applet file. How can I implement it in that class with main method?
Thanks
Alam Loveday

How can I implement it

Please explain "implement it"? What is it you want to do?
My previous post laid out the steps you'd take for the way you wrote the original question.

Please explain "implement it"? What is it you want to do?
My previous post laid out the steps you'd take for the way you wrote the original question.

I want the class with a main method to call an Applet file(that is, execute it). What method can I use in the main method class to execute the applet code? The files are attached here. Pls have a look.
Thanks
Alam Loveday

To call a method in another class:
1) get/create a reference to an instance of the class:
AnApplet anApplet = new AnApplet(); // create an instance of the class

2)To call a method in that class, use the reference created above:
anApplet.aMethod(); // call a method in the class

to call an Applet file(that is, execute it)

What do you mean by "call" and by "execute"?
When an applet executes in a browser, the browser provides support via an AppletContext class to the applet. If you don't need any "applet" support, then you can ignore that.
If you do, then you you need to provide an AppletContext object to the applet you are executing.

To call a method in another class:
1) get/create a reference to an instance of the class:
AnApplet anApplet = new AnApplet(); // create an instance of the class

2)To call a method in that class, use the reference created above:
anApplet.aMethod(); // call a method in the class


What do you mean by "call" and by "execute"?
When an applet executes in a browser, the browser provides support via an AppletContext class to the applet. If you don't need any "applet" support, then you can ignore that.
If you do, then you you need to provide an AppletContext object to the applet you are executing.

I have done as you directed but am still having some issues. You can have a glance to see with what I have done so far in the attached file. Thanks for your efforts.

but am still having some issues

Please explain what you have tried, what the issues are and show full text of any errors.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.