wood burning stoves 2.0*
The moose likes Applets and the fly likes using applets in html Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "using applets in html" Watch "using applets in html" New topic
Author

using applets in html

tod murphey
Greenhorn

Joined: Jan 13, 2001
Posts: 22
Hello all,
I'm trying to practice some java every day, to eventually do some actual work in it! In running applets, one option to test them is to place them in a basic html page and run appletviewer, or load the page from a browser (I assume IE can process applets to the same degree as Netscape??). However, I can't get this one running:
import java.awt.*;
import java.applet.Applet;
public class SimplePaint extends Applet {
public void paint(Graphics g) {
g.setColor(Color.black);
g.fillRect(0,0,300,300);
g.setColor(Color.white);
g.fillOval(30,30,50,50);
}
}
I know the html code is fine, but I'll post it anyway...
<HTML>
<HEAD>
<TITLE> A Simple Program </TITLE>
</HEAD>
<BODY>
Here is the output of my program:
<APPLET CODE="SimplePaint.class" WIDTH=150 HEIGHT=25>
</APPLET>
</BODY>
</HTML>
When I run it either way, it doesn't produce what's expected- a white oval on black background. Can you help me out?
thnx!!
Suneel Setlur
Ranch Hand

Joined: Nov 26, 2000
Posts: 202
Hi
I don't see any problem with your program. It works fine.
It does give a black background and a white oval.
May be you can simply try increasing the height parameter in your html.
Regards
Suneel

[This message has been edited by Suneel Setlur (edited January 14, 2001).]


Suneel
Golam Newaz
Ranch Hand

Joined: Jan 08, 2001
Posts: 64
Hi,
Your program is ok but Problem arised in your applet. You gave
your height=25 that is the problem. You drew your fillOval
method x=30 and y=30. But you gave 25 height in your applet.
Look your html applet code height and your java fillOval
method's height's i.e. y-axis, both of those are related matter. So increase your applet height point like 100 instead of 50 (
you gave before in height field).
<HTML>
<HEAD>
<TITLE> A Simple Program </TITLE>
</HEAD>
<BODY>
<APPLET CODE="SimplePaint.class" WIDTH=150 HEIGHT=100>
</APPLET>
</BODY>
</HTML>
Then you will find the solution.
Thanks,
Newaz
tod murphey
Greenhorn

Joined: Jan 13, 2001
Posts: 22
I tried it again, modifying the height tag up a bit, and I can now see the applet plain as day... Thanks!
Golam Newaz
Ranch Hand

Joined: Jan 08, 2001
Posts: 64
Kindly paste this code into notepad and compile it in jdk1.2 ver.
And give the same html code to run it. Everything should be ok.

import java.awt.*;
import java.applet.*;
public class SimplePaint extends Applet {
public void paint(Graphics g) {
g.setColor(Color.red);
g.fillRect(0,0,300,100);
g.setColor(Color.white);
g.fillOval(25,25,50,50);

}
}
Thanks,
Newaz
vineeta pillai
Greenhorn

Joined: Jan 18, 2001
Posts: 2
I think the problem with your code is that you are
first setting the colour to black and then setting it again to
white again before drawing the oval.
I Hope this will work.
import java.awt.*;
import java.applet.*;
public class SimplePaint extends Applet
{
public void paint(Graphics g)
{
g.drawRect(0,0,25,100);
g.setColor(Color.black);
g.fillOval(5,5,10,10,20,10);
g.setColor(Color.white);
}
}

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using applets in html