import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JFrame;
import java.io.*;public class test4 extends JFrame { /**
 * Launch the application
 * @param args
 */
public static void main(String args[]) {
try {
test3 frame = new test3();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
} /**
 * Create the frame
 */
public test4() {
super();
getContentPane().setLayout(new FlowLayout());
setBounds(100, 100, 500, 375);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
File file=new File("c:/");
File[] fi=file.listFiles();

//final JButton button = new JButton();
//button.setText("New JButton");

if(fi!=null){
for(int i=0;i<fi.length;i++){

//setBounds(100+i, 100+i, 500+i, 375+i);
JButton bu=new JButton();

bu.setText(fi[i].getName());
bu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
//File fil=new File("c:/"+fi[i].getName());
System.out.print("love");
}
});
getContentPane().add(bu, BorderLayout.NORTH);
//
}
}
}}
怎么样给每个随机生成的按钮添加监听事件那。