# Does OS X's Java support Swing?



## TommyWillB (Apr 8, 2001)

I'm working my way through a Java book that says only Java 2 is required... I'm not very far in and I'm already stumbling on this:

	import java.awt.*; 
	public class RootApplet extends javax.swing.JApplet 

I've compiled without any problems, but when I try to run the HTML file with the applet tag in either the IE 5.1 Preview or the Apple supplied Applet Viewer I get nothing.

It makes no difference if I use my verion or the one from the CD, so I know I'm not making a typo.

Doesn't OS X's Java 2 support swing? If not, how do I get it to?

Heres the full code of RootApplet.java:
	
	



```
import java.awt.*;
 
public class RootApplet extends javax.swing.JApplet 
{
    int number;
 
    public void init() 
    {
        number = 225;
    }
 
    public void paint(Graphics screen) 
    {
       Graphics2D screen2D = (Graphics2D) screen;
       screen2D.drawString("The square root of " + number + " is " +  Math.sqrt(number), 5, 50);
    }
}
```


----------



## strobe (Apr 9, 2001)

Swing works and so does Java2D. Perhaps your problem is you haven't setup a place to draw stuff.

(BTW if you use Swing, never ever use the mac L&F plugin)


----------



## TimMcG (Apr 9, 2001)

The IE 5.1 preview release does not have Java enabled by default. You need to change the preferences in IE to enable Java.


----------



## TommyWillB (Apr 11, 2001)

> _Originally posted by strobe _
> *Swing works and so does Java2D. Perhaps your problem is you haven't setup a place to draw stuff.*


I have IE enabled... as is the Applet Viewer.

What do I have to do to give Java "a place to draw stuff"?


----------



## spike666 (Apr 12, 2001)

your code runs fine on my osx.

i even changed it from running the JApplet to running Applet w/o any problems.
 (change it from extending javax.swing.JApplet to extending java.applet.Applet) -- both ran fine on my box.
also, you might want to check the html that is calling the applet.  aka the apple tag... here's mine:

<applet code="RootApplet.class" width=200 height=200> 
</applet>

and then to run it, from the terminal window typed in appletviewer RootApplet.html  and up it popped.


----------



## rharder (Apr 12, 2001)

I tried your code on my Windows machine at work. 

When I run appletviewer with an appropriate applet tag, nothing happens. That is, I get my command prompt back with no errors and no appletviewer.

That's weird.

When I run it in Internet Explorer (which I don't expect to work because it uses JDK1.1) I get a RootApplet not found error.

-Rob


----------

