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