Jump to content

  • Log In with Google      Sign In   
  • Create Account

[java] background color


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 ARCHIGAMER   Members   -  Reputation: 122

Like
Likes
Like

Posted 31 August 2000 - 11:50 AM

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; } }

Sponsor:

#2 Jim_Ross   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 September 2000 - 05:59 AM

Can I see this applet? Doesn''t look like it should behave that way from the code.

#3 loserkid   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 September 2000 - 08:15 AM

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

#4 ARCHIGAMER   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 September 2000 - 05:23 PM

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.

#5 ARCHIGAMER   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 September 2000 - 10:17 AM

sorry for the hold up. had a busy couple of days.

here

#6 isrking   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 September 2000 - 12:08 PM

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



#7 Jim_Ross   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 September 2000 - 12:17 PM

try a repaint() after the setBackgroundColor

#8 ARCHIGAMER   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 September 2000 - 12:27 PM

repint doesnt help or do anything

#9 Jim_Ross   Members   -  Reputation: 122

Like
Likes
Like

Posted 07 September 2000 - 03:21 AM

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

#10 ARCHIGAMER   Members   -  Reputation: 122

Like
Likes
Like

Posted 07 September 2000 - 08:18 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;
}
}




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS