tic tac toe을 실행하는 프로그램을 작성 중이며 button.setImage (image) 메서드를 사용하지 않고 버튼 위에 x 또는 o로 이미지를 표시하는 방법을 찾을 수 없습니다. 그렇게하면 이미지가 회색으로 변하며 원하지 않습니다. 버튼을 클릭 할 때 버튼이 비활성화되고 이미지가 위에 표시되도록하거나 버튼이 비활성화되었을 때 버튼을 회색으로 표시하지 않도록 할 수있는 방법이 있습니까?이미지를 회색으로 표시하지 않고 비활성화 된 버튼 위에 표시 하시겠습니까?
또한 GUI에서 SWT를 사용하고 있습니다.
public static void drawX(Button b, Shell s, Image x){ //draws an X image
int topLeft_X=b.getLocation().x;
int topLeft_Y=b.getLocation().y;
GC gc = new GC(b);
gc.drawImage(x, topLeft_X, topLeft_Y);
}
public static void drawO(Button b, Shell s, Image o){ //draws an O image
int topLeft_X=b.getLocation().x;
int topLeft_Y=b.getLocation().y;
GC gc = new GC(b);
gc.drawImage(o, topLeft_X, topLeft_Y);
}
static double turnCount = 1;
public static void button(final Button b, final Shell s, final int i, final int j, final Image g, final Image h){ //the method that would make the image appear
b.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
b.setEnabled(false);
turnCount++;
if(p1()){
a[i][j]++;
drawX(b, s, g);
b.setVisible(false);
}
else{
a[i][j]--;
drawX(b, s, h);
b.dispose();
}
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
이렇게하는 방법이 있을지 모르겠다.하지만 대안은 버튼을 제거/숨기고 버튼에 'JLabel'을 넣는 것이다. – twain249