Thread: JFrame problem
View Single Post
  #1 (permalink)  
Old 01-24-2008, 11:40 PM
vassil_zorev vassil_zorev is offline
Member
 
Join Date: Dec 2007
Posts: 4
vassil_zorev is on a distinguished road
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:

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(); } }

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...
Reply With Quote
Sponsored Links