Results 1 to 2 of 2

Thread: JFrame problem

  1. #1
    vassil_zorev is offline Member
    Join Date
    Dec 2007
    Posts
    4
    Rep Power
    0

    Default JFrame problem

    Hey guys,
    to the point:
    I've got two "test classes" - one creates a JFrame instance and the other extends the JFrame class. They do exactly the same thing. The problem is one of them doesn't work. Now here are the classes:

    Java Code:
    public class GameTest {
        
        /**
         * Creates a new instance of GameTest
         */
        public GameTest() {
        }
        
        public void PlayAGame() {
            JFrame myFrame = new JFrame("Beginner Mode:");
            BeginnerMode panel = new BeginnerMode();
            myFrame.setSize(256,256);
            myFrame.setDefaultCloseOperation(myFrame.EXIT_ON_CLOSE);
            myFrame.getContentPane().add(panel);
            panel.PlayAGame();
            myFrame.pack();
            myFrame.setVisible(true);
        }
        
        public static void main(String ar[]){
            GameTest myGame = new GameTest();
            myGame.PlayAGame();
        }
    }

    Java Code:
    public class Navigator extends javax.swing.JFrame {
        
        /** Creates new form Navigator */
        public Navigator() {
            initComponents();
        }
        
        public void PlayAGame() {
            BeginnerMode panel = new BeginnerMode();
            this.getContentPane().add(panel);
            panel.PlayAGame();
            this.pack();
            this.setVisible(true);
        }
        
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                          
        private void initComponents() {
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 400, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 300, Short.MAX_VALUE)
            );
            pack();
        }// </editor-fold>                        
        
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    Navigator gameStart = new Navigator();
                    gameStart.PlayAGame();            }
            });
        }
    The second one doesn't work. What might be the reason? The problem is that the BeginnerMode panel doesn't display itself in the Navigator frame...

  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    Not having the BeginnerMode class, I had to comment out those lines where that applies. Once I did that, they both worked for me. Would you mind posting the missing class? I seem to recall that you might need a method similar to ... alwaysOnTop or to that effect.
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

Similar Threads

  1. Add an image to JFrame
    By Eranga in forum AWT / Swing
    Replies: 4
    Last Post: 02-01-2010, 03:09 PM
  2. Picture in a JFrame problem
    By saytri in forum New To Java
    Replies: 3
    Last Post: 01-12-2008, 09:44 AM
  3. JFrame problem
    By saytri in forum New To Java
    Replies: 6
    Last Post: 01-11-2008, 05:12 PM
  4. How to close a JFrame
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 05:33 PM
  5. Help with JFrame
    By Albert in forum AWT / Swing
    Replies: 2
    Last Post: 07-04-2007, 04:44 AM

Posting Permissions

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