Hi All,

I have created a Java applet in Eclipse and ran it in eclipse, it works fine . To run the applet in Webbrowser it was mentioned to embed the .class file inside a webpage by creating a HTML file. My class name is MyFirstGUI. i have created a file name gui.html and saved it in my documents. The error im getting in browser when running the file is "ClassNotFoundException". This is the content of my html file .

<HTML>
<HEAD>
<TITLE>Metric Conversion Helper</TITLE>
</HEAD>
<BODY>
<APPLET code = “MyFirstGUI.class” width = “400” height = “120”>
</APPLET>
</BODY>
</HTML>

Please Explain....

Make sure the class file is located in the same directory as the html file. also make sure it is actually an applet rather than an aplication (has an init and a paintComponent method and it extends JApplet).

i have created it in NetBeans sorry not in Eclipse as i mentioned, so it is saved inside netbeans projects folder, i have also cpoied the HTMl file to the same location which is " C:\Users\jacksons5\Documents\NetBeansProjects\myFirstGUI\build\classes\myfirstgui " . Its still throwing the same error.

Here is my code

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


package myfirstgui;

import java.awt.event.ActionEvent;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;

    private JTextField jtInput;
    private JTextField jtOutput;
    private static final int WIDTH = 600;
    private static final int HEIGHT = 100;

    public void init(){
        Container container = super.getContentPane();

        GridLayout gridlabel ;

        gridlabel = new GridLayout(3,2);

        container.setLayout(gridlabel);

        JLabel jInput = new JLabel("Input",SwingConstants.CENTER);
        JLabel jOutput = new JLabel("Output",SwingConstants.CENTER);

         jtInput = new JTextField(10);
         jtOutput = new JTextField(10);

        jtOutput.setEditable(false);

        JButton jbInput = new JButton("Calculate");
        jbInput.addActionListener(new CalculateJButtonInterface());


        container.add(jInput);
        container.add(jtInput);
        container.add(jOutput);
        container.add(jtOutput);
        container.add(jbInput);
        //container.add(jbOutput);

    }


private class CalculateJButtonInterface implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) {
            int n,sum;

            n = Integer.parseInt(jtInput.getText());

            sum =  sum = ((n + 1) / 2) * n;
            jtOutput.setText("" + sum); 

            //throw new UnsupportedOperationException("Not supported yet.");
        }

}
       }

I have the class file and HTML file both in "C:\Users\jacksons5\Documents\NetBeansProjects\myFirstGUI\build\classes\myfirstgui".

I have tried putting Codebase in HTML file as

<APPLET code = “C:\Users\jacksons5\Documents\NetBeansProjects\myFirstGUI\build\classes\” width = “400” height = “120”>

and

<APPLET code = “C:\Users\jacksons5\Documents\NetBeansProjects\myFirstGUI\build\classes\MyFirstGUI.class” width = “400” height = “120”>

Still doesnot work.

Could you please tell what i need to put in <APPLET code to make it work in Browser

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.