7

I have a problem.

How i can run my java-applet directly without embedded in my web page?

I know appletViewr can execute applet without a browser but I need to get java applet without html page.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
PleaseHelpMe
  • 81
  • 1
  • 1
  • 2

8 Answers8

7

Use below code with your code, where AppletClass is your Applet class.

AppletClass appletClass = new AppletClass ();

JFrame frame = new JFrame();
frame.setLayout(new GridLayout(1, 1));
frame.add(appletClass );

// Set frame size and other properties
...

// Call applet methods
appletClass .init();
appletClass .start();

frame.setVisible(true);

More customizations can be done as required.

spgodara
  • 984
  • 9
  • 10
5

Appletviewer is the way to go, BUT, it still requires a webpage with an applet-tag.

An alternative solution is to write a stub class, with a main method, that instantiates the applet, calls init(), start(), stop() and destroy() as would otherwise have been done by the browser or appletviewer.

aioobe
  • 413,195
  • 112
  • 811
  • 826
1

Use /*<applet code="java file name " height=150 width=150></applet>*/ before declaring applet class and then compile java program and run applet by using appletviewer it execute perfectly don't require any html file

Pratik M.
  • 11
  • 2
1

Run appletviewer [ options ] urls ...

Documentation

rjdkolb
  • 10,377
  • 11
  • 69
  • 89
stacker
  • 68,052
  • 28
  • 140
  • 210
1

Build a subclass, which implements main-method, and call init(), start(), stop(), destroy as needed.

springfeld
  • 89
  • 8
1

If you use eclipse: Right-Click on your main java file (the one which extends Applet), select the 'Run As' submenu, and select 'Applet.

Justin
  • 4,437
  • 6
  • 32
  • 52
0

This browser extension works quite well. Supports Chrome and Edge.

https://leaningtech.com/cheerpj-applet-runner/

tesla
  • 1,219
  • 1
  • 10
  • 18
-1
<applet code=classname height=200 width=200>

</applet>

Simply write this code in your java program and first run using:

javac classname.java

after

run:appletviewer classname.java
Raul Luna
  • 1,945
  • 1
  • 17
  • 26