Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (769)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: JFrames and JPanels on: 2012-01-14 02:39:00
Sorry that few lines of code where I added the Panels to the frame
2  Game Development / Newbie & Debugging Questions / JFrames and JPanels on: 2012-01-14 01:18:09
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.
Pages: [1]
 
EgonOlsen (1672 views)
2018-06-10 19:43:48

EgonOlsen (1720 views)
2018-06-10 19:43:44

EgonOlsen (1161 views)
2018-06-10 19:43:20

DesertCoockie (1587 views)
2018-05-13 18:23:11

nelsongames (1187 views)
2018-04-24 18:15:36

nelsongames (1716 views)
2018-04-24 18:14:32

ivj94 (2541 views)
2018-03-24 14:47:39

ivj94 (1767 views)
2018-03-24 14:46:31

ivj94 (2847 views)
2018-03-24 14:43:53

Solater (972 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!