日期:2014-05-20  浏览次数:20742 次

swing中的问题,高手帮忙解决下?
为什么我在JFARAM中加了下面这JPanel,JRAME的KEY监听就无效了?
class Ground extends JPanel{ 
public Ground(){ 
this.intial();
}

public void intial(){ 
this.setLayout(new GridLayout(7,7));
this.setBounds(0,0,400,400);
bricks=this.getBrick();
this.setBrick();
//((JButton)bricks.get(0)).setIcon(new ImageIcon(buttonImg));
}

public void setBrick(){ 
for(int i=0;i<49;i++){
((JButton)bricks.get(i)).setOpaque(false);
((JButton)bricks.get(i)).setContentAreaFilled(false);
this.add((JButton)bricks.get(i));
}


public List getBrick(){ 
List bricks=new ArrayList();
for(int i=0;i<49;i++){ 
bricks.add(new JButton());
}
return bricks;
}

public void paintComponent(Graphics g) { 
g.drawImage(gameImg,0,0,this);
}
}

------解决方案--------------------
因为JFrame不是当前焦点所在的组件