Welcome to Dream.In.Code
Become a Java Expert!

Join 149,513 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,355 people online right now. Registration is fast and FREE... Join Now!




Applet help

 
Reply to this topicStart new topic

Applet help

itpro4470
12 Jul, 2007 - 08:04 AM
Post #1

D.I.C Head
Group Icon

Joined: 17 Jun, 2007
Posts: 123



Thanked: 1 times
Dream Kudos: 25
My Contributions
I am new to applets I am going through the applet fundamentals in the complete java reference book for j2se 5.
the fir applet they have is as follows
CODE

import java.awt.*;
import java.applet.*;
public calss SimpleApplet extends Applet
{
    public void paint(Graphics g)
          {
                  g.drawString("Simple applet",20,20);
           }
}


This applet will compile but will not run correctly on my computer. Is there something wrong with the coding????? it is copied directly out of the book.

This post has been edited by itpro4470: 12 Jul, 2007 - 08:06 AM
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Applet Help
12 Jul, 2007 - 08:56 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Hi,

Well first of all you have a typo at the top where you spell "class" as "calss". But I am sure that is a bad typo here and not in your program since you said it compiles and an error like that would prevent a compile.

I have tested your code as is and it does work fine. However, if you are running it in IE you will have to make sure it is not being blocked. check to make sure you don't have a yellow warning box at the top of the screen when you run it. Also make sure you are using a good test HTML page to activate the applet. This is what I used...

CODE

<html>
<head>
<title>Test</title>
</head>

<body>

<applet width=300 height=300 code="SimpleApplet.class"> </applet>

</body>
</html>


So compile your .java file into a .class and then make sure your "code=" part points to the class file's location. Here I am using a HTML test file that is in the same directory as the .class file so it will find it easily.

I hope some of these tips will solve your problem.

NOTE: If you have Firefox installed, try using that and see if you can see the output. If IE is the problem, you can go to Internet Options >> Advanced tab and in there activate any java checkboxes you think should be checked (use discretion).

This post has been edited by Martyr2: 12 Jul, 2007 - 09:00 AM
User is offlineProfile CardPM
+Quote Post

itpro4470
RE: Applet Help
12 Jul, 2007 - 09:02 AM
Post #3

D.I.C Head
Group Icon

Joined: 17 Jun, 2007
Posts: 123



Thanked: 1 times
Dream Kudos: 25
My Contributions
thanks! I will try this in firefox too it may be my IE. I have to try later though my loptop is out fo commision for a few hours.
User is offlineProfile CardPM
+Quote Post

itpro4470
RE: Applet Help
12 Jul, 2007 - 06:21 PM
Post #4

D.I.C Head
Group Icon

Joined: 17 Jun, 2007
Posts: 123



Thanked: 1 times
Dream Kudos: 25
My Contributions
ok sorry it took so long. Here is the code copied directly from my IDE
CODE

import java.applet.*;
import java.awt.*;
public class SimpleApplet extends Applet
{
    public void paint(Graphics g)
    {
        g.drawString("A simple applet", 20,20);
    }
}


i am using netbeans 5.5.1 with j2se 5 it compiles fine but on the applet it shows applte in the upper right of the window and at the bottom it states Start: applet not initialized when running it from netbeans however this is exactly as it is shown in the book. it gives me just the red X in the IE or Firefox browsers.
User is offlineProfile CardPM
+Quote Post

itpro4470
RE: Applet Help
12 Jul, 2007 - 06:33 PM
Post #5

D.I.C Head
Group Icon

Joined: 17 Jun, 2007
Posts: 123



Thanked: 1 times
Dream Kudos: 25
My Contributions
OMG i'm such a Fr|663N N3wb... I just forgot to add package p1; at the very begining of the code!!!!! excuse me while I bang my head on the wall. mrt.gif mrt.gif mrt.gif stupid.gif stupid.gif stupid.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 07:52PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month