[From Bill Powers (990925/0705 MDT)]
Richard Kennaway (990925.0031 BST)--
The first thing I did was fire up CodeWarrior and create a new Java
applet project. This creates a source code file for a trivial "hello
world" applet, which I then compiled and ran as a check my system was
working ok. Then I added in your code, and compiled and ran it. It
appeared to work as it should, although my screen isn't big enough to
show the clipping at 600. So I reduced the clip bounds to 400*300 and
it worked. Remember that the third and fourth arguments to setClip()
are the width and height, not the positions of the right and bottom
edges.
My immediate guess was that setBackground is a member function of
Applet, not of Graphics. ... As such, it should be called in the init()
method of the applet
I did that and it still works. thanks.
Notice also that your code in the paint() method does not actually erase
the window before drawing the circles. Assuming that's what you want to
do, the routine to call is g.clearRect( left, top, width, height ).
clearRect() fills a rectangle with the background colour.
I added the clearing statement at the end, to help see when the run was
finished.
The biggest problem was in the .HTML file, where part of the statement sets
the size of the window. I had forgotten that. I'm running 1280 x 768
resolution, so my 300 x 200 window was pretty small. Now everything works
as it should.
If you decide to
try to explain it to me ...
How am I doing?
Excellent. ly.
You can also write Math.random(), provided you import java.lang.*. This
is why random() doesn't work, no matter what you import:
Did that; it works. One of my problems was that I forgot I was doing an
applet and tried to run the program via "java" instead of an html screen,
which just returns a lot of errors. I see that you can't import
"java.lang.Math.*" and just use "random()". Oh, well.
In Java, *every* function is a member function of some object or class.
...
To call the random() function of the Math
class, you must write Math.random().
It's beginning to make sense.
I can't find out how to draw a single point on the screen. There doesn't
seem to be a method for doing this in the Graphics class. Lines,
rectangles, and ovals, yes. Points, no.
That is true. To draw a point at (x,y), call g.drawLine( x, y, x, y )
or g.drawRect( x, y, 1, 1 ).
Interesting. It can draw 25000 1-pixel lines per second, but only 12,500
1-pixel rectangles per second. It also draws 12,500 ovals per second with a
radius of 5 pixels.
But weren't you complaining that the designers threw in everything that
everyone might want? Well, here's one they missed. You want there
should be a g.drawPoint() as well?
Yeah.
... I haven't used Swing yet, but I have a book devoted to it. It is
two hundred pages longer than "Java 1.1: The complete reference", and it
only deals with Swing.
I can see that if I use Java, it's going to be in a limited way. Thanks
much for your help. You're a good explainer.
Best,
Bill P.