0
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) 
{}

}

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by NormR1
0

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?

0

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

Edited by adams161: n/a

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.