Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Problem with visual editor/visual class  RSS feed

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
myFrame.setVisible(true);

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!
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!