(Apple Problem ID# 2841578)
On Macintosh OS X, clicking the buttons in the applet
below does not result in events being sent, and nothing appears in the system
Console. The same code generates events on other operating systems,
including OS 9.
It is not entirely clear whether this is a bug or just a less
tolerant implementation than in other platforms. Either of two changes in
the code fix the problem:
Books about Java suggest that validate is used for layout issues, not event issues. Therefore people will be surprised to have to call validate to activate events on a component that is laid out properly. If calling validate is needed on OS X and not on OS 9 or Windows, people will figure there is something wrong with Java on OS X even if this behavior is technically correct.
The code was written by Seth Carlson and condensed by Lee Ann Rucker. A listing of many Macintosh Java bugs with demonstration applets is at this link, including information on how to add any necessary Java plugins.
The source code is shown below and can be downloaded from: MuteButtons.java
// PintyChessBug Written by Seth Carlson
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class MuteButtons extends Applet {
static boolean sIllustrateTheBug = true;
// ************************************** CONSTANTS *******************************
private final int MAX_SMALL_WIDTH = 600; // Max width for the game
private final int MAX_SMALL_HEIGHT = 500; // Max height for the game
// ************************************** VARIABLES *******************************
public Frame myFrame;
public Button mac_NameButton = new Button("Set Player Name");
public Button mac_SetTimeControls = new Button("Set Time Controls");
// ********************************** BEGIN CODE *******************************
public String getAppletInfo() {return "PintyChessBug, by S. Carlson";}
public void init() { // Variable initialization, image loading, etc.
myFrame = new Frame("MuteButtons");
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent e) {
String temp;
boolean check;
String command = e.getActionCommand();
if (command.compareTo("Set Player Name") == 0) {
System.err.println("Set Player Name button pushed...");
} else if (command.compareTo("Set Time Controls") == 0) {
System.err.println("Set Time Controls button pushed...");
}
}
};
/* Set up action listeners and menus */
mac_NameButton.addActionListener(al);
mac_SetTimeControls.addActionListener(al);
myFrame.setResizable(false);
myFrame.setSize(MAX_SMALL_WIDTH, MAX_SMALL_HEIGHT);
myFrame.setLocation(300, 300);
myFrame.setLayout(null);
if (sIllustrateTheBug) myFrame.setVisible(true); // Showing before adding buttons breaks it
// Set up buttons
// .setBounds(x, y, width, height);
mac_NameButton.setBounds(15, 75, 160, 25);
myFrame.add(mac_NameButton);
mac_SetTimeControls.setBounds(15, 115, 160, 25);
myFrame.add(mac_SetTimeControls);
if (!sIllustrateTheBug) myFrame.setVisible(true); // It works if show is after the buttons are added
else myFrame.repaint();
}
}