I have been pulling my hair for days with this now. I simply want to create a black background and then add a JPanel on top of that with a green bg. New to Java and Swing obvisiouly. Over all I want to draw a football field in the panel, that displays 30 yards at a time and the background will scroll up and down following the location of the football. I figured with a panel I could draw the entire field and the panel would clip the remainder of the field. Problem is I cant get the second panel to even show. This is what I have.
public static void main(String[] args) {
drawPracticeField addField = new drawPracticeField();
//Create frame
JFrame backGroundWindow = new JFrame();
backGroundWindow.setSize(760, 760);
backGroundWindow.setUndecorated(true);
backGroundWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Utilizing apsolute positioning
backGroundWindow.setLayout(null);
//make Visible
backGroundWindow.setVisible(true);
//JPanel Background color component
JPanel backGroundPanel = new JPanel();
backGroundPanel.setSize(760,760);
backGroundPanel.setBackground(Color.black);
// add panel to container
backGroundWindow.add(backGroundPanel);
// addNewField JPanel
backGroundWindow.add(addField).setLocation(50, 40);
public class drawPracticeField extends JPanel{
public drawPracticeField() {
JPanel newField = new JPanel();
Dimension d = new Dimension();
d.setSize(600, 600);
newField.setPreferredSize(d);
}
/*
Draw outside boarders
Draw hash marks
Draw 10 yard lines
Add Line numbers Line of scrimage to 40 yard line
*/
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Color greenField = new Color (45, 96, 32);
g.setColor(greenField);
g.drawRect(50,40,600,600);
g.fillRect(50,40,600,600);
}
Thank you for any info you can give me.