that is a
GridLayout
. That would mean that you have to make the position of the "arrow" dynamic (given as arguments when the
JPanel
is created) and you would have to draw the
JPanel
newly (
JPanel.doLayout()
).
So you need to redesign your approach:
- Between
GridLayout
and
JFrame
needs to be a
JPanel
that can be redrawn. So add a
JPanel
to your
JFrame
and put the rest into the
JPanel
.
- make this
JPanel
an own
Object
:
public class GridPanel extends JPanel(){
public GridPanel(int iRow, int iCol){
super();
this.ignition(iRow, iCol);
}
it's easier to work with it then because you can renew the
JPanel
simply with a little function:
public void setGridPanel(int iRow, int iCol) {
remove(oGridPanel);
repaint();
oGridPanel = new GridPanel(iRow, iCol);
getContentPane().add(oGridPanel);
oGridPanel.doLayout();
}
EDIT:
You should give your Buttons a ActionCommand while creating them. I can recommend to use a
Enum
for that, that's one of the smartest way to create a fixed set of commands that one can refer to.
See Nagy's Article for more about how to use enums:
The Secret Classes or How I Stopped Counting and Loved the Enumerator[
^]