|
import java.applet.Applet; import java.awt.*;
public class NestForOut extends Applet {
int board[][]; int row,col;
public void init() { board = new int[3][5]; board[1][0]=9; for (int x=0; x<3; x++) for (int y=1; y<4; y++) { if (x == y) board[x][y] = x+y; if (x<y) board[x][y] = y-x; else (board[x][y] = x-y+2); }
}
public void paint(Graphics g) { for (int r=0; r<3; r++) { for (int c=0; c<5; c++) { g.drawString(String.valueOf(board[r][c]),c*20,r*20+20); } } } }
import java.applet.Applet; import java.awt.*;
public class TTT extends Applet {
int board[][]; int row,col;
public void init() { board = new int[3][3]; board[0][0]=1;
}
public void paint(Graphics g) { for (int r=0; r<3; r++) { for (int c=0; c<3; c++) { if (board[r][c]==0) g.drawString("_",c*20,r*20+20); else if (board[r][c]==1) g.drawString("X",c*20,r*20+20); else g.drawString("O",c*20,r*20+20); } } } }
import java.applet.Applet; import java.awt.*;
public class TTT2 extends Applet {
int board[][]; int row,col; Label rowLab,colLab; Choice rowInp,colInp; Button move;
public void init() { board = new int[3][3]; board[0][0]=1; rowLab = new Label("Row?"); add(rowLab); rowInp = new Choice(); rowInp.addItem("1"); rowInp.addItem("2"); rowInp.addItem("3"); add(rowInp); colLab = new Label("Column?"); add(colLab); colInp = new Choice(); colInp.addItem("1"); colInp.addItem("2"); colInp.addItem("3"); add(colInp); move = new Button("Make the Move"); add(move);
}
public void paint(Graphics g) { for (int r=0; r<3; r++) { for (int c=0; c<3; c++) { if (board[r][c]==0) g.drawString("_",c*20+50,r*20+110); else if (board[r][c]==1) g.drawString("X",c*20+50,r*20+110); else g.drawString("O",c*20+50,r*20+110); } } }
public boolean action(Event e, Object o) { if (e.target == move) { board[rowInp.getSelectedIndex()][colInp.getSelectedIndex()] = -1; repaint(); } return true; }
}
|