-
Applet not initialized
I have compiled the following code and it compiles but when i run the code the following error message is shown in the applet window Start: Applet not initialized. Can someone have a look at my code and say where I went wrong. Thanks
import java.awt.*;
import javax.swing.*;
import javax.swing.JApplet;
/*
* Created on Feb 12, 2005
*
*/
/**
* @author trixma
* @version 1.0
*/
public class IPClassFinder extends JApplet {
private Container container;
private JLabel ipClass, header, title, fullstop, fullstop1, fullstop2;
private JButton calculate, clear;
private JTextField field1, field2, field3, field4, field5;
public void init() {
container = getContentPane();
JPanel border = new JPanel(new BorderLayout(5,5));
header = new JLabel("IP address information", JLabel.CENTER);
border.add(header);
JPanel grid1 = new JPanel();
grid1.setLayout(new GridLayout(2,8,1,5));
title = new JLabel("Enter IP Address", JLabel.CENTER);
grid1.add(title);
field1 = new JTextField(3);
grid1.add(field1);
fullstop = new JLabel(".", JLabel.CENTER);
grid1.add(fullstop);
field2 = new JTextField(3);
grid1.add(field2);
fullstop1 = new JLabel(".", JLabel.CENTER);
grid1.add(fullstop1);
field3 = new JTextField(3);
grid1.add(field3);
fullstop2 = new JLabel(".", JLabel.CENTER);
grid1.add(fullstop2);
field4 = new JTextField(3);
grid1.add(field4);
ipClass = new JLabel("IP Address Class");
grid1.add(ipClass);
field5 = new JTextField();
grid1.add(field5);
border.add("CENTER", grid1);
JPanel grid2 = new JPanel(new GridLayout(1,2,5,5));
calculate = new JButton("Calculate");
grid2.add(calculate);
clear = new JButton("Clear");
grid2.add(clear);
border.add("South", grid2);
container.add(border);
}
}
-
fixed problem
Below is the solution to the above problem.
JPanel border = new JPanel(new BorderLayout(5,5)); <-- deleted this line
border.add(header); <- this line should be container.add(header, BorderLayout.NORTH);
border.add("CENTER", grid1); <- This line should be container.add(grid1, BorderLayout.CENTER);
border.add("South", grid2); <- This line should be container.add(grid2, BorderLayout.SOUTH);
container.add(border); <- deleted this line
-
also, you may delete import javax.swing.JApplet; as it is already imported via import javax.swing.*;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks