user3078709
user3078709

Reputation: 13

What is wrong with my applet?

I want to put a simple Java code into an HTML document. This is the code of my applet and I saved it at: C:\Users\user\Documents\NetBeansProjects\JavaApplication17\src\javaapplication17.

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

public class App extends JApplet implements ActionListener {
    JLabel m,n;
    JTextField v;
    JButton b;
    public void init(){
        setSize(500,500);
        m=new JLabel("Ingrese el radio del círculo");
        m.setBounds(20, 50, 150, 30);
        add(m);
        v=new JTextField();
        v.setBounds(270,50,50,30);
        add(v);
        b=new JButton("Calcular área");
        b.setBounds(20,90,350,30);
        add(b);
        b.addActionListener(this);
        n=new JLabel();
        n.setBounds(100,130,100,30);
        add(n);
    }

    @Override
    public void actionPerformed(ActionEvent ae) {
        double r,a;        
        r=Double.parseDouble(v.getText());
        a=Math.PI*r*r;        
        n.setText("El área del círculo es: "+a);
    }
}

And this is the html file, I saved it at C:\Users\user\Documents\NetBeansProjects\JavaApplication17\src

<HTML>
<HEAD>   
<TITLE>         
Cálculo del área de un círculo
</TITLE>    
</HEAD>
<BODY>
<APPLET CODE="App" 
CODEBASE="javaapplication17/" 
WIDTH="500" 
HEIGHT="500">
</APPLET>
</BODY>
</HTML> 

But it doesn't work! When I try to open the applet with a navigator, it shows me this message:

NoClassDefFoundError

App(Wrong name: javaapplication17/App)

What can I do?

Upvotes: 1

Views: 72

Answers (2)

Reimeus
Reimeus

Reputation: 159754

You need to specify the fully qualified class in the applet code attribute:

<APPLET CODE="javaapplication17.App" WIDTH="500" HEIGHT="500">

For this to work, the HTML file needs to be located in the src directory

Upvotes: 1

Ashish
Ashish

Reputation: 1121

Did you try this:

<APPLET CODE="App.class" CODEBASE="javaapplication17/" WIDTH="500" HEIGHT="500"/>

if above doesn't work, put both of the files in same folder and remove 'codebase' attribute.

Upvotes: 0

Related Questions