Hi all, I'm a long time reader of the forums and thought this would be a good place to ask a question. For the record, I am very new to Java!
Basically, I have a MainClass which inherits JFrame, the constructor for which sets window size, title etc. It also adds a new instance of my class Board. In my constructor for Board, I try to set the background color, but I still have the grey background when I interpret using Eclipse. I know for a fact that Board is being added to the JFrame due to other things that I've painted to it.
Here's my MainClass
import javax.swing.JFrame; //Allows the game to use a window
public class MainClass extends JFrame{
//Main/program opening method
public static void main(String args[]){
new MainClass();
}
//Constructor
public MainClass(){
add(new Board());
setDefaultCloseOperation(EXIT_ON_CLOSE); //Ensures that the program ends properly
setSize(520, 545); //Sets the size of the window
setLocationRelativeTo(null); //Makes the window start in the centre of the screen
setTitle("Revision Game"); //Title-bar
setResizable(false); //The window can't be resized
setVisible(true); //Ensures the window is visible
}
}
And here's constructor of the JPanel Board that I'm trying to change the background of.
import java.awt.Color; //Allows the use of colour
import javax.swing.JPanel; //Allows the board to make a new panel in the window
public class Board extends JPanel{
//Constructor
public Board(){
setBackground(Color.black);
initGame();
}
}
There's a lot of code that I've omitted, but I've tried to include everything that's relevant.
Any Ideas?
Thanks in advance!
Morley