import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class AL extends Frame implements WindowListener,ActionListener 
{
	TextField text = new TextField(20);
	Button b;
	private int numClicks = 0;

	public static void main(String[] args) {
		AL myWindow = new AL("My first window");
		myWindow.setSize(350,100);
		myWindow.setVisible(true);
	}

	public AL(String title) {

		super(title);
		setLayout(new FlowLayout());
		addWindowListener(this);
		b = new Button("Click me");
		add(b);
		add(text);
		b.addActionListener(this);
	}

	public void actionPerformed(ActionEvent e) 
{
		numClicks++;
		text.setText("Button Clicked " + numClicks + " times");
	}

	public void windowClosing(WindowEvent e) 
{
		dispose();
		System.exit(0);
	}

	public void windowOpened(WindowEvent e) 
{}
	public void windowActivated(WindowEvent e) 
{}
	public void windowIconified(WindowEvent e) 
{}
	public void windowDeiconified(WindowEvent e) 
{}
	public void windowDeactivated(WindowEvent e) 
{}
	public void windowClosed(WindowEvent e) 
{}

}

Dani AI

Generated

Thread shows an AWT Frame-based class (AL) that also imports applet classes while defining a main method. That mix is the most likely reason for the "Applet not initialized" symptom: a browser/plugin expects an applet lifecycle but the class is behaving as a standalone application. Two clean routes exist: keep AL as a desktop app (Frame + main) and ignore the browser/applet side, or convert the UI host into a true applet wrapper the plugin can load. Also note that code paths that terminate the JVM or rely on top-level Frame windowing are fine for desktop apps but will misbehave in a browser environment.

Useful diagnostic checklist (items repeatedly requested in the thread): confirm that the compiled class or JAR is located where the page expects it; check package declarations and case-sensitive filenames; run the HTML with the JDK appletviewer to separate browser/plugin issues from code issues; and capture the Java Console or appletviewer stack trace — an uncaught exception during initialization is the most common cause of "Applet not initialized". If the intent is desktop execution, verify the main/Frame behavior locally before wrapping it for browser use.

As observed, the HTML embed plus OS/browser details are typical diagnostics. correctly flagged the inheritance/lifecycle mismatch: a GUI class meant for browser loading must follow the applet lifecycle rather than only providing a desktop main. As requested, Java Console or appletviewer traces are the single most useful artifacts for pinpointing the exact exception behind the initialization failure.

Recommended Answers

All 3 Replies

1. Remember to use code tags to make your code easier for others to read.
2. You might also want to post the HTML page (or at least the embed / applet / object tag and immediate surroundings) that you are using to test your applet.

And as long as we are covering the basics of troubleshooting, what browsers and operating systems have you tried this on?

you dont use a main method in an applet

you have:

public static void main(String[] args)

replace it with

public void init()

your class also needs to extends JApplet. since you cant extend JFrame and JApplet both in one class, maybe make the Applet the outer class and the frame the inner class.

Mike

Do you get any error messages in the browser's Java console?
Please copy and paste them here.

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.