Re: JFrames not coming up?
I believe you have to set the components to be visible too with setVisible();
Re: JFrames not coming up?
I added that for all my JFrames, included the inherited one.
It seems it just sits there when I run, nothing comes up.
Re: JFrames not coming up?
Did you set the textAreas and JButtons to be visible too?
Also, I think I found a typo:
frame[1].setVisible(true);
try frame[i].setVisible(true);.
Also, I believe you could get away with not having button in your actionListener() and instead having
if (e.getActionCommand().equals(action[0].getText()))
I know that
if (e.getActionCommand().equals("Run")))
will go into affect if a button that has the text "Run" is clicked.
Re: JFrames not coming up?
Are there exceptions thrown? If so please post the entire stack trace...for instance, calling
Code :
frame[1].setVisible(true);
in one of the initialization loops should result in a NullPointerException
Re: JFrames not coming up?
I noticed that, and it was fixed. oddly it didn't throw a nullpointer exception.
And I'll try that e.getActionCommand()
Re: JFrames not coming up?
Alright I got it displaying, now I'm getting a NullPointException at
Code :
scores = sg.getTestGrades();
Re: JFrames not coming up?
Re: JFrames not coming up?
Initialize sp.
You must never have initialized it.
Re: JFrames not coming up?
Simple. A NullPointerException indicates that you are attempting to dereference a variable that hasn't been initialized, or has had its value set to null. If the line you posted is giving rise to the exception, sg is null.
Trace the code execution and find out why a value hasn't been assigned to sg.
db
edit :humph: No response for nearly 2 hours and the penguin gets in a minute before me ;)
Re: JFrames not coming up?
I know I initialized sg. I always hit the construct button before I hit any of the action buttons.
When I hit my Action 1 button, it gives me a NPE for scores.
I know scores is set to null, but why won't it take the returned array?
Re: JFrames not coming up?
Re: JFrames not coming up?
Um, ok, I have a few questions and comments for you and for some of the people helping:
First off, the reason the JFrame would not be showing is that you haven't used the JFrame.setVisible(true) method. That was said by javapenguin I believe. What isn't necessary is to set each component visible. By default, they are visible. The JFrame however, is not visible by default (dunno why).
You also have a few unnecessary method calls. Specifically, this in your GUI class:
Code java:
frame[i].getContentPane();
frame[i].setBounds(300,300,100,100);
frame[i].setResizable(true);
...
frame[1].setVisible(true);
I'm unsure why you included these calls. The JFrame.getContentPane() method returns a Container, but you are not capturing that Container, so it is just getting garbage collected. The JFrame.setBounds() method sets the boundary or something of the JFrame. Why not just use the JFrame.setSize(int width,int height) method? I suspect the x and y coordinate of 300 and 300 you are sending in the JFrame.setBounds() method might give some unexpected results. It is also unnecessary to call the JFrame.setResizable(true) method, as JFrame are already resizable by default. Lastly, are you aware that you are only setting the second JFrame in your array visible with the call frame[1].setVisible(true);?
Now we get into an area that I'm not positive about, but shooting guesses is always fun.
This chunk of code:
The API reads as follows for the Container.add() method you are using:
Quote:
Note: If a component has been added to a container that has been displayed, validate must be called on that container to display the new component. If multiple components are being added, you can improve efficiency by calling validate only once, after all the components have been added.
This probably means that you need to call the Container.validate() method after adding all of your components. However, this might not be the problem, just guessing.
Work on those issues, I think there were some more I noticed, but I've forgotten them...
Re: JFrames not coming up?
I've gotten the JFrames fixed. I entirely eliminated the use of the JFrame array.