爱玺玺

爱玺玺的生活日记本。wx:lb87626

java swing 通过监听事件添加组件

class AddSjd implements ActionListener{

JPanel jPanel=null;

ArrayList<GridPanel> arrayList = null;

public AddSjd(JPanel jPanel,ArrayList<GridPanel> arrayList) {

this.jPanel=jPanel;

this.arrayList=arrayList;

}

@Override

public void actionPerformed(ActionEvent e) {

this.jPanel.setBackground(Color.RED);

for(GridPanel gridPanel:arrayList){

this.jPanel.remove(gridPanel);

}

this.arrayList.add(new GridPanel("08-10"));

for(GridPanel gridPanel:arrayList){

System.out.println(arrayList.size());

this.jPanel.add(gridPanel);

}

this.jPanel.revalidate();

this.jPanel.repaint();

}

}


发表评论:

Powered By Z-BlogPHP 1.4 Deeplue Build 150101

Copyright Your WebSite.Some Rights Reserved.

蜀ICP备11021721号-5