Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

applet and application

 
salvador rcn
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it possible applet and application both can retain in a single code ?
in fact when i need applet i will use applet and when i need application i will use application . can they stay both in a sigle code ?

how do i invoke them if both of them exists ?

thankig you
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only real difference between an Applet and an application is the environment they run in. An Applet runs in a "sandboxed" environment in a browser, an application runs in a JVM with no such restrictions. If your Applet and application have common functionality it makes sens to create this in a set of shared classes so they can be invoked from either.
 
salvador rcn
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>it makes sens to create this in a set of shared classes so they can be invoked from either.

set of shared classes ?
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Typically, when I create GUI applications, I create one class that extends JFrame and another that extends JPanel. The frame class has minimal logic; it adds the panel to its content pane and creates a menu (if I want one). The JPanel class on the other hand has most of the logic to create the GUI controls (buttons, text fields, labels, etc.). This allows me to easily create a third class that extends JApplet and just adds the already-written panel with most of the GUI logic set up. I only have to provide an alternative to the menu that was in the JFrame class. In a program of any major complexity, there are also other classes that do the actual work of the program. It's usually a good idea to separate the "business logic" from the "GUI logic" as much as possible.

To clarify my written explanation above, here's a quick example of some code:

HTH

Layne
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic