Just another WordPress.com site

PENKOM, TicTacToe coding

public TicTacToe() {
//Setting game properties and layout and sytle…
//Setting window properties:

window.setSize(X, Y);
window.setLocation(450, 260);
window.setResizable(false);
window.setLayout(new BorderLayout());
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Syntax di atasbergunauntukmengaturlayartampilan.Layardiaturpadaukuran 450×260 dantidakdapatdimaximize.

//Setting Panel layouts and properties
pnlNewGame.setLayout(new GridLayout(2, 1, 2, 10));
pnlNorth.setLayout(new FlowLayout(FlowLayout.CENTER));
pnlSouth.setLayout(new FlowLayout(FlowLayout.CENTER));

pnlNorth.setBackground(new Color(color-20, color-20, color-20));
pnlSouth.setBackground(new Color(color, color, color));

pnlTop.setBackground(new Color(color, color, color));
pnlBottom.setBackground(new Color(color, color, color));

pnlTop.setLayout(new FlowLayout(FlowLayout.CENTER));
pnlBottom.setLayout(new FlowLayout(FlowLayout.CENTER));
pnlNewGame.setBackground(Color.blue);

Syntax di atasbergunauntukmengaturwarnapadabagianlataryaknibagianatas, bawah, kanandankiridanmengatur agar layarmunculpadabgiantengah.

//Adding menu items to menu bar
mnuMain.add(mnuNewGame);
mnuMain.add(mnuInstruction);
mnuMain.add(mnuAbout);
mnuMain.add(mnuExit);//—->Menu Bar Complete
//Adding buttons to NewGame panel
pnlNewGame.add(btn1v1);
pnlNewGame.add(btn1vCPU);

Syntax di atasberfungsuuntukmenampilkan menu bar padabagianatastampilan game. Menu bar tersebutberisi 4 sub menu yaitu menu New Game, Instruction, About, dan Exit. Saat sub menu New Game diklikmakanakanmuncul sub menu baru. Menu barutarsebutadalah btn1v1 artinyasaatbermainakanmelawan player lain sedangkan btn1artinyasaatbermainakanmelawan CPU.

//Adding Action Listener to all the Buttons and Menu Items
mnuNewGame.addActionListener(this);
mnuExit.addActionListener(this);
mnuInstruction.addActionListener(this);
mnuAbout.addActionListener(this);
btn1v1.addActionListener(this);
btn1vCPU.addActionListener(this);
btnBack.addActionListener(this);

Syntax di atasberfungsiuntukmengatur agar ketikapilihan sub menu di klikdapatmenghubungkankekelas yangdituju.

//Setting up the playing field
pnlPlayingField.setLayout(new GridLayout(3, 3, 2, 2));
pnlPlayingField.setBackground(Color.black);
for(int i=1; i<=9; i++) {
btnEmpty[i] = new JButton();
btnEmpty[i].setBackground(new Color(220, 220, 220));
btnEmpty[i].addActionListener(this);
pnlPlayingField.add(btnEmpty[i]);

Syntax di atasberfungsiuntukmengaturtampilanpadatampilan game.Tampilantersebutsepertimengaturukurantampilanuntuksetiap player jika yang bermainadalebihdarisatu player.Selainitudapatjugadiaturtampilanwarnapadabagianlatarnya.Padabagianinidibuatsatutombol yang diberiwarnatertentudimanajikatombolinidiklikmakaakanmenghubungkanke Playing Field.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

Awan Tag

%d blogger menyukai ini: