在Linux平台上,Frame :: getBounds和Frame :: setBounds不能一致地工作.这已在2003年(!)报道,见这里:
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4806603
为方便起见,我简化了导致错误的声明代码,并将其粘贴为:
import java.awt.Button;
import java.awt.Frame;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/** Demonstrates a bug in the java.awt.Frame.getBounds() method.
* @author Mirko Raner, PTSC
* @version 1.0 (2003-01-22) **/
public class GetBoundsBug extends Frame implements ActionListener {
public static void main(String[] arg) {
GetBoundsBug frame = new GetBoundsBug();
Button button = new Button("Click here!");
button.addActionListener(frame);
frame.add(button);
frame.setSize(300, 300);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent event) {
Rectangle bounds = getBounds();
bounds.y--;
setBounds(bounds);
bounds.y++;
setBounds(bounds); …Run Code Online (Sandbox Code Playgroud)