이제 나는 내가 여기서 매우 혼란스러워했는지 확실하지 않습니다. 온라인에서 검색을 많이했는데 도움이되지 않는 것 같아서 여기서 물어볼 거라고 생각했습니다. 나는 본질적으로 배열 game []의 값에서 컬러 그리드를 만들려고합니다.
public class first
{
public static void Newgame(){
//variables etc
game = new int[100];
for(int i=0; i<100; i++)
{
game[i] = 0;
if(i==89){
game[i] = 2;
}
}
grid table1 = new grid(game[i]); // I'm trying to call the method in the other class and create the jframe grid using the values from the array game[]
}
다른 클래스는 다음과 같습니다.
public class grid extends JFrame {
void game(int[] value) {
setSize(400, 400);
int size = 10;
JPanel content = new JPanel(new GridLayout(size,size));
for (int i = 0; i < size*size; ++i) {
JPanel panel = new JPanel();
if(value[i]==0){
panel.setBackground(Color.BLACK);
}
if(value[i]==1){
panel.setBackground(Color.RED);
}
if(value[i]==2){
panel.setBackground(Color.GREEN);
}
content.add(panel);
}
add(content);
setVisible(true);
}
}
감사합니다. 인내심을 가지고 배우려고 노력하고 있습니다 :)
그리드 클래스에 개체 만들기
grid table1 = new grid();
배열을 전달하여 해당 객체에 대한 게임 메서드를 호출합니다.
table1.game(game);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다