public PenApp() {
super("PenApp");
pack();
setVisible(true);
setVisible(false);
pack();
setResizable(false);
pack();
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
setLocation((d.width - CANVAS_SIZE) / 2, (d.height - CANVAS_SIZE) / 2);
setSize(CANVAS_SIZE + getInsets().left + getInsets().right,
CANVAS_SIZE + getInsets().top + getInsets().bottom);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
img = Toolkit.getDefaultToolkit().getImage
(getClass().getResource("penguin.gif"));
img2 = Toolkit.getDefaultToolkit().getImage
(getClass().getResource("kuwa.gif"));
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
x = getInsets().left;
y = getInsets().top;
setVisible(true);
}
像这样的一段代码。我只是想知道为什么在这里使用几个 pack() 和 setVisible() 。谢谢 :)