Does OS X's Java support Swing?

TommyWillB

Registered
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:
Code:
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

Puny Member
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

Registered
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

Registered
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

Registered
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

Do not read this sign.
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
 
Top