How to get specific ID for a JButton?

前端 未结 2 407
攒了一身酷
攒了一身酷 2021-01-27 07:10

I\'m trying to build a program that utilizes a 3x3 grid of buttons (using Java Swing), so I initialize it with a GridLayout and a loop to create the buttons:

            


        
2条回答
  •  青春惊慌失措
    2021-01-27 07:54

    you already keep a track of the buttons by the array index i.e. buttray[i]. Use getSource()

       public void actionPerformed(ActionEvent e) 
    {
        // TODO Auto-generated method stub
        for(int i=0;i

提交回复
热议问题