Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error to execute an applet?

 
yamini nadella
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got a simple applet from internet tutorial which draws lines on screen.

---------------
import java.applet.*;
import java.awt.*;

public class myapplet extends Applet {

int width, height;

public void init() {
width = getSize().width;
height = getSize().height;
setBackground( Color.black );
}

public void paint( Graphics g ) {
g.setColor( Color.green );
for ( int i = 0; i < 10; ++i ) {
g.drawLine( width, height, i * width / 10, 0 );
}
}
}
------------------

I wrote a small html script like below

<html>
<header>
<title>hello</title>
</header>
<body>
<h1>header</h1>
<h1>next<h1>
<applet code="myapplet.class" width=300 height=300></applet>
</body>
</html>
----------------

this html showing a gray color square but not the lines. I wonder is the above java script is correct?

But I tried with a applet class which is available in internet, that is working fine.

Thanks in advance
Yamini
 
ashish kulkarni
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you keeping the html page and class file in same folder,
try adding codebase="." to applet tag
 
yamini nadella
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I kept both files in same directory.
I also tried by keeping codebase="."in applet tag as

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

even i tried to execute by applet viewer, but it gave error message like below.

D:\eclipse\workspace\test>appletviewer myapplet
I/O exception while reading: D:\eclipse\workspace\test\myapplet
(The system cannot find the file specified)

Yamini.
 
Joe Ess
Bartender
Posts: 9339
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code in your first post worked fine for me. Did you compile your myapplet.java file to create a myapplet.class file?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic