0

EDIT: Made the question shorter.

I have 5 classes in my program, all are GUI's. The front page GUI, options GUI, and quiz GUI all are able to be called and setVisible works for them. The tips GUI and the score card GUI are unable to be displayed with setVisible. There is a button on the quiz GUI that is supposed to call the tips GUI. However, the button will not call the GUI. It does work though; I know this because I did a System.out.println("Button test") and it printed.

The tips GUI is just a panel with a label and 3 buttons. I have not done any listeners yet, just designed the panel with NetBeans. On my quiz GUI, I have the button to launch the tips GUI and the code is:

    private void tipsButtonMouseClicked(java.awt.event.MouseEvent evt) {                                        
    FrontPageGUI.tipsGUI.setVisible(true);
    System.out.println("Test to check if help button works");
    } 

This is just as I have done with calling the other GUI's. It is just the tips and the scorecard that do not display. I don't understand at all... On my options GUI, I have a button that starts the quiz with the same code and it works just fine. Hence my confusion.

Hopefully my editing makes it easier to understand my question.

Thanks all, Brandon

Sanellek
  • 1
  • 2
  • Since this part of the GUI is a JPanel which AFAIK cannot exists by itself as a standalone window, it would be useful to see your FrontPageGUI which I'm assuming it extends a JFrame. – Morfic Jun 18 '12 at 20:20

1 Answers1

3

This is in NetBeans so it did generate almost all the code you see. This is why I don't understand. Does anybody have an idea on what I might be missing? If any of the other four classes are needed, I will happily post them.

then without any comments,

replace your public static void main(String args[]) { from your code

public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            FrontPageGUI.tipsGUI.setVisible(true);
        }
    });
}

with

public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(new TipsMainGUI());
            frame.pack();
            frame.setVisible(true);
        }
    });
}

and output will be

enter image description here

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • Thank you for responding to me. I applied those changes and I still cannot get the GUI to launch when I click the tips button. The button code is just a FrontPageGUI.tipsGUI.setVisible(true); It still won't launch the GUI... Any other ideas? – Sanellek Jun 18 '12 at 21:26
  • @Sanellek: See also this [answer](http://stackoverflow.com/a/2561540/230513), which worked for me. – trashgod Jun 18 '12 at 22:29
  • @trashgod, I did what the answer trashgod linked said and I did what mKorbel said. I created a new panel that looks very similar to the output linked by mKorbel. Yet my button on my quiz GUI will still not open up that Tips Panel... I really do appreciate the help and I hate to keep asking, but, any other ideas? Thanks everybody! – Sanellek Jun 19 '12 at 00:08
  • @Sanellek: Please edit your question to include the revised [sscce](http://sscce.org/) that exhibits the problem you describe. – trashgod Jun 19 '12 at 01:57
  • @trashgod Sorry, first time posting. I edited my question and hopefully it helps :-) – Sanellek Jun 19 '12 at 03:26
  • @Sanellek: Your revised question is shorter, but not an [sscce](http://sscce.org/); please read the linked article. Also try running the examples without using the GUI editor. – trashgod Jun 19 '12 at 03:34
  • @trashgod I fear that posting all the code needed to see the problem would be a crazy amount of code. There is a timer, a question counter, an attempts counter, randomly generated numbers for the problems etc. If posting all is what I need to do, then I will. But it won't be a short post at all... – Sanellek Jun 19 '12 at 15:21
  • Exactly. That's the great value of an [sscce](http://sscce.org/); try paring it down to the least code that reproduces the problem. If you can't able to make mKorbel's or my example work, you may need to check your installation. – trashgod Jun 19 '12 at 17:25
  • Ok, problem solved. I created a JPanel form instead of a JFrame form. I didn't know this would cause issues but luckily another set of eyes caught it for me! Thanks for mKorbel and trashgod for your time =) – Sanellek Jun 19 '12 at 21:35