0

I have a simple program I made and I want to make it into an Applet so its runnable on a web page, but the only way I've learned how to do that so far is by extending JApplet. I have the following:

public class HolidayTester extends JFrame {

and from what I've learned if I want to make an applet it needs to be

public class HolidayTester extends JApplet {

So how do I go about extending both classes? Because I know you cannot have

public class HolidayTester extends JFrame, JApplet {

or anything of the sort. Any suggestions or better ways to do this?

Luminusss
  • 571
  • 1
  • 6
  • 27

2 Answers2

1

Consider using Java Web Start to launch an application from a link.

Otherwise, if applet is what you need then extend JApplet and add all the relevant methods - init(), start(), stop(). Note that unlike Java applications, applets do not need to implement a main method. See Getting Started With Applets tutorial. It covers applet's methods, milestones, its life cycle and its deployment.

tenorsax
  • 21,123
  • 9
  • 60
  • 107
  • My issue is that I don't know how to implement JApplet with a JFrame. I don't know how to take my working code and present it into an applet. – Luminusss Dec 05 '13 at 22:21
  • @xTopShelfx I'm not sure the reason for using `JApplet`. If you decide to go the `JApplet` path it is crucial to understand what applets are. Please go through the tutorial. As for the conversion, it all depends on the complexity of existing application. Not all apps can be applets. See `What Applets Can and Cannot Do` section. In general, for presentation, your objective is to display the content of `JFrame` in the `JApplet`. Applet is a container. Add whatever you added to a frame to the applet instead. – tenorsax Dec 05 '13 at 22:32
  • 1
    +1 for [tag:java-web-start]; also consider a [hybrid](http://stackoverflow.com/a/12449949/230513). – trashgod Dec 06 '13 at 00:26
0

HolidayTester should extend JComponent as a reusable custom component and then it can be added to JFrame or JApplet as a child component like JLabel or JButton.

Your code extending JFrame or JApplet should not have any application-specific context, or it is not reusable.

Andrei Nicusan
  • 4,555
  • 1
  • 23
  • 36
chmin.seo
  • 271
  • 4
  • 10