Hello Members,

The following problem has troubled me for sometime now:

I have an applet called FileA.java. It has two classes both of which are JPanels. Both these JPanels are then added to the applet in the public class of FileA.java. I use BlueJ.

The program works well offline on my desktop. To post it online on my webpage, I used the "Create Jar File" option in BlueJ to create the FileA.jar file. I further checked the contents of FileA.jar by using the "jar tf FileA.jar" command and I see all the classes and .gif files I would need. I then created my FileA.html file as follows:

<title> FileA Applet</title>
        <h1>FileA Applet</h1>
        <applet code="FileA.class" 

The FileA.html and FileA.jar files are under my public_html folder. So, there was no need for any codebase specification.

When I run the applet on my webpage, all I get is a blank screen. I would be grateful for any help.

Thank you!!

7 Years
Discussion Span
Last Post by sciprog1

The program works well offline on my desktop.

Have you tried running it locally from within the Jar file? Does that work? Can you run it using appletviewer?

I don't see anything obviously wrong with your HTML. If the above tests don't shed any light, post the jar & the html as attachments and I will see if I can figure out what's going wrong.


Hello kramer,

Thank you for the reply.

When I double click the FileA.jar file, I get the error, "Fatal Exception Occured. Program will exit". Also, here is the public JApplet class:

public class FileA extends JApplet
   public void init()
        JFrame window = new JFrame("Yahtzee 1.3");
        YahtzeeB animation2 = new YahtzeeB(); //YahtzeeB is a JPanel in the same file
        Yahtzee animation = new Yahtzee(); //Yahtzee is a JPanel in the same file
        window.setLayout(new FlowLayout(FlowLayout.CENTER)) ;
        window.setSize(1025, 650);

When I run this on the command line with appletviewer, I get the following error:

java.lang.Error: Do not use javax.swing.JFrame.setLayout() use javax.swing.JFrame.getContentPane().setLayout() instead
        at javax.swing.JFrame.createRootPaneException(JFrame.java:458)
        at javax.swing.JFrame.setLayout(JFrame.java:524)
        at FileA.init(FileA.java:4345)
        at sun.applet.AppletPanel.run(AppletPanel.java:347)
        at java.lang.Thread.run(Thread.java:536)

Even after using the getContentPane(), I am still getting the same errors.
Before sending you the FileA.jar and FileA.html, I thought I will tell you the errors I currently have when I run it with appletviewer and try to run the FileA.jar file.

Thank you for your help!!

Edited by sciprog1: n/a


I'm not familiar with these errors, but I do have a few comments on your code.
1. You should set the layout manager before adding components to the window.
2. You shouldn't call pack() if you are setting the size of the window yourself. The purpose of pack() is to ask Java to set the window size for you.
3. You should call setVisible(true); at the very end, after setting the size, and setting resizable to false.
I don't know if any of these changes will help.


Hello Kramer,

Thank you for your suggestions. I still have issues with my program. I have another question which relates to networking. I have a Client sending Server a stream of integers and when I use the streamIn.readInt() (streamInt being a DataInputStream type) on the Server( BlackJackServer.java) to read these integers, I get the following exception:

	at java.io.DataInputStream.readInt(DataInputStream.java:375)
	at BlackJackServer.<init>(BlackJackServer.java:236)
	at BlackJackServer.main(BlackJackServer.java:279)

Any idea on how to fix this error?

If you want me to post this in a new thread, please let me know.

Thank you!!


Generally when you read from a stream, you read until you reach EOF. So if you have already reached EOF and then you try to read again, you will get this exception.

If my answer doesn't help or you have more questions on this topic, you should probably start a new thread because there may be other people who can help you too.

I also had another thought about your applet. The problem might have to do with the version of the JVM in the browser. Is it different from what you are using in BlueJ?

Edited by kramerd: n/a


Hello kramer,

I tried as per your suggestions and ensured that the JVM for BlueJ and the browser was the same. I still get a blank applet screen. As you said, I will close this thread. I have re-posted this question as a seperate thread.

Thank you!!

This question has already been answered. 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.