So basically, Netscape 4.61 is whacked for Java. On Redhat 6.0, Redhat 5.2, and Debian potato. Yay! What's frustrating is this stuff used to work. I was using Netscape 4.5 for the longest time with Java with no problems. So maybe it's a recent Netscape bug, rather than a Linux version problem. Is anyone running a Netscape that does work well for Java on Redhat 6.0? Here's the source code for my simple applet that's killing Netscape. It's just one example, I haven't found any Java to run reliably in Netscape recently. My apologies for the ugly code, it's some of the first Java I wrote. The paint/repaint interactions are a bit bizarre in DoubleBufferApplet, maybe that's the source of the problem.
// mas964 ps2
// draw circles on mouse click that demonstrate repetition
import java.applet.*;
import java.awt.*;
import java.lang.Math;
import DoubleBufferApplet;
public class CircleRepetition extends DoubleBufferApplet {
public boolean mouseDrag(Event e, int x, int y) {
return mouseDown(e, x, y);
}
public boolean mouseDown(Event e, int x, int y) {
Graphics g = imageBuffer.getGraphics();
this.clearImageBuffer();
g.setColor(this.getForeground());
int maxNumCircles = 30;
int circleSizeGradations = 10;
int numCircles;
int circleSize;
float cellSize;
// y coordinate controls the number of circles drawn
numCircles = maxNumCircles * y / imageBufferSize.height + 2;
if (imageBufferSize.width > imageBufferSize.height)
cellSize = imageBufferSize.width / numCircles;
else
cellSize = imageBufferSize.height / numCircles;
// x coordinate controls how big the circles are
circleSize = (int)(cellSize * x / imageBufferSize.width) + 1;
if (circleSize < 2)
circleSize = 2;
// System.out.println("numCircles " + numCircles + " circleSize " + circleSize);
// now draw circles in a hexagonal pattern (some slop on both sides
// to handle roundoff error)
int i, j;
for (i = -1; i < numCircles+4; i++) {
for (j = -1; j < numCircles+4; j++) {
if (i % 2 == 0)
g.fillOval(Math.round(i * cellSize), Math.round(j * cellSize),
circleSize, circleSize);
else
g.fillOval(Math.round(i * cellSize),
Math.round(j * cellSize + cellSize/2),
circleSize, circleSize);
}
}
repaint();
return true;
}
public void init() {
this.setBackground(Color.white);
this.setForeground(Color.black);
super.init();
}
}
// base class for double buffered applets. Drawing is done to imageBuffer,
// an offscreen buffer that's BLTed to the frame as need be. This gives
// you less flashies and some measure of image persistence across exposes.
// (it'd be nice if we could do this for arbitrary components, but that
// would require changing the root Component class)
// Draw model:
// When drawing, don't use this.getGraphics() or paint()'s argument-
// use imageBuffer.getGraphics()
// override paint() as expected to paint, but make sure to
// call super.paint() to actually render your changes
// call this.repaint() to actually cause the drawing to show up
// (or wait for something else to call this.update())
// use this.setBackground() as you would normally
// call clearImageBuffer() to reset the entire drawing to background color
import java.applet.*;
import java.awt.*;
public class DoubleBufferApplet extends Applet {
protected Image imageBuffer;
protected Dimension imageBufferSize;
// paint - just call update. Subclass can override this, be sure to call
// super.paint() as the last step.
public void paint(Graphics g) {
this.update(g);
}
// clear the image buffer to whatever the background colour is.
public void clearImageBuffer() {
Graphics ig = imageBuffer.getGraphics();
Color oldColor = ig.getColor();
ig.setColor(this.getBackground()); // clear the buffer
ig.fillRect(0, 0, imageBufferSize.width, imageBufferSize.height);
ig.setColor(oldColor);
}
// update - render the buffer onto the screen
// also handles lazy creation of the offscreen buffer
public void update (Graphics g) {
Dimension appletSize = this.size(); // read the current size
// check that the buffer is valid - if not, build one
if (imageBuffer == null ||
appletSize.width != imageBufferSize.width ||
appletSize.height != imageBufferSize.height) {
// System.out.println("Building a buffer of size " + appletSize);
imageBuffer = createImage(appletSize.width, appletSize.height);
imageBufferSize = appletSize;
this.clearImageBuffer();
}
g.drawImage(imageBuffer, 0, 0, this);
}
}
Title: Repetition Circles
Repetition CirclesYou control the vertical You control the horizontal |
