Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Require assistance with a contentPane problem please.

    Hi All,

    I would appreciate it if someone could assist with a contentPane problem that I have. I have written a 2D game that works when I run it from my IDE (netneans). It will not work correctly when I run the Executable Jar File outside of my IDE. Basiclly if I call ‘f.pack();’ (f is the JFrame) everything works fine but when I run the game outside of the IDE the I get a transparent JFrame which I cannot do anything with. If I remove ‘f.pack();’ the game works outside of the IDE (likewise inside) but I have no contentPane which is holding: an inventorylabel – this is just a label, a JPanel – this shows Icon which the player collides with during the game to show what the player is holding and a JTextArea – this gives the player information such as “you need to speak to......”.
    I have tried adding a BorderLayout to the contentPane which will not allow me to add the three different components needed or change the text / picture etc when a collision occurs. I also need the three components in a row to the EAST and it will not allos me to set the horizontal axis (but will allow the vertical)
    I’ve tried calling validate(), show(), and various other methods from the API but to no avail.

    The Board class is just a class which looks for collision detections from other classes and updates the JPanel and JtextArea when a collision occurs. The Frame class creates a new instance of Board and holds my main method which calls run() from my Board class. As the Board class is 1600 lines long I have just inserted the area of code where I think my problem may be, let me know if you need more and I will post it. Apologies if I have my [CODE] tags wrong.
    [CODE]
    //Other Instance Variables
    JFrame f = new JFrame();
    JTextArea textArea;
    JPanel inventoryPanel;
    JLabel inventoryLabel;
    Container contentPane;
    public Board()
    //Other variables inisalised in the constructor
    inventoryPanel = new JPanel();
    inventoryLabel = new JLabel("Inventory");
    textArea = new JTextArea(text[0]);
    contentPane = f.getContentPane();
    f.setPreferredSize(new Dimension(800, 550));
    contentPane.add(inventoryLabel);
    contentPane.add(inventoryPanel);
    contentPane.add(textArea);
    inventoryLabel.setBounds(610, 20, 170, 40);
    inventoryPanel.setBounds(610, 80, 170, 200);
    f.pack();
    textArea.setBounds(610, 300, 170, 225);

    public void paint(Graphics g)
    super.paintComponent(g);
    contentPane.paint(g);
    //Paints other objects from other classes
    public void run()
    f.add(new Board());
    try
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int height = screenSize.height;
    int width = screenSize.width;
    f.setSize(width/2, height/2);
    f.setSize(new Dimension(800, 590));//600, 585 for programming otherwise
    f.setLocationRelativeTo(null);// Centre JFRAME
    f.setVisible(true);
    try
    Thread.sleep(50);
    Catch
    Finally
    [CODE]

  • #2
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Resolved


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •