如何从ArrayList中捕获每个按钮的ActionEvents?

时间:2017-02-11 17:31:30

标签: java jframe jbutton actionlistener actionevent

我的问题是,我不知道如何抓住ActionPerformed(ActionEvent e)中的每个按钮ArrayList

输出是课程表的图表

private static List<JButton> buttons = new ArrayList<>();
public static String[] doctobuttontxt = new String[20];
public static void buttons(Panel cp){
    int ctr = 0; //counter
    int ycod = 48;
    int xcod = 88;
    for (int y = 0; y < 5; y++) {
        xcod = 88;
        for (int x = 0; x < 4; x++) {
            JButton button = new JButton();
            button.setBounds(xcod, ycod, 75, 25);
            button.setText(doctobuttontxt[ctr]);
            button.setMargin(new Insets(2, 2, 2, 2));
            button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    actionPerformed(e);
                }
            });
            buttons.add(button);
            cp.add(button);
            ctr++;
            xcod = xcod + 88;

        }
        ycod = ycod + 48;
    }

我不能使用JTable

0 个答案:

没有答案