setForeground in Applet does not work (Netbeans under Linux)

I'm attempting to make a Breakout version of java (if I go through with it) and the first issue that I encountered is that I can't change the color of the moving rectangle (you know, the thing you hit the ball with). I tried the code under Textpad on a Windows machine and that worked fine, but not under Netbeans in Linux using jdk 1.6.0_01.

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

publicclass Breakoutextends Appletimplements MouseListener, MouseMotionListener{

int mouse_x, mouse_y;

Thread t;

publicvoid init(){

addMouseListener(this);

addMouseMotionListener(this);

}

publicvoid start(){

t=new Thread();

t.start();

}

publicvoid run(){}

publicvoid mouseClicked(MouseEvent me){}

publicvoid mouseEntered(MouseEvent me){}

publicvoid mouseExited(MouseEvent me){}

publicvoid mousePressed(MouseEvent me){}

publicvoid mouseReleased(MouseEvent me){}

publicvoid mouseDragged(MouseEvent me){}

publicvoid mouseMoved(MouseEvent me){

mouse_x = me.getX();

if(mouse_x>=400)

mouse_x=400;

repaint();

}

publicvoid stop(){}

publicvoid destroy(){}

publicvoid paint(Graphics g){

setBackground(Color.black);

setForeground(Color.white);//doesn't work

g.drawRoundRect(mouse_x, 600, 50, 20, 20, 20);

}

}

I'm wondering if it's because the Applet under Linux uses the Native l&f theme while appets under Windows uses the Windows l&f theme.

Any thoughts would be helpful!

[3663 byte] By [angryfirelorda] at [2007-11-27 5:30:30]
# 1
You should not be calling setForeground or setBackground in the paint method.Just call them in start() or init().And if you did, you'd have to call super.paint(g) after calling those methods anyway to get it to paint the background... Which you should usually do anyway.
bsampieria at 2007-7-12 14:54:48 > top of Java-index,Java Essentials,Java Programming...
# 2

> setForeground(Color.white); //doesn't work

> g.drawRoundRect(mouse_x, 600, 50, 20, 20, 20);

Change this to:

g.setColor(Color.WHITE);

g.drawRoundRect(mouse_x, 600, 50, 20, 20, 20);

You can move the background setting into method init(), calling it once is enough.

> I'm wondering if it's because the Applet under Linux

> uses the Native l&f theme while appets under Windows

> uses the Windows l&f theme.

You use java.awt.Applet, so you use AWT which means there's no L&F theme (as in Swing) but it's native components being responsible.

quittea at 2007-7-12 14:54:48 > top of Java-index,Java Essentials,Java Programming...
# 3
Ok, I tried putting the setBackground & setForeground in init() with capital letters for Color.WHITE, but to no avail.Here's a snapshot (may take a few seconds to come up): http://server6.theimagehosting.com/image.php?img=snapshot1.442.png
angryfirelorda at 2007-7-12 14:54:48 > top of Java-index,Java Essentials,Java Programming...
# 4
> Ok, I tried putting the setBackground & setForeground> in init() with capital letters for Color.WHITE, but> to no avail.> Please read reply #2.
cotton.ma at 2007-7-12 14:54:48 > top of Java-index,Java Essentials,Java Programming...
# 5

> Please read reply #2.

Tried that with super.paint(g), but that didn't work either. In fact, I don't see anything wrong in terms of coding...

If I can get Eclipse with all of its 10 million dependencies installed, I'll try that instead and see if that makes a difference, but I think it's something with appletviewer.

Edit: Oops, I was looking at reply #1. Yes, the setColor(Color.WHITE) did the trick. Thank you for helping me with my stupidity. =]

Message was edited by:

angryfirelord

angryfirelorda at 2007-7-12 14:54:48 > top of Java-index,Java Essentials,Java Programming...