我目前面临的问题是我有一个带有大约6561个按钮的JFrame,我想根据点击的JButton只启用9个按钮。我通常能够做到这一点,但在重新创建JFrame的某个更改后,它会停止工作。我不知道为什么会这样。
if(abwincheck[m/r][h/r] == null) {
if(cdwincheck[m/3][h/3] == null) {
if(bcwincheck[m][h] == null) {
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) {
if(bcwincheck[i][j] == null) {
for(int k=0; k<9; k++) {
if(n == 2)
newDossier.Board.metaboard[i][j].getComponent(k).setEnabled(false);
}
}
if(n == 3) {
if(abwincheck[i][j] == null) {
for(int b=0; b<l; b++) {
for (int c=0; c<l; c++) {
if(bcwincheck[b][c] == null) {
for(int k=0; k<9; k++) {
for(int a=0; a<9; a++) {
Component []componentsx3 = newDossier.Board.metametaboard[i][j].getComponents();
if(componentsx3.length>1) {
Component []components = ((JPanel)newDossier.Board.metametaboard[i][j].getComponent(k)).getComponents();
if(components.length>1)
((JPanel)newDossier.Board.metametaboard[i][j].getComponent(k)).getComponent(a).setEnabled(false);
}
}
}
}
}
}
}
}
if(n == 4) {
if(abwincheck[i][j] == null) {
for (int b=0; b<9; b++) {
for(int c=0; c<9; c++) {
if(cdwincheck[b][c] == null) {
if(bcwincheck[i*9+b][j*9+c] == null) {
for(int k=0; k<9; k++) {
for(int a=0; a<9; a++) {
for(int p=0; p<9; p++) {
Component []componentsx3 = newDossier.Board.metametametaboard[i][j].getComponents();
if(componentsx3.length>1) {
Component []componentsx9 = ((JPanel)newDossier.Board.metametametaboard[i][j].getComponent(k)).getComponents();
if(componentsx9.length>1) {
Component []components = ((JPanel)((JPanel)newDossier.Board.metametametaboard[i][j].getComponent(k)).getComponent(a)).getComponents();
if(components.length>1) {
((JPanel)((JPanel)newDossier.Board.metametametaboard[i][j].getComponent(k)).getComponent(a)).getComponent(p).setEnabled(false);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
for(int i=0; i<l; i++) {
for(int j=0; j<l; j++) {
if(i == m && j == h) {
for(int k=0; k<9; k++) {
if(n == 2 && ((JButton)newDossier.Board.metaboard[i][j].getComponent(k)).getText().equals("")) {
newDossier.Board.metaboard[i][j].getComponent(k).setEnabled(true);
}
if(n == 3 && ((JButton)((JPanel)newDossier.Board.metametaboard[i/3][j/3].getComponent((m%3)*3+h%3)).getComponent(k)).getText().equals("")) {
((JPanel)newDossier.Board.metametaboard[i/3][j/3].getComponent((m%3)*3+h%3)).getComponent(k).setEnabled(true);
}
if(n == 4 && ((JButton)((JPanel)((JPanel)newDossier.Board.metametametaboard[i/9][j/9].getComponent(((m%9)/3)*3+(h%9)/3)).getComponent(((m%9)%3)*3+(h%9)%3)).getComponent(k)).getText().equals("")) {
((JPanel)((JPanel)newDossier.Board.metametametaboard[i/9][j/9].getComponent(((m%9)/3)*3+(h%9)/3)).getComponent(((m%9)%3)*3+(h%9)%3)).getComponent(k).setEnabled(true);
}
}
}
else {
if(n == 3||(n == 2 && bcwincheck[i][j] == null)) {
for(int k=0; k<9; k++) {
if(n == 2)
newDossier.Board.metaboard[i][j].getComponent(k).setEnabled(false);
if(n == 4||(n == 3 && bcwincheck[i][j] == null)) {
for(int a=0; a<9; a++) {
if(i<3 && j<3) {
Component [] componentsx3 = newDossier.Board.metametaboard[i][j].getComponents();
if(componentsx3.length>1) {
Component [] components = ((JPanel)newDossier.Board.metametaboard[i][j].getComponent(k)).getComponents();
if(components.length>1)
((JPanel)newDossier.Board.metametaboard[i][j].getComponent(k)).getComponent(a).setEnabled(false);
}
}
if(n == 4 && bcwincheck[i][j] == null) {
for(int p=0; p<9; p++) {
if(i<3 && j<3) {
Component [] componentsx3 = newDossier.Board.metametametaboard[i][j].getComponents();
if(componentsx3.length>1) {
Component [] componentsx9 = ((JPanel)newDossier.Board.metametametaboard[i][j].getComponent(k)).getComponents();
if(componentsx9.length>1) {
Component[] components = ((JPanel)((JPanel)newDossier.Board.metametametaboard[i][j].getComponent(k)).getComponent(a)).getComponents();
if(components.length>1)
((JPanel)((JPanel)newDossier.Board.metametaboard[i][j].getComponent(k)).getComponent(a)).getComponent(p).setEnabled(false);
}
}
}
}
}
}
}
}
}
}
}
}
有更多与所有更改相关的代码,但这是您需要查看的部分。
导致失败的更改是metametametaboard [0] [0]中的一个面板已删除所有按钮而只取消了JLabel。 JButtons在重新创建JFrame的任何其他时间都可以正确启用和禁用...但是通过此更改,无论出于何种原因它都会停止工作。请指教。