Frame 안에 Panel이랑 Button이 있구요
Button을 한 번 누를 때마다 Label을 하나씩 생성해서 Panel에 add시키는데요
Frame의 repaint() 를 호출했는데 화면이 바뀌지 않아요 ㅜㅜ
그런데 창을 최소화 시킨담에 다시 화면 크게 만드니까 그제서야 변경된 화면이 나와요 ㅜㅜ
제가 뭔가 잘못알고있는건가요?
import java.awt.*;
import java.awt.event.*;
public class Test2 {
Frame f;
Button b;
Panel p;
Test2(String title) {
f = new Frame(title);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
p = new Panel();
b = new Button("click");
b.addActionListener(new ButtonHandler());
f.add(p, "Center");
f.add(b, "South");
f.setBounds(100,50,500,500);
f.setVisible(true);
}
public static void main(String[] args) {
new Test2("repaint test");
}
class ButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent ae) {
Label label = new Label("hello");
p.add(label);
f.repaint();
}
}
}