Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

setForeground in Applet does not work (Netbeans under Linux)

807606May 25 2007 — edited May 25 2007
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.*;

public class Breakout extends Applet implements MouseListener, MouseMotionListener{

	int mouse_x, mouse_y;
	Thread t;

	public void init(){
		addMouseListener(this);
		addMouseMotionListener(this);
	}

	public void start(){
		t= new Thread();
		t.start();
	}

	public void run(){}

	public void mouseClicked(MouseEvent me){ }
	public void mouseEntered(MouseEvent me){ }
	public void mouseExited(MouseEvent me){ }
	public void mousePressed(MouseEvent me){ }
	public void mouseReleased(MouseEvent me){ }
	public void mouseDragged(MouseEvent me){ }
	public void mouseMoved(MouseEvent me){
		mouse_x = me.getX();
		if(mouse_x>=400)
			mouse_x=400;
		repaint();
	}


	public void stop() {}
	public void destroy(){ }
	public void 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!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 22 2007
Added on May 25 2007
5 comments
436 views