hi everyone i really need help with my problem, i have created a full online tutorial using applets however one of my html pages containing this particular applet will not show the applet when viewed in any broswer. The applet contains an image and without the image the browser shows the applet, thecode for the applet is below;

import javax.swing.*;
import java.awt.*;

public class labels2 extends JApplet 
{
    public void init() 
    {
    	Container contentPane = getContentPane();
    	contentPane.setLayout(new BorderLayout());
    	contentPane.setBackground(Color.LIGHT_GRAY);
    	
    	JLabel label = new JLabel("This is Ginger, my cat");
    	contentPane.add(label, BorderLayout.NORTH);
    	
    	ImageIcon catIcon = new ImageIcon("ginger.jpg");
    	label.setIcon(catIcon);
    	contentPane.add(label, BorderLayout.NORTH);	
    
    }
}

the applet works fine, the code placed inside the html page is as below;

<applet
	code	= "labels2.class"
	width	= "450"
	height	= "250">
</applet>

the html page shows the applet only when the image is not inside it, this code works because i have created many other html pages with applets embedded using the same code, however this one does not, does anyon have any suggestions? i would be very very grateful.

hi,

write the html code in the java itself and keep it in the comment lines,and see the image it is there or not for this particular task only , i am speaking.

and compile as usual as javac filename.java

and excute as appletviewer filename.java(labels2.java).

import javax.swing.*;
import java.awt.*;


public class labels2 extends JApplet
{
public void init()
{
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.setBackground(Color.LIGHT_GRAY);


JLabel label = new JLabel("This is Ginger, my cat");
contentPane.add(label, BorderLayout.NORTH);


ImageIcon catIcon = new ImageIcon("compman.gif");
label.setIcon(catIcon);
contentPane.add(label, BorderLayout.NORTH);


}
}


/* <applet
code    = "labels2.class"
width   = "450"
height  = "250">
</applet> */
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.