Forums Register Login

using applets in html

+Pie Number of slices to send: Send
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!!
+Pie Number of slices to send: Send
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).]
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
I tried it again, modifying the height tag up a bit, and I can now see the applet plain as day... Thanks!
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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);
}
}

Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1152 times.
Similar Threads
How to get username from Win2K
Problems while Loading Applet...
Conflict between applets and JVM
Applets fail to load in a browser
Problem with inter-applet communication
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:15:43.