Results 1 to 8 of 8

Thread: JFrame Trouble

  1. #1
    Join Date
    Jul 2013
    Location
    Wisconsin, USA
    Posts
    60
    Rep Power
    0

    Default JFrame Trouble

    I'm just trying to make a JFrame window for my application:

    Java Code:
    package mmlgame;
    import java.awt.*;      // Needed for the FlowLayout manager
    import javax.swing.*;
    
    /**
     * This class demonstrates how to use a FlowLayout manager
     * with a JFrame object's content pane.
     */
    
    public class GameScreen extends JFrame
    {
       private JButton btnNewGame;//Some buttons
       private JPanel pnlNavigation, pnlGameScreen;//component containers
       private JComboBox cboImages;//Images for game screen cards
       private final int WINDOW_WIDTH = 600;//Window width
       private final int WINDOW_HEIGHT = 300;//Window height
    
       //Start of Constructor
       public GameScreen()
       {
          // Set the title bar text.
          super("MMLG");
    
          // Set the size of the window.
          setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    
          // Specify what happens when the close button is clicked.
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
          // add a FlowLayout manager to the content pane.
    		// Specify right alignment.
          this.setLayout(new FlowLayout(FlowLayout.RIGHT));
          
          //Create the panels:
          pnlNavigation = new JPanel();
          pnlGameScreen = new JPanel();
          
          pnlNavigation.setLayout(new FlowLayout());
              
          //Create the buttons:
          btnNewGame = new JButton("New Game");      
          
          //Create the ComboBox:
          cboImages = new JComboBox();
          
    
          //Add the buttons and combo box to the Navigation Panel:
          pnlNavigation.add(btnNewGame, cboImages, FlowLayout.RIGHT);
          //pnlNavigation.add(cboImages, FlowLayout.RIGHT);
          
          
          //Add the Navigation Panel to the content pane, specifying a right
          //alignment:
          this.add(pnlNavigation, FlowLayout.RIGHT);
          this.add(pnlGameScreen, FlowLayout.LEFT);
          
    
          //Display the window.
          setVisible(true);
       }
       //End of Constructor
       
       public static void main(String[] args)
       {
          new GameScreen();//New instance ignored?
       }
    }
    I don't have any errors, but when I tried to run the file, I got this:

    JFrame Trouble-jframetrouble.png

    Any ideas?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,607
    Rep Power
    23

    Default Re: JFrame Trouble

    What does the API doc say for the add() method you are trying to use?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    Jul 2013
    Location
    Wisconsin, USA
    Posts
    60
    Rep Power
    0

    Default Re: JFrame Trouble

    I'm not sure. How do I check the API doc in Netbeans?

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,607
    Rep Power
    23

    Default Re: JFrame Trouble

    I use a browser to go to this site: Java Platform SE 7
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Join Date
    Jul 2013
    Location
    Wisconsin, USA
    Posts
    60
    Rep Power
    0

    Default Re: JFrame Trouble

    Norm, why didn't you just tell me to use "Ctrl + Space" in Netbeans?

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,607
    Rep Power
    23

    Default Re: JFrame Trouble

    I have no idea how to use your IDE.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    748
    Rep Power
    2

    Default Re: JFrame Trouble

    And all of a sudden it's your fault, Norm. Amazing how fast the tables turn here :)

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,607
    Rep Power
    23

    Default Re: JFrame Trouble

    Win some, lose some.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Trouble adding a BufferedImage to a JFrame
    By ejyption in forum AWT / Swing
    Replies: 5
    Last Post: 09-11-2013, 11:04 PM
  2. Click in JFrame Titlebar sets the JFrame Opaque
    By tim8w in forum AWT / Swing
    Replies: 1
    Last Post: 02-02-2013, 07:29 AM
  3. Replies: 3
    Last Post: 11-27-2011, 05:18 AM
  4. Trouble adding JPanel to JFrame with NetBeans IDE
    By ozzyman in forum New To Java
    Replies: 1
    Last Post: 05-23-2011, 10:35 PM
  5. Replies: 5
    Last Post: 06-14-2010, 06:10 PM

Posting Permissions

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