• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert a Java Program to Web Applet

 
Namnai Kidorkar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone. A newbie in this forum, but not too newbie in java. I've a question that if you can provide some help, it will be really appreciated.

I've a code for a program, that includes three frames and connection to database. How hard it is to convert it to a web applet program?

I know the first step is to change that

....... extends JFrame {

to
.... extends JApplet {

but if someone did it before, how hard it would be and what kind of problem to expect. I'm trying to find out first if it is possible and if possible how hard it is.

please help or let me know if my post is not clear.

thanks in advanced.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Namnai,
Welcome to JavaRanch!

Unfortunately the answer to your question is that "it depends." The database connection makes it somewhat more complicated as it involves security and firewalls. It also depends on what version of Java the program/applet use.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our Applets forum...
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The book Core Java Volume 1 has (or at least in edition 2 it did) a great explanation about converting a Swing application into an applet. There is also an example of making a single class that is both! For my own Swing applications, I usually minimize the amount of code in my class that extends JFrame by putting most of the GUI logic in a class that extends JPanel. That way I can easily add the JPanel class to a JFrame or a JApplet. The most complicated thing my JFrame class does is create a JMenuBar. With that in mind, I would suggest moving all of the logic that creates Swing components to a JPanel class that you can add to either a JApplet or a JFrame. This also makes it so you can easily reuse the same code for both.

With that in mind, you also need to implement the init() method of your JApplet. Usually this is nearly identical to the JFrames constructor. You should probably also implement destroy() (I think that's the right method name) in order to clean up any resources your program uses, like the database connection. Off the top of my head, those are the two major changes you need to make. Like I said earlier, using a separate JPanel class to create the other visual components will help simiplify things a lot.

I hope this helps.

Keep Coding!

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