I am trying to get a jbutton from a jframe. this is my code:
JButton button2 = (JButton) frame.getComponentAt(move);
I get this error when I do this: javax.swing.JFrame cannot be cast to javax.swing.JButton
These are the two class hierarchies http://docs.oracle.com/javase/7/docs/api/javax/swing/JButton.html http://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame.html
They are the same at container, and getComponentAt is on the level of component. How can I get the button from the jframe?
EDIT
I am able to get a button once it is pressed. The purpose of my code is to make a game in which a computer will respond to a user's move on the grid, a given click, with a response click (as if two humans were playing and the second person, the computer, clicked a button just like the first person). I have to find a way to access the button in the jframe through the code.