Insert java file to html

Asked By 10 points N/A Posted on -
qa-featured

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

SHARE
Answered By 0 points N/A #101938

Insert java file to html

qa-featured

 

Code to be written in HTML file to invoke an applet which is a java program.
<Html>
<Head>
<Title>My Title</Title>
</Head>
<Body>
Applet page<br>
Applet viewer<br>
<br>
<Applet Code="NewApplet.class" width=200 Height=100>
</Applet>
</Body>
</Html> 
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.getContentPane().add(label);
 
        frame.pack();
        frame.setVisible( true );
    }
 
    public static void main(String[] args) {
 
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                ShowGUI();
            }
        });
    }
}
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. 
Thanks.
Please leave a comment.
 

Related Questions