Insert java file to html

Asked By 10 points N/A Posted on -

Is it possible to insert java file to html? How does it work? Can you give me some working html codes on with a java file on it? Hope you may help. Thanks

Answered By 0 points N/A #101938

Insert java file to html



Code to be written in HTML file to invoke an applet which is a java program.
<Title>My Title</Title>
Applet page<br>
Applet viewer<br>
<Applet Code="NewApplet.class" width=200 Height=100>
Code in the Applet
Create a file New Applet.class and cpy the below.
import javax.swing.*;        
public class NewApplet {
    private static void ShowGUI() {
        JFrame frame = new JFrame ( " This is My first applet program ");
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        JLabel label = new JLabel( " Hello World " );
        frame.setVisible( true );
    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
Open the HTML file in browser enabled with java. You see the string written in the browser.
The entire system is that when you have a .class file then you can run it if you have J V M installed on your machine. This is fairly possible. However Running applets require a inherited function run() that has to be in the class which is do ing the applet work. The program runs on the browser. If you have any other java program, you can convert into an applet by using the run() method and then you get the applet to run on a java enabled browser itself. 
Please leave a comment.

Login/Register to Answer

Related Questions