Mac Java Journal

Week Two


2/20/96 Discovered that the Applet Viewer's File Open Local is blind to HTML files that use CAPs in their title. Couldn't see SLA.HTML, but could see sla.html. Found a new way to crash the Mac. Move the Applet Viewer into another file and drop a class file on it. Unimplemented Trap. (Sounds like one that Elmer Fudd or Wiley Coyote would end up with. "BeepBeep you wascally wabbit!")

I've decided to approach Mac Java in my traditional way. I'll learn "about" the language by adapting existing programs to my own uses, while I work through various documentation sources (tutorials, books and the API) and also tapping into the comp.lang.java newsgroup by lurking and asking questions.

Gamelan has a site that has a navigation routine written in Java that shows up on the Applet Viewer when you do File Open URL (in fact it is the default address in my copy.) I haven't actually been able to navigate with it yet, but perhaps I'm just too impatient. I'll try it again later when I have War and Peace here at the desk so I can fill the delay time. Or maybe I'll get some chips and Frito deLay. Sorry.:-)

Added a simple animation routine to my Tom Robbins page to make Salome dance the "dance of ultimate cognition" on the cover of Skinny Legs and All.

2/21/96 Created a Mac+Java animation and added it to this page. I'm writing out a step-by-step for that and the Salome dance animation and will post it soon. (As Steve Martin might have said, "It's so easy when you don't know the language.")

I discovered that you can't use an URL that is wider than the entry box on the Applet Viewer. So that excludes any address over 49 characters long.

How I persuaded Salome to do her dance of the seven veils of illusion on a Web page in front of God and everybody:
1. I had a gif of the cover of Tom Robbins' novel Skinny Legs and All already.
2. I loaded it into Adobe Photoshop 3.0. I used the Zoom tool and expanded the picture until I could almost see the pixels. I used the lasso tool and outlined an area around Salome's torso. I used the Skew command and rotated that part of the image about 45%. Then I used the stamp tool to fill in the now white areas that had been uncovered with the color of the rest of the back ground. I shrunk the image down to .65 x.9 inches. Made it into an Indexed Color pict. and saved it under the name of T2.gif. Then I reloaded the original, shrunk it down to the same size and saved it as T1.gif.
3. I used the sample applet called Animator. I copied the .class file, the .example2.html file and the image folder to a new folder. There I replaced the T1 & T2 gifs that were there with my new ones.

I edited the html file from:
<applet code=Animator.class width=200 height=200>
<param name=imagesource value="images/SimpleAnimation">t
<param name=endimage value=2>
<param name=soundsource value="audio">
<param name=soundtrack value=spacemusic.au>
<param name=sounds value="1.au|2.au|3.au|4.au|5.au|6.au|7.au|8.au|9.au|0.au">
<param name=pause value=200>
</applet>
to
<applet code=Animator.class width=200 height=200>
<param name=endimage value=2>
<param name=pause value=200>
</applet>

And inserted that code into my Web page at the appropriate place.

Then I uploaded the following files to my server: tom_robbins.html, Animator.class, T1.gif, and T2.gif. (I immediately regreted not recompiling the Animator.class to use different gif names and vowed to "never do that again". Well next time I'll do it right.)

What I learned from this was that if you eliminate the line <param name=imagesource value="images/SimpleAnimation"> from the html, then it defaults to the current directory. (Note to myself: finally make that images subdirectory on your server that you've been meaning to create.) Here's the applet if you have a Java enabled one:

You don't have a Java-enabled browser. Maybe you own a Macintosh like me!

If you got a blinking message then you see that any html stuff within the <applet> </applet> tags shows up if the applet doesn't get activated. So you can have alternative messages or even images (I think) show up if you put your applets where the Sun don't shine.

2/22/96 The only reason that the two simple applications worked with the applet viewer was because they had simple calls to the system. The basic fact is that this version of the JDK only works for applets. And the only way to view an applet is through an html document. Applets usually start by importing the classes they need from the libraries. So, for example, if I go back to my rectangle attempts I would first find out where the rectangle capability is. I would open the API User's Guide.html with my browser. Click on the index. Search for "rectangle" and find that it is part of the library Graphics. So I would start the applet with:
import java.awt.Graphics.
This will give my applet the ability to draw rectangles.

2/23/96 I just thought of an excellent use for applets. To insult Windows 95 users! Since they are the most likely to be able to view applets, we simply put in html code for Mac & Win 3.1x browser that says something like, "Welcome user of Windows 95. Your wisdom in buying into that system is appreciated here." But in the applet we have the little Duke character making obscene gestures and saying, "Win 95 is Mac 86, suckers!" Of course, that won't work in another week or two, because even Macs will be able to browse applets in the wild. And besides we don't really feel any resentment like that do we now?

BTW, my interview with Sun Java's Webmaster, Hassan Schroeder is on the newstands. The magazine is Web Developer and my column is The Dukes of URL.

2/24/96 On the comp.lang.java newsgroup Kevin Raulerson of Metrowerks says that the MacJDK is much easier to use than that of Windows 95.

So back to drawing a rectangle. Using a simplified version of a script that Campione-Walrath provide in their tutorial, I get the following bare-bones script to draw a rectangle.

import java.awt.Graphics;

public class Dalerect extends java.applet.Applet {
     public void paint(Graphics g) {
                            g.drawRect(5, 5, 20, 20);
                       }
    }

I save that as Dalerect.java and drag that file to the compiler. It creates the Dalerect.class. I create the html code: (Dalerect is Dale + rect, don't split the name after Dal)
<applet code=Dalerect.class width=200 height=200>
</applet>
and save it as Dalerect.html. When I drop that on the AppletViewer I get the following impressive output. Da Vinci eat your heart out.

I've found that the Java Compiler needs about 1400k to compile a 4-5 line applet. Longer applets take twice that and more. So if you drop a .java file onto the compiler and the memory shows up at less than 1400 you're gonna get kicked out for lack of memory.

2/25/96 I finally read the known bugs document. Here are the most interesting ones to me.
1. AppletViewer does not recognize <APPLET> tag, only the lower case <applet> tag.
2. Cannot select or copy stderr/stdout or from compiler output windows. Which means when you can't click and drag over text when errors are displayed and then do Command C to copy it. Very frustrating.
3. Audio clips will not play. (The Sounds of Silence.)
4. One I discovered was that you can't paste an URL into the File Open URL input box in the Applet Viewer.

Peter Howell pointed out to me that you can save the error by pressing Command-S. I eagerly went to test it and sure enough, despite the fact that the File Save command is greyed out and unavailable, pressing Command-S allows you to save either the stderr or stdout content (depending on which window is active.) Another little quirk is that if you try to open the resultant files while you are still in the applet, you get a "file in use by another" error (how DOS-like!) But as soon as the applet is not active you can open the text files and edit them. Thanks very much, Peter.

2/26/96 I've been reading through one lesson per day from Campione/Walrath's tutorial and I feel I'm absorbing the Java paradigm. Interestingly, I think the book will be even more effective than the hypertext version. Actually I think a combination of the two will be best. I like the interactivity (and no typing requirements) of the hypertext version, but I like the convenience of a book. I hope it will include any Mac-specific info that emerges after Netscape's Mac upgrade empowers the Mac community to see Java.

I just learned from Matt McRae's Web site, Apple Flavored Java that a Java-enabled version of Netscape has been released. He says it's for the PowerMac only. So 68k owners are still stuck with the AppletViewer. I'm downloading the 2300k file now, but I will still write this journal in terms of both 68k and PowerPC machines.

Guy Kawasaki, whom I will call The Hit Man (the counter was at 314 on Monday morning check it out now), mentioned this page in his Macway mailing list. Hundreds of Evangelista dropped by. Welcome! And they came bearing suggestions. Which I also welcome. John Bryan sic'd his Cyberdog on the trail and came up with the Web site for downloading MacJava 2.0b1. Matt McRae's site also has ftp addresses for the new browser. Brad Andrews reported that the new browser "blew up on animations, but worked on the arc example."

Pssst. I'm having a little trouble with Speech Plug-in at the moment. Probably something I did wrong. It's a neat addin.

Back to MacJava