Error in JAVA while running applet program

While I was running my applet program, I got in applet viewer window as "Applet not initialized" and in cmd i got the following errors!

    **java.lang.ClassCastException: application cannot be cast to java.applet.Applet
    at sun.applet.AppletPanel.createApplet(AppletPanel.java:799)
    at sun.applet.AppletPanel.runLoader(AppletPanel.java:728)
    at sun.applet.AppletPanel.run(AppletPanel.java:378)
    at java.lang.Thread.run(Thread.java:745)**

Can anyone help me why does this error occur?

Here's my code:

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
//<applet code="application" width=500 height=500> </applet>
public class application extends Frame implements ActionListener,ItemListener
{
Label name,regno
Button submit;
TextField tname,tregno;
String msg=" ";
public void init()
{
    name=new Label("Name");   //Adding name and regno field box
    regno=new Label("Register No");
    submit=new Button("Submit");
    tname=new TextField(20);
    tregno=new TextField(10);
    add(name); add(tname);
    add(regno); add(tregno);
    add(submit);
    submit.addActionListener(this);
    tname.addActionListener(this);
    tregno.addActionListener(this);
    }
public void actionPerformed(ActionEvent ae)
{
    String str=ae.getActionCommand();
    if(str.equals("Submit"))
        msg="Your application form is submitted successfully";
    app a=new app();    //Reference for my next program called "app"
    a.setVisible(true);
    repaint();
}
public void itemStateChanged(ItemEvent ie)
{
    repaint();
}
public void paint(Graphics g)
{
    g.drawString("Name: "+tname.getText(),10,160); //Printing the name and regno
    g.drawString("Register No: "+tregno.getText(),10,180);
    g.drawString(msg,250,350);
}
}

In the above program, I've created a basic applet structure that gets the details of the person(name and regno) and hyperlinks to another program when submit button is clicked.

Answers


An Applet class should be a subclass of Applet. Revise the class declaration so that it also extends Applet:

public class application extends ..., Applet {
    //code here
}

More information on java.applet.Applet can be found on Javadocs.


Need Your Help

What is the Eclipse equivalent of IntelliJ “Live templates”?

java eclipse ide intellij-idea live-templates

I mean stuff like typing "iter" and getting a "for" loop with a choice of what variable to iterate on , typing "soutv" to generate a "System.out.println" with the "variable=" already in ...

Object-oriented or sequential?

c++ oop

I'm refactoring a 500-lines of C++ code in main() for solving a differential equation. I'd like to encapsulate the big ideas of our solver into smaller functions (i.e. "SolvePotential(...)" instea...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.