Results 1 to 3 of 3

Thread: JFrame window problem

  1. #1
    Join Date
    Nov 2009
    Posts
    446

    JFrame window problem

    Hi
    I have problem with JFrames in Java, the program still has a same background color. Please check the program
    Code:
    class gameFrame extends JFrame implements Runnable { //
        public void run(){
            paintIt p = new paintIt();
            add(p);
        }
        public gameFrame(){
            
            
            
            //paintIt p = new paintIt();
            //add(p);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(1000,1500);
            setTitle("Image test");
            getContentPane().setBackground(Color.WHITE);
            setVisible(true);
        }
    }
    Any help or suggestions will be appreciated. Thanks in advance

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: JFrame window problem

    I did not understand paintln object? Is it a JPanel? I think this is repeatedly added to the JFrame's contentPanel. It does not matter what color you set the contentPanel as it will bet you will never see it. I did used one JPanel as an animation panel and then swap images in the same panel rather than creating and adding a bunch of components. Your way seems somewhat inefficient to me and may risk running out of memory. Check your program throughly and if any problems then post back again.

  3. #3
    Join Date
    Nov 2009
    Posts
    446

    Re: JFrame window problem

    Hey I checked my program again, I have done some modification and posted you the new program. Please analyze my program again. Thanks for the help, hooping you will solve my problem.
    Code:
    class MyTimerActionListener implements ActionListener {
          public void actionPerformed(ActionEvent e) {
              if (!(Player.Y+Player.SizeY+2> 400)){
                  Player.CharVel[1] += 2;
              } else {
                  Player.CharVel[0] = (Player.CharVel[0]/Player.Friction);
              }
            if (Player.Y+Player.SizeY> 400){
                
                Player.CharVel[1] = -Player.CharVel[1]/2;
                Player.Y = 400-Player.SizeY;
            }
            Player.Y += Player.CharVel[1];
               Player.X += Player.CharVel[0]+Player.CharWalk[0];   
            TestingArea.gf.repaint();   
          }
    }

Similar Threads

  1. Problem of overlapping JLabel on JFrame with background
    By Baazigar in forum Software Development
    Replies: 6
    Last Post: 14-12-2010, 02:09 PM
  2. Pass JFrame to actionlistener
    By Freeza 2 in forum Software Development
    Replies: 5
    Last Post: 23-08-2010, 06:30 PM
  3. What is the use of JFrame class?
    By Ram Bharose in forum Software Development
    Replies: 5
    Last Post: 17-02-2010, 10:56 AM
  4. Anchoring a JFileChooser in a JFrame
    By technika in forum Software Development
    Replies: 5
    Last Post: 27-01-2010, 11:27 AM
  5. How to pass object to jframe
    By Brunoz in forum Software Development
    Replies: 3
    Last Post: 06-08-2009, 11:36 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,566,931.43891 seconds with 17 queries