Here are a few ways to bring but1 and but2 into scope: 1. Declare them as instance variables of the SimpleGUI class. 2. Pass them into the constructor of MyActionListener: class MyActionListener implements ActionListener { private JButton but1, but2; public MyActionListener(JButton b1, JButton b2) { but1 = b1; but2 = b2; } // rest of class } 3. Use anonymous inner classes: but1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // use but1 } });