Overriding paint() for a Component (Button) that already knows how to
paint itself via a ComponentPeer gives different results in Solaris
versus Win95. The code below attempts to paint a red line on top of a
native button. The red line appears initially and on window exposes
in Solaris, but never shows up in Win95.
================ PaintExample.html ================
<html>
<head>
<title>PaintExample</title>
</head>
<body>
The PaintExample applet:
<applet code="PaintExample.class" width=200 height=200>
</applet>
</body>
</html>
================ PaintExample.java ================
import java.awt.*;
/**
* PaintExample -- defining/overriding paint() in Component subclasses
*/
public class PaintExample extends java.applet.Applet {
public void init() {
MyPaintButton b = new MyPaintButton("a button");
add(b);
}
}
/**
* A Button subclass that draws a red line across the normal Button image.
*/
class MyPaintButton extends Button {
public MyPaintButton(String s) {
super(s);
}
public void paint(Graphics g) {
super.paint(g); /* draw as a regular Button first */
g.setColor(Color.red);
g.drawLine(6, size().height / 2, size().width - 6, size().height / 2);
}
}
================================