JButton button = new JButton("Lights On"); button.setBorder(BorderFactory.createEmptyBorder(0,10,10,10)); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (X.lightIs(1)) { X.lightOff(); //button.setText("Lights On"); } else { X.lightOn(); //button.setText("Lights OFF"); } } });