The Artima Developer Community
Sponsored Link

Java Answers Forum
Applet

3 replies on 1 page. Most recent reply: Nov 10, 2005 7:11 AM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Makhmud Kasumov

Posts: 16
Nickname: marik
Registered: Oct, 2005

Applet Posted: Nov 10, 2005 5:25 AM
Reply to this message Reply
Advertisement
Hi all!
I wrote a simple applet
public class MyApplet extends Applet {
  public void init()
  {
    System.out.println("Hello, world!");
  }
}


Now I write a test HTML-page for it

<html>
<head><title>MyApplet</title></head>
& lt;body>
<applet code="MyApplet.class">
</applet>
</body>
</html>

Both files (MyApplet.class & myapplet.html) are put in the same folder. And when I open the page with IE it says it can't find MyApplet class. Whatever I do.

I tried many modifications. I used 'codebase ' attribute, I tried "myapplet.class", just "MyApplet" and many other things but - zero. I checked CLASSPATH and JAVAHOME environment paths - seems to be ok...

What am I doing wrong?


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Applet Posted: Nov 10, 2005 5:50 AM
Reply to this message Reply
System.out.println() prints to the Std I/O stream.
It draws nothing on the canvas of your applet. include this method
for which your Applet will be looking for.
    public void paint(Graphics g) {
	//Draw a Rectangle around the applet's display area.
        g.drawRect(0, 0, size().width - 1, size().height - 1);
 
	//Draw Hello World in Rectangle
        g.drawString("Hello World", 5, 15);
    }
    


You may also want your HTML to specify width and height of your applet

<applet code="yourApplet.class" width="600" height="400">

Makhmud Kasumov

Posts: 16
Nickname: marik
Registered: Oct, 2005

Re: Applet Posted: Nov 10, 2005 6:24 AM
Reply to this message Reply
> System.out.println() prints to the Std I/O stream.
> It draws nothing on the canvas of your applet.
> let. include this method
> for which your Applet will be looking for.
>
>     public void paint(Graphics g) {
> 	//Draw a Rectangle around the applet's display area.
> g.drawRect(0, 0, size().width - 1, size().height -
> height - 1);
> 
> 	//Draw Hello World in Rectangle
>         g.drawString("Hello World", 5, 15);
>     }
>     

>
> You may also want your HTML to specify width and
> and height of your applet
>
> <applet code="yourApplet.class" width="600"
> 600" height="400">

Ok ok, I skipped the whole class declaration. I do have paint() method in MyApplet. It still won't launch.

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Applet Posted: Nov 10, 2005 7:11 AM
Reply to this message Reply
May be you need to Jar the file and define the Class-path
in your Manifest. then include the jar file as an archive
in your <applet> tag.

Flat View: This topic has 3 replies on 1 page
Topic: Get current URL from Internet explorer Previous Topic   Next Topic Topic: own urlclassloader

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use