• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Polymorphism main() and JFrame - impossible?

 
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Usually main class of program extends JFrame, sometimes implements ActionListener. In main class is method main(), where
- is MainClass obj = new MainClass(); and obj.setVisible(true);

Sometimes by other way:

This way is in book by Horstmann and Cornell.
Why is so? What way is better?

But my ask: is possible main() function not in top of code?
In other words: I have class A and A.main()
B extends A and has no main().
Class A can be in library, and user edit only B. It is possible?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andrzej Borucki wrote:But my ask: is possible main() function not in top of code?
In other words: I have class A and A.main()
B extends A and has no main().
Class A can be in library, and user edit only B. It is possible?


Sure; although I'm not quite sure what you mean by "user edit only B". I don't usually want users editing ANY classes I write. Or did you mean extending?

IMO, main() should only be used for launching, and should rarely contain more than a couple of lines. I'm not a GUI expert though, so I'm not familiar with the style suggested in your book, or why you would use it; but I'm sure they wouldn't suggest it without a good reason.

If you want another alternative, you might want to look at the MainIsAPain page.

Winston
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The comments in the posted code are wrong. The program does not demonstrate a worker thread; it demonstrates respecting Swing's single threaded rule.

And in professional programming, I would be very surprised to find a main class that extends JFrame or indeed implements ActionListener. Those are shortcuts used in tutorials and beginner books in order to squeeze all the needed parts into one class, and aren't even the best way to do that.
 
Andrzej Borucki
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Darryl Burke wrote:TAnd in professional programming, I would be very surprised to find a main class that extends JFrame or indeed implements ActionListener. Those are shortcuts



Where can I find not very large professional program - example?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic