jQuery in Action, 3rd edition
The moose likes Swing / AWT / SWT and the fly likes Problem with visual editor/visual class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem with visual editor/visual class" Watch "Problem with visual editor/visual class" New topic

Problem with visual editor/visual class

Nicol Green
Ranch Hand

Joined: Jan 30, 2010
Posts: 66
I would like to separate my GUI from other code.

I created Visual Class, and I would like to place main method in main class. How do I connect these too ? If I have this in main class:

MyFrame myFrame = new MyFrame();

It will not create an instance of my visual class MyFrame.

My Visual Class:

When I place main method in this class I cannot even run it. Since I have never used visual editor, is there as well, somthing else what I should know from start.

Any help is welcome and thank You!
Sveta Nartano

Joined: Feb 06, 2010
Posts: 2
Hi Nicol!

Main problem here - that you create your class extending JFrame, but you never add any components to the instance of THIS class. Besides you add all the components to the frame that is created in the getJFrame method, which is never called in your code.

You should replace your method

with constructor:

and call it from such main method:

Having your code you can use such main method:

But it's NOT appropriate in this context, because you don't really EXTEND JFrame class (you even don't need to write "extends JFrame" in declaration). You just create some GUICreator class that constructs and fill JFrame instance in getJFrame method.

Nicol Green
Ranch Hand

Joined: Jan 30, 2010
Posts: 66
Hi Sveta!

Now I see where is the problem! Thank you for quick response!

I haven't use Visual Editor before, so I assumed that "all is included"
Nicol Green
Ranch Hand

Joined: Jan 30, 2010
Posts: 66
I tried to replace that code with constructor, but it says "The methods setTitle, setSize and setContentPane are undefined for type MyFrame."

I thought it is bad practice to mix components from Visual Editor and components programme ?
I agree. Here's the link: http://aspose.com/file-tools
subject: Problem with visual editor/visual class
It's not a secret anymore!