problems with JFrame!?

Discussion in 'Java' started by ktjk, Dec 10, 2009.

  1. ktjk

    ktjk New Member

    Joined:
    Dec 10, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi just wondering if anyone could solve a problem with a not being able to load a JFrame in a java game ive been coding, I've no idea how how or why but on loading the program the game is loading properly with no errors but no frame is visible ill include a sample of some of the code i've used so far any help would be much appreciated!:
    Code:
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.Graphics;
    import javax.swing.JFrame;
    
    
    public class Game extends JFrame {
    	
    	Board theBoard = new Board();
    	FileHandler theFileHandler = new FileHandler(theBoard);
    	Graphic Drawspace = new Graphic(theBoard);
    	
    	Game(){
    		
    		getContentPane().setLayout(new FlowLayout());
    		getContentPane().add(Drawspace);
    		Drawspace.repaint();
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    		pack();
    		setVisible(true);
    		
    		}
    	
    		public void paint(Graphics g){
    			paintComponents(g);
    		}
    		
    	
    	
    	public static void main(String[] args) {
    		Game theGame = new Game();
    	}
    
    }
     
    Last edited by a moderator: Dec 11, 2009
  2. ewaldhorn

    ewaldhorn New Member

    Joined:
    Feb 16, 2010
    Messages:
    36
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    Cape Town, South Africa
    Home Page:
    http://www.javak.co.za
    Hi.

    Without knowing what Board and Graphic is / does, it's a bit difficult to guess what might be wrong.

    Could you perhaps explain those classes and then we can get to the bottom of the problem?

    Best regards
    Ewald
     
  3. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    you mean you don't see the windows(jframe) at all or the graphics you draw inside?

    try this
    change
    pack();
    with
    setSize(300,300);

    if that doen't help post the whole code ,with all classes needed.
     
  4. tryhardbox

    tryhardbox New Member

    Joined:
    Feb 1, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    heres a simple soulution inset this in between the first brackets, an serror will apear double click the light bulb and click the second option

    code:
    Code:
    public class te {
    	public static class JavaCraft {
    		public static void main (String[] args) {
    		JFrame frame= new JFrame("JavaCraft Alpha 0.01");
    		frame.setVisible(true);
    		frame.setSize(600,600);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		}
    	}
     
    Last edited by a moderator: Feb 2, 2012

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice