Hey guys,
I am having a problem with my code as it displays a blank JFrame to me whereas it should display a button.
The initialization code stands as follows:
JFrame frame = new JFrame(); Canvas canvas = new Canvas(); canvas.setSize(WIDTH, HEIGHT); frame.setResizable(false); frame.addWindowFocusListener(new WindowAdapter() { @Override public void windowGainedFocus(WindowEvent e) { canvas.requestFocusInWindow(); } }); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { closeRequested = true; } }); frame.add(canvas); try { Display.setParent(canvas); Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT)); frame.pack(); frame.setVisible(true); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); }
The above code creates the JFrame as well as the LWJGL display.
At some point during the program, the following method is called:
public void craft(){ JButton button = new JButton("Exit"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { STATE = GAME; remove(); frame.getRootPane().revalidate(); } }); frame.add(button); frame.getRootPane().revalidate(); }
AS a result nothing is displayed on the JFrame.
I have tested that the method does in fact run and has no errors in completing it, as well as altered the frame.getRootPane().revalidate(); to frame.revalidate(); with no success.
The only success I have had was due to me changing the frame.add(button); to frame.add(button, BlockLayout.Center); which results in the buttons filling the screen, I am not sure where to proceed from here in terms of getting this to work.
Anyone have any ideas?
Thanks
SACoder