Results 1 to 3 of 3
- 03-06-2011, 01:50 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
[SOLVED]JFrame, isn't visible sometimes..
Hi.
When i start my application, sometimes i get a blank, Jframe(It's supposed to have black background) and when i press my start button, the game dosen't start, and sometimes it works perfectly. The console dosen't say any errors, so i'll post the code of all frames that's included.
Starter class, the Frame for the game.
Cube class, the class with the game.PHP Code:public class Starter extends JFrame{ public static void main(String[]args){ new Starter(); } public Starter(){ super("The Cube"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); setLocation(750, 250); setResizable(false); setSize(600, 400); Cube cu = new Cube(); addKeyListener(cu); add(cu); }
The menu , it shows up next to the game frame. The Menu class is inside the Cube class.PHP Code:public class Cube extends JPanel implements ActionListener,KeyListener{ public Cube(){ setVisible(true); setSize(600, 400); setBackground(Color.BLACK); setLocation(750, 250); addKeyListener(this); player = new Starter(20, 330); //////////////////////////////////////////////////////////////// lvl1part1 = new Starter(0, 200); lvl1part2 = new Starter(230, 200); lvl1win = new Starter(150, 0); //////////////////////////////////////////////////////////////// begin = new Timer(5, this); begin.start(); new Menu(); }
PHP Code:class Menu extends JFrame implements ActionListener{ private JButton level1; private JButton level2; public Menu(){ super("Menu"); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(300, 300); setLayout(null); setResizable(false); setLocation(450, 250); level1 = new JButton("Level 1"); level1.addActionListener(this); level1.setBounds(0, 80, 100 ,50); add(level1); level2 = new JButton("Level 2"); level2.addActionListener(this); if(!lvl1done){ level2.setEnabled(false); } else if(lvl1done){ level2.setEnabled(true); } level2.setBounds(101, 80, 100 ,50); add(level2); }Last edited by AndroidAppNewbie; 03-06-2011 at 02:17 PM.
-
It's the order of things that matter here: First add your components to the JFrame, then call setVisible(true). You'll also want to learn how to use layout managers and pack to full advantage.
- 03-06-2011, 02:13 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
Last edited by AndroidAppNewbie; 03-06-2011 at 02:25 PM.
Similar Threads
-
GUI is visible but content is not.
By seemant.bisht in forum AWT / SwingReplies: 3Last Post: 10-07-2009, 06:28 PM -
JTextField not visible?
By McChill in forum New To JavaReplies: 2Last Post: 05-20-2009, 12:17 AM -
Tab or Table not visible
By madhuvanthi2312 in forum SWT / JFaceReplies: 1Last Post: 04-25-2009, 09:00 AM -
Address bar not visible
By Akashchopra521 in forum New To JavaReplies: 0Last Post: 12-03-2008, 07:13 AM -
constructor ... is not visible
By emceenugget in forum New To JavaReplies: 2Last Post: 09-27-2008, 05:12 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks