[Logo]
Forums Register Login
using applets in html
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!!
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).]
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
I tried it again, modifying the height tag up a bit, and I can now see the applet plain as day... Thanks!
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
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 RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
ScroogeXHTML 7.1 - RTF to HTML5 / XHTML converter
https://coderanch.com/t/690611/ScroogeXHTML-RTF-HTML-XHTML-converter


This thread has been viewed 866 times.

All times above are in ranch (not your local) time.
The current ranch time is
Feb 20, 2018 03:05:38.