Getting a red Oval to displayed on screen
Hey JPF members,
I'm a beginner in java trying to get a Red Oval to appear on screen. I'm also using a java book but im stuck with this problem. Any solution to this problem? :)
As you may know I'm trying to get a red oval to appear using my guy.java source file.
heres my code:
public class Guy extends java.applet.Applet {
/** initialization method that will be called after
* applet is loaded into the browser
*/
public void init() {
//
}
public void paint(java.awt.Graphics g){
g.drawOval(200,200,100,100);
g.fillOval(400, 300, 75, 288);
g.setColor(java.awt.Color.RED);
}
}
Re: Getting a red Oval to displayed on screen
Try making a call to super(g).
Code java:
public void paint(java.awt.Graphics g){
super(g);
g.drawOval(200,200,100,100);
g.fillOval(400, 300, 75, 288);
g.setColor(java.awt.Color.RED);
}
Also, don't know your whole code. Try called setVisible(true) within your guy() constructor.
Re: Getting a red Oval to displayed on screen
Quote:
Try making a call to super(g).
No. This will not compile, I believe you mean call super.paint(g). To the original poster, is your question that the applet does not draw the circles? Are you sure? How large is your applet (if its smaller than the smallest x/y (200,200) value you will not see the graphics)
Re: Getting a red Oval to displayed on screen
public class Guy extends java.applet.Applet {
/** initialization method that will be called after
* applet is loaded into the browser
*/
public void init() {
//
}
public void paint(java.awt.Graphics g){
super(g);
g.drawOval(200,200,100,100);
g.fillOval(400, 300, 75, 288);
g.setColor(java.awt.Color.RED);
setVisible(true);
So I took your advice but I get an error : Constructor call must be the first statement in a constructor. I dont understand what you mean by constructor?
Re: Getting a red Oval to displayed on screen
Yeah, that's what I meant.
super.paint(g);
Re: Getting a red Oval to displayed on screen
Quote:
Originally Posted by
warnexus
public class Guy extends java.applet.Applet {
/** initialization method that will be called after
* applet is loaded into the browser
*/
public void init() {
//
}
public void paint(java.awt.Graphics g){
super(g);
g.drawOval(200,200,100,100);
g.fillOval(400, 300, 75, 288);
g.setColor(java.awt.Color.RED);
setVisible(true);
So I took your advice but I get an error : Constructor call must be the first statement in a constructor. I dont understand what you mean by constructor?
I meant super.paint(g).
I was calling the Applet constructor with the Graphics g as a parameter.
Re: Getting a red Oval to displayed on screen
All I see is a White oval and a black oval. Why is not my set color red code in effect? I want a red oval on screen :)
Re: Getting a red Oval to displayed on screen
Call setColor before you draw :P
Re: Getting a red Oval to displayed on screen
Thanks Chris. Apparently the book did not even told me about this. Make perfect sense nevertheless set before you draw. I will remember this! Thanks a bunch Now I can move on to chapter 3\:D/