tags:

views:

705

answers:

3

Hi all,
I was wondering if anyone could help me on using NetBeans....
I just need one piece of advice.
Here's the problem:
When I create a new Java Desktop App I can manage to "call" another Frame Form class from the skeleton class that is created. But when I create another class and edit it's design using the Swing gui editor, I cannot instanciate the class from any other one...
For example if i do this:

new JFrame();

I don't know wether the class is instanciated or not because I don't get any visual feedback from the application ( the JFrame doesn't appear...).

maybe this is a stupid question with a very simple answer... But i really need to figure this out..

Thank you in advance.

Edit:
To clarify: JFrame is my own class.

+1  A: 

new JFrame().setVisible(true) ?

ante.sabo
I think you misunderstood something.... mainly because of me..you see... JFrame is my class.... I just gave it a very common name lol... and therefore you thought i was referring to JFRAME java predefined class...in this case, JFrame is a class of my own and I want to create a new instance of it from another class.... it just doesn't display anything onscreen...
Do you except that people here can debug your home-brew classes, if you don't even show the code? Come on...
Joonas Pulakka
+1  A: 

You have to add the JFrame to something before you can see it.

JFrame jf = new JFrame();
panelYouWantToAddFrameTo.add(jf);
Mark
lol.... that seems pretty simple.... I think that's it.... i was just a litte confused when i switched from eclipse IDE to netbeans....thank you !P.S: this site is really gr8. People seem to be very helpfull...
This is actually wrong. You dont not add a JFrame to a JPanel it is the other way around. For a JFrame to be visible you call setVisible(true) on it.
willcodejavaforfood
willcodeforfood: JFrame is Richard's own class, so he has to add his JFrame to any other panel.
furtelwart
+2  A: 

you see... JFrame is my class.... I just gave it a very common name lol...

It is not a good idea to give your classes that same names as the Java API classes - it is very confusing.

The preferred way to use Matisse (NetBean's form designer) is to create JPanels rather than JFrames - this improves testability. Then you would create a small main method to actually create the JFrame.

Here is an example. Say you have created a panel in Matisse called MyPanel that contains all your components. You could use the following main to launch the application:

public class AppMain {
    public static void main(String[] args) {
        javax.swing.JFrame frame = new javax.swing.JFrame();
        frame.add(new MyPanel());
        frame.setVisible(true);
    }
}
Russ Hayward
You guys got it all wrong lol :)I created a new JFrame Form and named id Test. But in my post's example, i named it JFrame. Sorry for the confusion..BTW, i didn't manage to solve it yet....:(