I am working with the NetBeans IDE in Java.
I have a form with one JPanel. Each JPanel has a gridLayout 3x3, and in every place there is an image representing the number [0,1,2,3,4,5,6,7,8] (the created image uses a custom class, not just the image setup in the lab).
I want to be able to share two images on the panel when the user clicks on them (first click: no action, second click: switch two images installed in jPanel components).
I have already created the exchangeComponents function with test code (for example:
exchangeComponents (0,8,jPanel1)
it correctly arranges the images located at position 1 (1st row, 1st column) and at position 2 (3rd row, 3rd column).
The creted function is as follows:
public void exchangeComponents(int component1,int component2,JPanel jpanel){
try{
Component aux1 = jpanel.getComponent(component1);
Point aux1Loc = aux1.getLocation();
Component aux2 = jpanel.getComponent(component2);
Point aux2Loc = aux2.getLocation();
aux1.setLocation(aux2Loc);
aux2.setLocation(aux1Loc);
}
catch (java.lang.ArrayIndexOutOfBoundsException ex){
System.exit(1);
}
}
, , exchangeComponents(), jPanel1, ? , () ?
, , ( IDE), ,
private void button1ActionPerformed(java.awt.event.ActionEvent evt) {
}
.
.