Step through the code as the computer would. First call the constructor:
public window(){
so far so good. continue...
setLayout(new FlowLayout());
JPanel p1 = new JPanel();
ok.... go on..........