This week's book giveaway is in the Web Services forum.
We're giving away four copies of Microservices in Action and have Morgan Bruce & Paulo A. Pereira on-line!
See this thread for details.
Win a copy of Microservices in Action this week in the Web Services 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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!