Why this code never prints "Hello2" ?
public class Test4 {
public static void main(String[] args) {
JFrame f = new JFrame();
JPanel p = new JPanel();
f.getContentPane().add(p);
JLabel x = new JLabel("Hello");
p.add(x);
p.addComponentListener(new ComponentListener() {
public void componentResized(ComponentEvent arg0) {
System.err.println("Hello1");
}
public void componentMoved(ComponentEvent arg0) {
}
public void componentShown(ComponentEvent arg0) {
System.err.println("Hello2");
}
public void componentHidden(ComponentEvent arg0) {
}
});
f.setVisible(true);
f.pack();
}
}