[java] background color
I am having some trouble having my applet background color staying black can someone help me? it stays black for about 3 secs then it goes grey.
import java.awt.*;
import java.applet.*;
import javax.swing.*;
public class test extends JApplet {
public void init() {
setBackground(Color.black);
}
public void paint(Graphics screen) {
super.paint(screen);
Graphics2D screen2D = (Graphics2D) screen;
}
}
How about just drawing a filled rect the size of the applet and the color of your background? If your applet has animation you''ll have to erase the previous frame anyway.
=============================
silly programmer vb is for kids.
=============================
www.thejpsystem.com
=============================
silly programmer vb is for kids.
=============================
www.thejpsystem.com
I well have the applet up later today I am at my brothers right now...not at my home comp. Well I supose I could draw a rectangle but it should stay the same background color as the examples in my book say it should.
That is strange. It should stay black. I think that you might want to look into using a black rectangle the size of the applet like loserkid mentioned. This is handy especially if you start doing double buffering.
Adam
Adam
It is because you are overriding paint and doing nothing with it. JApplet is a Container, so calling its paint method does nothing but paint it's children. Get rid of the super.paint(Graphics) and replace it with Graphics.clearRect(x,y,h,w);
Whoa i see a problem here. I know now that your original problem was a real one, archigamer. I just made a simple applet to prove my point to myself, and when i substituted JApplet for Applet I got the same behavior as you. The Applet behaves correctly with no overridden paint method or a call to super.paint in it's paint method, but the JApplet requires a clearRect(x,y,h,w) call in it's paint method to do anything.
Edited by - Jim_Ross on September 7, 2000 10:28:01 AM
Whoa i see a problem here. I know now that your original problem was a real one, archigamer. I just made a simple applet to prove my point to myself, and when i substituted JApplet for Applet I got the same behavior as you. The Applet behaves correctly with no overridden paint method or a call to super.paint in it's paint method, but the JApplet requires a clearRect(x,y,h,w) call in it's paint method to do anything.
Edited by - Jim_Ross on September 7, 2000 10:28:01 AM
i dont understnad what you are saying...very well. anyways if it try the method the compiler spits out
"Background.java:13: non-static method clearRect(int,int,int,int) cannot be referenced from a static context
Graphics.clearRect(500,300,500,300);
^
1 error"
I am not to sure about the xy coords its asking for i dont see why it needs to info or what i need to put in for it. i tried clearRect without the "Graphics." doesnt compile heres the code if you still think you can help.
import javax.swing.*;
import java.awt.*;
public class Background extends JApplet
{
public void init()
{
setBackground(Color.black);
}
public void paint (Graphics screen)
{
Graphics.clearRect(500,300,500,300);
Graphics2D screen2D = (Graphics2D) screen;
}
}
"Background.java:13: non-static method clearRect(int,int,int,int) cannot be referenced from a static context
Graphics.clearRect(500,300,500,300);
^
1 error"
I am not to sure about the xy coords its asking for i dont see why it needs to info or what i need to put in for it. i tried clearRect without the "Graphics." doesnt compile heres the code if you still think you can help.
import javax.swing.*;
import java.awt.*;
public class Background extends JApplet
{
public void init()
{
setBackground(Color.black);
}
public void paint (Graphics screen)
{
Graphics.clearRect(500,300,500,300);
Graphics2D screen2D = (Graphics2D) screen;
}
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement