1 Reply Latest reply: Dec 4, 2012 2:38 AM by kaja.mohideen RSS

    Help with JButtons please

    977597
      Hi, I have a 2D array of JButton's in a gridLayout. This stores the buttons row/col and if it has an image:

      for(int i = 0; i < 7; i++) {
      for(int j = 0; j < 7; j++) {
      button[i][j] = new JButton(peg); //Populates grid with ImageIcons
      button[i][j].putClientProperty("column", i); //Stores all column properties
      button[i][j].putClientProperty("row", j); //Stores all row properties
      button[i][j].putClientProperty("ImageIcon" yes); //Sets each JButton to have an image

      button[i][j].addActionListener(new MyActionListener()); //Add actionListener
      add(button[i][j]); //Adds all buttons into gridLayout
      }
      }

      When I click one of my buttons the action listener is implemented and I can get all of the information about this button using the e.getSource() method:

      public class MyActionListener implements ActionListener {

      public void actionPerformed(ActionEvent e) {
      if(isFirstClick){

      JButton btn = (JButton) e.getSource(); //Get information on each button
      }
      }

      My question is, when I click on one button, how can I get the information from the button directly to its left without clicking on that button?

      I can get the button to the lefts row/col, but not the actually JButton's information like e.getSource()

      Thanks very much, I hope this makes sense