4 Replies Latest reply: Oct 30, 2009 6:10 AM by 843807 RSS

    JComponent.setbackground(Color.BLACK) is NOT working

      I am creating Space Invaders game and have GamePanel as my JComponent, named panel. The background is not changing for sum reason though???
      import java.awt.*;
      import javax.swing.*;
      public class SpaceInvaders{
           public static final int WIDTH = 800;
           public static final int HEIGHT = 800;
           GamePanel panel;
           public SpaceInvaders()
                //create frame
                JFrame demoFrame = new JFrame("Space Invaders");
                //create panel
                GamePanel panel = new GamePanel(this);
                //add buttons
                JButton startButton = new JButton("Start");
                JButton stopButton = new JButton("Stop");
      import java.awt.*;
      import javax.swing.*;
      import java.awt.Image;
      import java.awt.event.KeyListener;
      import java.awt.event.KeyEvent;
      import java.awt.image.BufferStrategy;
      import javax.swing.*;
      import java.awt.event.*;
      public class GamePanel extends JComponent implements KeyListener, ActionListener
           SpaceInvaders game;
           static Player player1;
           Bullets bullet;
           private BufferStrategy strategy;
           static int alienNum = 36;
           static int alienRow = 6;
           static int alienCol = 6;
           static Aliens[][] aliens;
           static Bullets[] bullets;
           private Timer timer;
           int bulletNum=0;
           public GamePanel(SpaceInvaders game)
                this.game = game;
                player1 = new Player(this);
                aliens = new Aliens[alienRow][alienCol];
                for(int i=0; i<alienRow; i++)
                     for(int j=0; j<alienCol; j++){
                          aliens[i][j] = new Aliens(this);
                bullets = new Bullets[5];
                     bullets[0]=new Bullets(this);
                timer=new Timer(500, this);
           public void paintComponent(Graphics g)
                Image pic1 = player1.getImage();