Mam taki kod:
private JButton nowaGra;
private JButton[] b = new JButton[9];
private JPanel plansza()
{
JPanel mp = new JPanel();
for(int i=1;i<10;i++)
{
b[i] = new JButton();
b[i].addActionListener(this);
b[i].setPreferredSize(new Dimension(20,20));
}
mp.setLayout(new GridLayout(3,3));
mp.setPreferredSize(new Dimension(300,300));
mp.add(b[1]); mp.add(b[2]); mp.add(b[3]);
mp.add(b[4]); mp.add(b[5]); mp.add(b[6]);
mp.add(b[7]); mp.add(b[8]); mp.add(b[9]);
nowaGra = new JButton("Nowa gra");
nowaGra.setPreferredSize(new Dimension(150, 50));
mp.add(nowaGra);
return mp;
}
i
public gra()
{
super();
this.getContentPane().add(this.plansza());
}
i wywołanie **this.getContentPane().add(this.plansza()); ** powoduje następujące błędy:
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
zakomentowanie pętli for i ustawienia buttonów rozwiązuje problem. O co chodzi?