Tampilkan postingan dengan label Java. Tampilkan semua postingan
Tampilkan postingan dengan label Java. Tampilkan semua postingan

Minggu, 06 Januari 2013

Sebenarnya saya lagi bingung mau posting apa, jadi daripada lama tidak update, saya posting saja contoh-contoh kecil yang siapa tau dibalik pendugaan ketidak gunaannya ini, rupanya inilah yang paling banyak dicari orang-orang, namun tidak ada yang posting sebelumnya. ohohoh.. memang beginilah lah terbawa khayalan harapan. 

berikut ini contoh sederhana penggunaan method equals yang iseng iseng saya buat ketika belajar soal UAS.

import java.util.*;
class CobaEquals
{
public static void main(String args [])
{
String jurusan;
Scanner in = new Scanner(System.in);

System.out.print("kamu Mahasiswa Jurusan Apa? ");
jurusan =in.nextLine();

System.out.println(jurusan);

if(jurusan.equals("Informatika") || jurusan.equals("informatika"))
{
System.out.println("nnSelamat datang masbro");
}
else
{
System.out.println("nnMaaf, ini hanya untuk Jurusan Informatika, silahkan ikut SNMPTN Ulang :p");
}
}
}

Ntar kalau dijalanakan penampakannya akan seperti ini:
http://go-program.blogspot.com/2013/01/contoh-penggunaan-method-equals-di-java.html
Begitulah kira kira contoh sederhananya, masih banyak contoh untuk penggunaan lainnya, silahkan berkreasi sendiri yaa 

Jumat, 04 Januari 2013

http://go-program.blogspot.com/2013/01/source-code-tugas-java-applet-2-game.html
Sesuai janji, kali ini saya akan posting source code yang saya kumpulkan sebagai tugas 2 mata kuliah PBO (Pemrograman Beriorentasi Objek)(Kami menggunakan Java). Tugas 2 yang diberikan yaitu membuat sebuah game Applet tictactoe tanpa AI(Artificial Inteligent) dan tanpa aturan menang, sehingga hanya untuk diklik-klik saja. Namun bagi mereka yang membuat sistem aturan menang yang apabila posisinya berjajar 5 kali secara berturut-turut maka akan menang. Sebelumnya saya sudah posting source code yang dimiliki dosen. (baca: Source Code Java Applet 1 Game TicTacToe). 

Mungkin tugas ini tidak terlalu sulit, karena selain sudah berhasil mendapatkan source code punya robot si dosen, saya juga berhasil mendapatkan berbagai contoh java applet tictactoe dari hasil googling, ada lumayan banyak sampai belasan gitu. Jadi saya hanya tinggal memilih dan sedikit melakukan modifikasi. adapun hasil akhir yang saya kumpulkan yaitu:

/*--------------------------------------------------------*/
/*-----Author : Ahmad Ariful Amri-----------------------*/
/*-----Program : Applet Tictactoe------------------------*/
/*------------http://go-program.blogspot.com--------------*/
/*--------------------------------------------------------*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.LineBorder;

public class TicTacToe extends JApplet
{
private char whoseTurn = 'X';
private Cell[][] cells = new Cell[10][10];
private JLabel jlblStatus = new JLabel("Giliran Pemain X");

public TicTacToe()
{
GridLayout grid = new GridLayout(10, 10, 0, 0);
JPanel p = new JPanel(grid);
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
p.add(cells[i][j] = new Cell());

p.setBorder(new LineBorder(Color.black, 1));
jlblStatus.setBorder(new LineBorder(Color.gray, 1));

add(p, BorderLayout.CENTER);
add(jlblStatus, BorderLayout.SOUTH);
}

public boolean isFull()
{
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
if (cells[i][j].getToken() == ' ')
return false;

return true;
}

public boolean isWon(char token) //Penentuan aturan menang
{ /*-----------------------------------------------------------------------------------------------------Kondisi Menang Horizontal--------------------------------------------------------------------------------------------------------------------------*/
for (int i = 0; i < 10; i++)
{
if ((cells[i][0].getToken() == token) && (cells[i][1].getToken() == token) && (cells[i][2].getToken() == token) && (cells[i][3].getToken() == token) && (cells[i][4].getToken() == token)) { return true;} /*Horizontal dari baris 1 sampai baris 5*/
else if((cells[i][1].getToken() == token) && (cells[i][2].getToken() == token) && (cells[i][3].getToken() == token) && (cells[i][4].getToken() == token) && (cells[i][5].getToken() == token)){return true;} /*Horizontal dari baris 2 sampai baris 6*/
else if((cells[i][2].getToken() == token) && (cells[i][3].getToken() == token) && (cells[i][4].getToken() == token) && (cells[i][5].getToken() == token) && (cells[i][6].getToken() == token)){return true;} /*Horizontal dari baris 3 sampai baris 7*/
else if((cells[i][3].getToken() == token) && (cells[i][4].getToken() == token) && (cells[i][5].getToken() == token) && (cells[i][6].getToken() == token) && (cells[i][7].getToken() == token)){return true;} /*Horizontal dari baris 4 sampai baris 8*/
else if((cells[i][4].getToken() == token) && (cells[i][5].getToken() == token) && (cells[i][6].getToken() == token) && (cells[i][7].getToken() == token) && (cells[i][8].getToken() == token)){return true;} /*Horizontal dari baris 5 sampai baris 9*/
else if((cells[i][5].getToken() == token) && (cells[i][6].getToken() == token) && (cells[i][7].getToken() == token) && (cells[i][8].getToken() == token) && (cells[i][9].getToken() == token)){return true;} /*Horizontal dari baris 6 sampai baris 10*/
}
/*-----------------------------------------------------------------------------------------------------Kondisi Menang Vertikal----------------------------------------------------------------------------------------------------------------------------*/
for (int j = 0; j < 10; j++)
{
if ((cells[0][j].getToken() == token) && (cells[1][j].getToken() == token) && (cells[2][j].getToken() == token) && (cells[3][j].getToken() == token) && (cells[4][j].getToken() == token)) {return true;} /*Vertikal dari kolom 1 sampai kolom 5*/
else if ((cells[1][j].getToken() == token) && (cells[2][j].getToken() == token) && (cells[3][j].getToken() == token) && (cells[4][j].getToken() == token) && (cells[5][j].getToken() == token)){return true;} /*vertikal dari kolom 2 sampai kolom 6*/
else if ((cells[2][j].getToken() == token) && (cells[3][j].getToken() == token) && (cells[4][j].getToken() == token) && (cells[5][j].getToken() == token) && (cells[6][j].getToken() == token)){return true;} /*vertikal dari kolom 3 sampai kolom 7*/
else if ((cells[3][j].getToken() == token) && (cells[4][j].getToken() == token) && (cells[5][j].getToken() == token) && (cells[6][j].getToken() == token) && (cells[7][j].getToken() == token)){return true;} /*vertikal dari kolom 4 sampai kolom 8*/
else if ((cells[4][j].getToken() == token) && (cells[5][j].getToken() == token) && (cells[6][j].getToken() == token) && (cells[7][j].getToken() == token) && (cells[8][j].getToken() == token)){return true;} /*vertikal dari kolom 5 sampai kolom 9*/
else if ((cells[5][j].getToken() == token) && (cells[6][j].getToken() == token) && (cells[7][j].getToken() == token) && (cells[8][j].getToken() == token) && (cells[9][j].getToken() == token)){return true;} /*vertikal dari kolom 6 sampai kolom 10*/
}

/*------------------------------------------------------------------------------------------------------Kondisi Menang Kiri atas ke Kanan Bawah-----------------------------------------------------------------------------------------------------------*/
if ((cells[0][0].getToken() == token) && (cells[1][1].getToken() == token) && (cells[2][2].getToken() == token) && (cells[3][3].getToken() == token) && (cells[4][4].getToken() == token)) {return true;} /*serong dari kiri atas ke kanan bawah dari kolom 1 sampai kolom 5*/
else if((cells[1][1].getToken() == token) && (cells[2][2].getToken() == token) && (cells[3][3].getToken() == token) && (cells[4][4].getToken() == token) && (cells[5][5].getToken() == token)){return true;} /*serong dari kiri atas ke kanan bawah dari kolom 2 sampai kolom 6*/
else if((cells[2][2].getToken() == token) && (cells[3][3].getToken() == token) && (cells[4][4].getToken() == token) && (cells[5][5].getToken() == token) && (cells[6][6].getToken() == token)){return true;} /*serong dari kiri atas ke kanan bawah dari kolom 3 sampai kolom 7*/
else if((cells[3][3].getToken() == token) && (cells[4][4].getToken() == token) && (cells[5][5].getToken() == token) && (cells[6][6].getToken() == token) && (cells[7][7].getToken() == token)){return true;} /*serong dari kiri atas ke kanan bawah dari kolom 4 sampai kolom 8*/
else if((cells[4][4].getToken() == token) && (cells[5][5].getToken() == token) && (cells[6][6].getToken() == token) && (cells[7][7].getToken() == token) && (cells[8][8].getToken() == token)){return true;} /*serong dari kiri atas ke kanan bawah dari kolom 5 sampai kolom 9*/
else if((cells[5][5].getToken() == token) && (cells[6][6].getToken() == token) && (cells[7][7].getToken() == token) && (cells[8][8].getToken() == token) && (cells[9][9].getToken() == token)){return true;} /*serong dari kiri atas ke kanan bawah dari kolom 6 sampai kolom 10*/

if ((cells[0][0].getToken() == token) && (cells[1][1].getToken() == token) && (cells[2][2].getToken() == token) && (cells[3][3].getToken() == token) && (cells[4][4].getToken() == token)) {return true;} /*00 - 44*/
else if ((cells[0][1].getToken() == token) && (cells[1][2].getToken() == token) && (cells[2][3].getToken() == token) && (cells[3][4].getToken() == token) && (cells[4][5].getToken() == token)) {return true;} /*01 - 45*/
else if ((cells[0][2].getToken() == token) && (cells[1][3].getToken() == token) && (cells[2][4].getToken() == token) && (cells[3][5].getToken() == token) && (cells[4][6].getToken() == token)) {return true;} /*02 - 46*/
else if ((cells[0][3].getToken() == token) && (cells[1][4].getToken() == token) && (cells[2][5].getToken() == token) && (cells[3][6].getToken() == token) && (cells[4][7].getToken() == token)) {return true;} /*03 - 47*/
else if ((cells[0][4].getToken() == token) && (cells[1][5].getToken() == token) && (cells[2][6].getToken() == token) && (cells[3][7].getToken() == token) && (cells[4][8].getToken() == token)) {return true;} /*04 - 48*/
else if ((cells[0][5].getToken() == token) && (cells[1][6].getToken() == token) && (cells[2][7].getToken() == token) && (cells[3][8].getToken() == token) && (cells[4][9].getToken() == token)) {return true;} /*05 - 49*/

else if ((cells[1][0].getToken() == token) && (cells[2][1].getToken() == token) && (cells[3][2].getToken() == token) && (cells[4][3].getToken() == token) && (cells[5][4].getToken() == token)) {return true;} /*10 - 54*/
else if ((cells[1][1].getToken() == token) && (cells[2][2].getToken() == token) && (cells[3][3].getToken() == token) && (cells[4][4].getToken() == token) && (cells[5][5].getToken() == token)) {return true;} /*11 - 55*/
else if ((cells[1][2].getToken() == token) && (cells[2][3].getToken() == token) && (cells[3][4].getToken() == token) && (cells[4][5].getToken() == token) && (cells[5][6].getToken() == token)) {return true;} /*12 - 56*/
else if ((cells[1][3].getToken() == token) && (cells[2][4].getToken() == token) && (cells[3][5].getToken() == token) && (cells[4][6].getToken() == token) && (cells[5][7].getToken() == token)) {return true;} /*13 - 57*/
else if ((cells[1][4].getToken() == token) && (cells[2][5].getToken() == token) && (cells[3][6].getToken() == token) && (cells[4][7].getToken() == token) && (cells[5][8].getToken() == token)) {return true;} /*14 - 58*/
else if ((cells[1][5].getToken() == token) && (cells[2][6].getToken() == token) && (cells[3][7].getToken() == token) && (cells[4][8].getToken() == token) && (cells[5][9].getToken() == token)) {return true;} /*15 - 59*/

else if ((cells[2][0].getToken() == token) && (cells[3][1].getToken() == token) && (cells[4][2].getToken() == token) && (cells[5][3].getToken() == token) && (cells[6][4].getToken() == token)) {return true;} /*20 - 64*/
else if ((cells[2][1].getToken() == token) && (cells[3][2].getToken() == token) && (cells[4][3].getToken() == token) && (cells[5][4].getToken() == token) && (cells[6][5].getToken() == token)) {return true;} /*21 - 65*/
else if ((cells[2][2].getToken() == token) && (cells[3][3].getToken() == token) && (cells[4][4].getToken() == token) && (cells[5][5].getToken() == token) && (cells[6][6].getToken() == token)) {return true;} /*22 - 66*/
else if ((cells[2][3].getToken() == token) && (cells[3][4].getToken() == token) && (cells[4][5].getToken() == token) && (cells[5][6].getToken() == token) && (cells[6][7].getToken() == token)) {return true;} /*23 - 67*/
else if ((cells[2][4].getToken() == token) && (cells[3][5].getToken() == token) && (cells[4][6].getToken() == token) && (cells[5][7].getToken() == token) && (cells[6][8].getToken() == token)) {return true;} /*24 - 68*/
else if ((cells[2][5].getToken() == token) && (cells[3][6].getToken() == token) && (cells[4][7].getToken() == token) && (cells[5][8].getToken() == token) && (cells[6][9].getToken() == token)) {return true;} /*25 - 69*/

else if ((cells[3][0].getToken() == token) && (cells[4][1].getToken() == token) && (cells[5][2].getToken() == token) && (cells[6][3].getToken() == token) && (cells[7][4].getToken() == token)) {return true;} /*30 - 74*/
else if ((cells[3][1].getToken() == token) && (cells[4][2].getToken() == token) && (cells[5][3].getToken() == token) && (cells[6][4].getToken() == token) && (cells[7][5].getToken() == token)) {return true;} /*31 - 75*/
else if ((cells[3][2].getToken() == token) && (cells[4][3].getToken() == token) && (cells[5][4].getToken() == token) && (cells[6][5].getToken() == token) && (cells[7][6].getToken() == token)) {return true;} /*32 - 76*/
else if ((cells[3][3].getToken() == token) && (cells[4][4].getToken() == token) && (cells[5][5].getToken() == token) && (cells[6][6].getToken() == token) && (cells[7][7].getToken() == token)) {return true;} /*33 - 77*/
else if ((cells[3][4].getToken() == token) && (cells[4][5].getToken() == token) && (cells[5][6].getToken() == token) && (cells[6][7].getToken() == token) && (cells[7][8].getToken() == token)) {return true;} /*34 - 78*/
else if ((cells[3][5].getToken() == token) && (cells[4][6].getToken() == token) && (cells[5][7].getToken() == token) && (cells[6][8].getToken() == token) && (cells[7][9].getToken() == token)) {return true;} /*35 - 79*/

else if ((cells[4][0].getToken() == token) && (cells[5][1].getToken() == token) && (cells[6][2].getToken() == token) && (cells[7][3].getToken() == token) && (cells[8][4].getToken() == token)) {return true;} /*40 - 84*/
else if ((cells[4][1].getToken() == token) && (cells[5][2].getToken() == token) && (cells[6][3].getToken() == token) && (cells[7][4].getToken() == token) && (cells[8][5].getToken() == token)) {return true;} /*41 - 85*/
else if ((cells[4][2].getToken() == token) && (cells[5][3].getToken() == token) && (cells[6][4].getToken() == token) && (cells[7][5].getToken() == token) && (cells[8][6].getToken() == token)) {return true;} /*42 - 86*/
else if ((cells[4][3].getToken() == token) && (cells[5][4].getToken() == token) && (cells[6][5].getToken() == token) && (cells[7][6].getToken() == token) && (cells[8][7].getToken() == token)) {return true;} /*43 - 87*/
else if ((cells[4][4].getToken() == token) && (cells[5][5].getToken() == token) && (cells[6][6].getToken() == token) && (cells[7][7].getToken() == token) && (cells[8][8].getToken() == token)) {return true;} /*44 - 88*/
else if ((cells[4][5].getToken() == token) && (cells[5][6].getToken() == token) && (cells[6][7].getToken() == token) && (cells[7][8].getToken() == token) && (cells[8][9].getToken() == token)) {return true;} /*45 - 89*/

else if ((cells[5][0].getToken() == token) && (cells[6][1].getToken() == token) && (cells[7][2].getToken() == token) && (cells[8][3].getToken() == token) && (cells[9][4].getToken() == token)) {return true;} /*50 - 94*/
else if ((cells[5][1].getToken() == token) && (cells[6][2].getToken() == token) && (cells[7][3].getToken() == token) && (cells[8][4].getToken() == token) && (cells[9][5].getToken() == token)) {return true;} /*51 - 95*/
else if ((cells[5][2].getToken() == token) && (cells[6][3].getToken() == token) && (cells[7][4].getToken() == token) && (cells[8][5].getToken() == token) && (cells[9][6].getToken() == token)) {return true;} /*52 - 96*/
else if ((cells[5][3].getToken() == token) && (cells[6][4].getToken() == token) && (cells[7][5].getToken() == token) && (cells[8][6].getToken() == token) && (cells[9][7].getToken() == token)) {return true;} /*53 - 97*/
else if ((cells[5][4].getToken() == token) && (cells[6][5].getToken() == token) && (cells[7][6].getToken() == token) && (cells[8][7].getToken() == token) && (cells[9][8].getToken() == token)) {return true;} /*54 - 98*/
else if ((cells[5][5].getToken() == token) && (cells[6][6].getToken() == token) && (cells[7][7].getToken() == token) && (cells[8][8].getToken() == token) && (cells[9][9].getToken() == token)) {return true;} /*55 - 99*/

/*------------------------------------------------------------------------------------------------------Kondisi Menang Kiri bawah ke Kanan atas-----------------------------------------------------------------------------------------------------------*/
if ((cells[0][4].getToken() == token) && (cells[1][3].getToken() == token) && (cells[2][2].getToken() == token) && (cells[3][1].getToken() == token) && (cells[4][0].getToken() == token)) { return true;} /*04 - 40*/
else if ((cells[0][5].getToken() == token) && (cells[1][4].getToken() == token) && (cells[2][3].getToken() == token) && (cells[3][2].getToken() == token) && (cells[4][1].getToken() == token)) {return true;} /*05 - 41*/
else if ((cells[0][6].getToken() == token) && (cells[1][5].getToken() == token) && (cells[2][4].getToken() == token) && (cells[3][3].getToken() == token) && (cells[4][2].getToken() == token)) {return true;} /*06 - 42*/
else if ((cells[0][7].getToken() == token) && (cells[1][6].getToken() == token) && (cells[2][5].getToken() == token) && (cells[3][4].getToken() == token) && (cells[4][3].getToken() == token)) {return true;} /*07 - 43*/
else if ((cells[0][8].getToken() == token) && (cells[1][7].getToken() == token) && (cells[2][6].getToken() == token) && (cells[3][5].getToken() == token) && (cells[4][4].getToken() == token)) {return true;} /*08 - 44*/
else if ((cells[0][9].getToken() == token) && (cells[1][8].getToken() == token) && (cells[2][7].getToken() == token) && (cells[3][6].getToken() == token) && (cells[4][5].getToken() == token)) {return true;} /*09 - 45*/

else if ((cells[1][4].getToken() == token) && (cells[2][3].getToken() == token) && (cells[3][2].getToken() == token) && (cells[4][1].getToken() == token) && (cells[5][0].getToken() == token)) {return true;} /*19 - 55*/
else if ((cells[1][5].getToken() == token) && (cells[2][4].getToken() == token) && (cells[3][3].getToken() == token) && (cells[4][2].getToken() == token) && (cells[5][1].getToken() == token)) {return true;} /*15 - 51*/
else if ((cells[1][6].getToken() == token) && (cells[2][5].getToken() == token) && (cells[3][4].getToken() == token) && (cells[4][3].getToken() == token) && (cells[5][2].getToken() == token)) {return true;} /*16 - 52*/
else if ((cells[1][7].getToken() == token) && (cells[2][6].getToken() == token) && (cells[3][5].getToken() == token) && (cells[4][4].getToken() == token) && (cells[5][3].getToken() == token)) {return true;} /*17 - 53*/
else if ((cells[1][8].getToken() == token) && (cells[2][7].getToken() == token) && (cells[3][6].getToken() == token) && (cells[4][5].getToken() == token) && (cells[5][4].getToken() == token)) {return true;} /*18 - 54*/
else if ((cells[1][9].getToken() == token) && (cells[2][8].getToken() == token) && (cells[3][7].getToken() == token) && (cells[4][6].getToken() == token) && (cells[5][5].getToken() == token)) {return true;} /*19 - 55*/

else if ((cells[2][4].getToken() == token) && (cells[3][3].getToken() == token) && (cells[4][2].getToken() == token) && (cells[5][1].getToken() == token) && (cells[6][0].getToken() == token)) {return true;} /*29 - 65*/
else if ((cells[2][5].getToken() == token) && (cells[3][4].getToken() == token) && (cells[4][3].getToken() == token) && (cells[5][2].getToken() == token) && (cells[6][1].getToken() == token)) {return true;} /*25 - 61*/
else if ((cells[2][6].getToken() == token) && (cells[3][5].getToken() == token) && (cells[4][4].getToken() == token) && (cells[5][3].getToken() == token) && (cells[6][2].getToken() == token)) {return true;} /*26 - 62*/
else if ((cells[2][7].getToken() == token) && (cells[3][6].getToken() == token) && (cells[4][5].getToken() == token) && (cells[5][4].getToken() == token) && (cells[6][3].getToken() == token)) {return true;} /*27 - 63*/
else if ((cells[2][8].getToken() == token) && (cells[3][7].getToken() == token) && (cells[4][6].getToken() == token) && (cells[5][5].getToken() == token) && (cells[6][4].getToken() == token)) {return true;} /*28 - 64*/
else if ((cells[2][9].getToken() == token) && (cells[3][8].getToken() == token) && (cells[4][7].getToken() == token) && (cells[5][6].getToken() == token) && (cells[6][5].getToken() == token)) {return true;} /*29 - 65*/

else if ((cells[3][4].getToken() == token) && (cells[4][3].getToken() == token) && (cells[5][2].getToken() == token) && (cells[6][1].getToken() == token) && (cells[7][0].getToken() == token)) {return true;} /*39 - 75*/
else if ((cells[3][5].getToken() == token) && (cells[4][4].getToken() == token) &

Agak panjang, agar tampilannya lebih rapi, silahkan copas saja ke tect editor atau pengolahan source code kesayangan anda.

Program diatas sudah dilengkapi dengan aturan kemenagan, jika pemain dapat menyusun posisi sebanyak 5 deret secara berturut-turut, maka akan menang. Untuk memainkannya silahkan menuju ke: http://cs.unsyiah.ac.id/~alamri/belajar/TicTacToe/ (KLIK).

Semoga source code diatas dapat berguna, lebih dan kurang saya mohon maaf. Wassalam. ~ Ahmad Ariful Amri

Kamis, 03 Januari 2013

http://go-program.blogspot.com/2013/01/source-code-java-applet-1-game-tictactoe.html
Iseng-iseng saya mencari cara membuat game tictactoe sebagai tugas yang diberikan dosen, ternyata source codenya sudah tertampang di halaman web dosen yang memberikan tugas tersebut. dihalaman tersebut sudah terpampang sebuah applet game tictactoe menggunakan java. Otomatis untuk menampilkan applet dibrowser, dibutuhkan file.class yang merpuakan hasil kompilasi file.java. Nah entah lupa khilaf atau kesalahan sistem, bapak "Pemberi tugas" tidak menutup akses tempat disimpannya file .class tersebut. 

Tentu saja mahasiswa seperti saya tidak bisa mengabaikan source code gratis dari dosen ini, langsung saja saya dowload TicTac.class dan di decompile menggunakan aplikasi java decompiler. Jreeeng Seluruh source code dari dosen terpampang jelas dengan sempurna. Namun source code dibawah ini bukanlah buatan dosen saya, melainkan robor pembuat game tictactoe yang telah dibuat olehnya. Iniah dia source code game TacTicToe Dengan java Applet

/*--------------------------------------------------------*/
/*-----Author : Robot Dosen saya------------------------*/
/*-----Program: Applet Tictactoe--------------------------*/
/*------------http://go-program.blogspot.com--------------*/
/*--------------------------------------------------------*/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class TicTac extends JApplet
implements ActionListener
{
int x = 10;

JButton[] pp = new JButton[this.x * this.x];
JLabel ln = new JLabel(" Giliran Pemain Pertama");
int w = 1;

public void init() {
setSize(50 * this.x + 5, 50 * this.x + 5);

JPanel pane = new JPanel();
BorderLayout border = new BorderLayout();
pane.setLayout(border);

JPanel paneButton = new JPanel();
paneButton.setLayout(new GridLayout(this.x, this.x, 0, 0));

for (int i = 0; i < this.x * this.x; i++) this.pp[i] = new JButton("");
for (int i = 0; i < this.x * this.x; i++) this.pp[i].addActionListener(this);
for (int i = 0; i < this.x * this.x; i++) paneButton.add(this.pp[i]);

pane.add("Center", paneButton);
pane.add("South", add(this.ln));
setContentPane(pane);
show();
}
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == this.pp[0]) {
if (this.w == 1) { this.pp[0].setText(" X "); this.pp[0].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[0].setText(" O "); this.pp[0].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[0].setEnabled(false);
} else if (evt.getSource() == this.pp[1]) {
if (this.w == 1) { this.pp[1].setText(" X "); this.pp[1].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[1].setText(" O "); this.pp[1].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[1].setEnabled(false);
} else if (evt.getSource() == this.pp[2]) {
if (this.w == 1) { this.pp[2].setText(" X "); this.pp[2].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[2].setText(" O "); this.pp[2].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[2].setEnabled(false);
} else if (evt.getSource() == this.pp[3]) {
if (this.w == 1) { this.pp[3].setText(" X "); this.pp[3].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[3].setText(" O "); this.pp[3].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[3].setEnabled(false);
} else if (evt.getSource() == this.pp[4]) {
if (this.w == 1) { this.pp[4].setText(" X "); this.pp[4].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[4].setText(" O "); this.pp[4].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[4].setEnabled(false);
} else if (evt.getSource() == this.pp[5]) {
if (this.w == 1) { this.pp[5].setText(" X "); this.pp[5].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[5].setText(" O "); this.pp[5].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[5].setEnabled(false);
} else if (evt.getSource() == this.pp[6]) {
if (this.w == 1) { this.pp[6].setText(" X "); this.pp[6].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[6].setText(" O "); this.pp[6].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[6].setEnabled(false);
} else if (evt.getSource() == this.pp[7]) {
if (this.w == 1) { this.pp[7].setText(" X "); this.pp[7].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[7].setText(" O "); this.pp[7].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[7].setEnabled(false);
} else if (evt.getSource() == this.pp[8]) {
if (this.w == 1) { this.pp[8].setText(" X "); this.pp[8].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[8].setText(" O "); this.pp[8].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[8].setEnabled(false);
} else if (evt.getSource() == this.pp[9]) {
if (this.w == 1) { this.pp[9].setText(" X "); this.pp[9].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[9].setText(" O "); this.pp[9].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[9].setEnabled(false);
} else if (evt.getSource() == this.pp[10]) {
if (this.w == 1) { this.pp[10].setText(" X "); this.pp[10].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[10].setText(" O "); this.pp[10].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[10].setEnabled(false);
} else if (evt.getSource() == this.pp[11]) {
if (this.w == 1) { this.pp[11].setText(" X "); this.pp[11].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[11].setText(" O "); this.pp[11].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[11].setEnabled(false);
} else if (evt.getSource() == this.pp[12]) {
if (this.w == 1) { this.pp[12].setText(" X "); this.pp[12].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[12].setText(" O "); this.pp[12].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[12].setEnabled(false);
} else if (evt.getSource() == this.pp[13]) {
if (this.w == 1) { this.pp[13].setText(" X "); this.pp[13].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[13].setText(" O "); this.pp[13].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[13].setEnabled(false);
} else if (evt.getSource() == this.pp[14]) {
if (this.w == 1) { this.pp[14].setText(" X "); this.pp[14].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[14].setText(" O "); this.pp[14].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[14].setEnabled(false);
} else if (evt.getSource() == this.pp[15]) {
if (this.w == 1) { this.pp[15].setText(" X "); this.pp[15].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[15].setText(" O "); this.pp[15].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[15].setEnabled(false);
} else if (evt.getSource() == this.pp[16]) {
if (this.w == 1) { this.pp[16].setText(" X "); this.pp[16].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[16].setText(" O "); this.pp[16].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[16].setEnabled(false);
} else if (evt.getSource() == this.pp[17]) {
if (this.w == 1) { this.pp[17].setText(" X "); this.pp[17].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[17].setText(" O "); this.pp[17].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[17].setEnabled(false);
} else if (evt.getSource() == this.pp[18]) {
if (this.w == 1) { this.pp[18].setText(" X "); this.pp[18].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[18].setText(" O "); this.pp[18].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[18].setEnabled(false);
} else if (evt.getSource() == this.pp[19]) {
if (this.w == 1) { this.pp[19].setText(" X "); this.pp[19].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[19].setText(" O "); this.pp[19].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[19].setEnabled(false);
} else if (evt.getSource() == this.pp[20]) {
if (this.w == 1) { this.pp[20].setText(" X "); this.pp[20].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[20].setText(" O "); this.pp[20].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[20].setEnabled(false);
} else if (evt.getSource() == this.pp[21]) {
if (this.w == 1) { this.pp[21].setText(" X "); this.pp[21].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[21].setText(" O "); this.pp[21].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[21].setEnabled(false);
} else if (evt.getSource() == this.pp[22]) {
if (this.w == 1) { this.pp[22].setText(" X "); this.pp[22].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[22].setText(" O "); this.pp[22].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[22].setEnabled(false);
} else if (evt.getSource() == this.pp[23]) {
if (this.w == 1) { this.pp[23].setText(" X "); this.pp[23].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[23].setText(" O "); this.pp[23].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[23].setEnabled(false);
} else if (evt.getSource() == this.pp[24]) {
if (this.w == 1) { this.pp[24].setText(" X "); this.pp[24].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[24].setText(" O "); this.pp[24].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[24].setEnabled(false);
} else if (evt.getSource() == this.pp[25]) {
if (this.w == 1) { this.pp[25].setText(" X "); this.pp[25].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[25].setText(" O "); this.pp[25].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[25].setEnabled(false);
} else if (evt.getSource() == this.pp[26]) {
if (this.w == 1) { this.pp[26].setText(" X "); this.pp[26].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[26].setText(" O "); this.pp[26].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[26].setEnabled(false);
} else if (evt.getSource() == this.pp[27]) {
if (this.w == 1) { this.pp[27].setText(" X "); this.pp[27].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[27].setText(" O "); this.pp[27].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[27].setEnabled(false);
} else if (evt.getSource() == this.pp[28]) {
if (this.w == 1) { this.pp[28].setText(" X "); this.pp[28].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[28].setText(" O "); this.pp[28].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[28].setEnabled(false);
} else if (evt.getSource() == this.pp[29]) {
if (this.w == 1) { this.pp[29].setText(" X "); this.pp[29].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[29].setText(" O "); this.pp[29].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[29].setEnabled(false);
} else if (evt.getSource() == this.pp[30]) {
if (this.w == 1) { this.pp[30].setText(" X "); this.pp[30].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[30].setText(" O "); this.pp[30].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[30].setEnabled(false);
} else if (evt.getSource() == this.pp[31]) {
if (this.w == 1) { this.pp[31].setText(" X "); this.pp[31].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[31].setText(" O "); this.pp[31].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[31].setEnabled(false);
} else if (evt.getSource() == this.pp[32]) {
if (this.w == 1) { this.pp[32].setText(" X "); this.pp[32].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[32].setText(" O "); this.pp[32].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[32].setEnabled(false);
} else if (evt.getSource() == this.pp[33]) {
if (this.w == 1) { this.pp[33].setText(" X "); this.pp[33].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[33].setText(" O "); this.pp[33].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[33].setEnabled(false);
} else if (evt.getSource() == this.pp[34]) {
if (this.w == 1) { this.pp[34].setText(" X "); this.pp[34].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[34].setText(" O "); this.pp[34].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[34].setEnabled(false);
} else if (evt.getSource() == this.pp[35]) {
if (this.w == 1) { this.pp[35].setText(" X "); this.pp[35].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[35].setText(" O "); this.pp[35].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[35].setEnabled(false);
} else if (evt.getSource() == this.pp[36]) {
if (this.w == 1) { this.pp[36].setText(" X "); this.pp[36].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[36].setText(" O "); this.pp[36].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[36].setEnabled(false);
} else if (evt.getSource() == this.pp[37]) {
if (this.w == 1) { this.pp[37].setText(" X "); this.pp[37].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[37].setText(" O "); this.pp[37].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[37].setEnabled(false);
} else if (evt.getSource() == this.pp[38]) {
if (this.w == 1) { this.pp[38].setText(" X "); this.pp[38].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[38].setText(" O "); this.pp[38].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[38].setEnabled(false);
} else if (evt.getSource() == this.pp[39]) {
if (this.w == 1) { this.pp[39].setText(" X "); this.pp[39].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[39].setText(" O "); this.pp[39].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[39].setEnabled(false);
} else if (evt.getSource() == this.pp[40]) {
if (this.w == 1) { this.pp[40].setText(" X "); this.pp[40].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[40].setText(" O "); this.pp[40].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[40].setEnabled(false);
} else if (evt.getSource() == this.pp[41]) {
if (this.w == 1) { this.pp[41].setText(" X "); this.pp[41].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[41].setText(" O "); this.pp[41].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[41].setEnabled(false);
} else if (evt.getSource() == this.pp[42]) {
if (this.w == 1) { this.pp[42].setText(" X "); this.pp[42].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[42].setText(" O "); this.pp[42].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[42].setEnabled(false);
} else if (evt.getSource() == this.pp[43]) {
if (this.w == 1) { this.pp[43].setText(" X "); this.pp[43].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[43].setText(" O "); this.pp[43].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[43].setEnabled(false);
} else if (evt.getSource() == this.pp[44]) {
if (this.w == 1) { this.pp[44].setText(" X "); this.pp[44].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[44].setText(" O "); this.pp[44].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[44].setEnabled(false);
} else if (evt.getSource() == this.pp[45]) {
if (this.w == 1) { this.pp[45].setText(" X "); this.pp[45].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[45].setText(" O "); this.pp[45].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[45].setEnabled(false);
} else if (evt.getSource() == this.pp[46]) {
if (this.w == 1) { this.pp[46].setText(" X "); this.pp[46].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[46].setText(" O "); this.pp[46].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[46].setEnabled(false);
} else if (evt.getSource() == this.pp[47]) {
if (this.w == 1) { this.pp[47].setText(" X "); this.pp[47].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[47].setText(" O "); this.pp[47].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[47].setEnabled(false);
} else if (evt.getSource() == this.pp[48]) {
if (this.w == 1) { this.pp[48].setText(" X "); this.pp[48].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[48].setText(" O "); this.pp[48].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[48].setEnabled(false);
} else if (evt.getSource() == this.pp[49]) {
if (this.w == 1) { this.pp[49].setText(" X "); this.pp[49].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[49].setText(" O "); this.pp[49].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[49].setEnabled(false);
} else if (evt.getSource() == this.pp[50]) {
if (this.w == 1) { this.pp[50].setText(" X "); this.pp[50].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[50].setText(" O "); this.pp[50].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[50].setEnabled(false);
} else if (evt.getSource() == this.pp[51]) {
if (this.w == 1) { this.pp[51].setText(" X "); this.pp[51].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[51].setText(" O "); this.pp[51].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[51].setEnabled(false);
} else if (evt.getSource() == this.pp[52]) {
if (this.w == 1) { this.pp[52].setText(" X "); this.pp[52].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[52].setText(" O "); this.pp[52].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[52].setEnabled(false);
} else if (evt.getSource() == this.pp[53]) {
if (this.w == 1) { this.pp[53].setText(" X "); this.pp[53].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[53].setText(" O "); this.pp[53].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[53].setEnabled(false);
} else if (evt.getSource() == this.pp[54]) {
if (this.w == 1) { this.pp[54].setText(" X "); this.pp[54].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[54].setText(" O "); this.pp[54].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[54].setEnabled(false);
} else if (evt.getSource() == this.pp[55]) {
if (this.w == 1) { this.pp[55].setText(" X "); this.pp[55].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[55].setText(" O "); this.pp[55].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[55].setEnabled(false);
} else if (evt.getSource() == this.pp[56]) {
if (this.w == 1) { this.pp[56].setText(" X "); this.pp[56].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[56].setText(" O "); this.pp[56].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[56].setEnabled(false);
} else if (evt.getSource() == this.pp[57]) {
if (this.w == 1) { this.pp[57].setText(" X "); this.pp[57].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[57].setText(" O "); this.pp[57].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[57].setEnabled(false);
} else if (evt.getSource() == this.pp[58]) {
if (this.w == 1) { this.pp[58].setText(" X "); this.pp[58].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[58].setText(" O "); this.pp[58].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[58].setEnabled(false);
} else if (evt.getSource() == this.pp[59]) {
if (this.w == 1) { this.pp[59].setText(" X "); this.pp[59].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[59].setText(" O "); this.pp[59].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[59].setEnabled(false);
} else if (evt.getSource() == this.pp[60]) {
if (this.w == 1) { this.pp[60].setText(" X "); this.pp[60].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[60].setText(" O "); this.pp[60].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[60].setEnabled(false);
} else if (evt.getSource() == this.pp[61]) {
if (this.w == 1) { this.pp[61].setText(" X "); this.pp[61].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[61].setText(" O "); this.pp[61].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[61].setEnabled(false);
} else if (evt.getSource() == this.pp[62]) {
if (this.w == 1) { this.pp[62].setText(" X "); this.pp[62].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[62].setText(" O "); this.pp[62].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[62].setEnabled(false);
} else if (evt.getSource() == this.pp[63]) {
if (this.w == 1) { this.pp[63].setText(" X "); this.pp[63].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[63].setText(" O "); this.pp[63].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[63].setEnabled(false);
} else if (evt.getSource() == this.pp[64]) {
if (this.w == 1) { this.pp[64].setText(" X "); this.pp[64].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[64].setText(" O "); this.pp[64].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[64].setEnabled(false);
} else if (evt.getSource() == this.pp[65]) {
if (this.w == 1) { this.pp[65].setText(" X "); this.pp[65].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[65].setText(" O "); this.pp[65].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[65].setEnabled(false);
} else if (evt.getSource() == this.pp[66]) {
if (this.w == 1) { this.pp[66].setText(" X "); this.pp[66].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[66].setText(" O "); this.pp[66].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[66].setEnabled(false);
} else if (evt.getSource() == this.pp[67]) {
if (this.w == 1) { this.pp[67].setText(" X "); this.pp[67].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[67].setText(" O "); this.pp[67].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[67].setEnabled(false);
} else if (evt.getSource() == this.pp[68]) {
if (this.w == 1) { this.pp[68].setText(" X "); this.pp[68].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[68].setText(" O "); this.pp[68].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[68].setEnabled(false);
} else if (evt.getSource() == this.pp[69]) {
if (this.w == 1) { this.pp[69].setText(" X "); this.pp[69].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[69].setText(" O "); this.pp[69].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[69].setEnabled(false);
} else if (evt.getSource() == this.pp[70]) {
if (this.w == 1) { this.pp[70].setText(" X "); this.pp[70].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[70].setText(" O "); this.pp[70].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[70].setEnabled(false);
} else if (evt.getSource() == this.pp[71]) {
if (this.w == 1) { this.pp[71].setText(" X "); this.pp[71].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[71].setText(" O "); this.pp[71].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[71].setEnabled(false);
} else if (evt.getSource() == this.pp[72]) {
if (this.w == 1) { this.pp[72].setText(" X "); this.pp[72].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[72].setText(" O "); this.pp[72].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[72].setEnabled(false);
} else if (evt.getSource() == this.pp[73]) {
if (this.w == 1) { this.pp[73].setText(" X "); this.pp[73].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[73].setText(" O "); this.pp[73].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[73].setEnabled(false);
} else if (evt.getSource() == this.pp[74]) {
if (this.w == 1) { this.pp[74].setText(" X "); this.pp[74].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[74].setText(" O "); this.pp[74].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[74].setEnabled(false);
} else if (evt.getSource() == this.pp[75]) {
if (this.w == 1) { this.pp[75].setText(" X "); this.pp[75].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[75].setText(" O "); this.pp[75].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[75].setEnabled(false);
} else if (evt.getSource() == this.pp[76]) {
if (this.w == 1) { this.pp[76].setText(" X "); this.pp[76].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[76].setText(" O "); this.pp[76].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[76].setEnabled(false);
} else if (evt.getSource() == this.pp[77]) {
if (this.w == 1) { this.pp[77].setText(" X "); this.pp[77].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[77].setText(" O "); this.pp[77].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[77].setEnabled(false);
} else if (evt.getSource() == this.pp[78]) {
if (this.w == 1) { this.pp[78].setText(" X "); this.pp[78].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[78].setText(" O "); this.pp[78].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[78].setEnabled(false);
} else if (evt.getSource() == this.pp[79]) {
if (this.w == 1) { this.pp[79].setText(" X "); this.pp[79].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[79].setText(" O "); this.pp[79].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[79].setEnabled(false);
} else if (evt.getSource() == this.pp[80]) {
if (this.w == 1) { this.pp[80].setText(" X "); this.pp[80].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[80].setText(" O "); this.pp[80].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[80].setEnabled(false);
} else if (evt.getSource() == this.pp[81]) {
if (this.w == 1) { this.pp[81].setText(" X "); this.pp[81].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[81].setText(" O "); this.pp[81].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[81].setEnabled(false);
} else if (evt.getSource() == this.pp[82]) {
if (this.w == 1) { this.pp[82].setText(" X "); this.pp[82].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[82].setText(" O "); this.pp[82].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[82].setEnabled(false);
} else if (evt.getSource() == this.pp[83]) {
if (this.w == 1) { this.pp[83].setText(" X "); this.pp[83].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[83].setText(" O "); this.pp[83].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[83].setEnabled(false);
} else if (evt.getSource() == this.pp[84]) {
if (this.w == 1) { this.pp[84].setText(" X "); this.pp[84].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[84].setText(" O "); this.pp[84].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[84].setEnabled(false);
} else if (evt.getSource() == this.pp[85]) {
if (this.w == 1) { this.pp[85].setText(" X "); this.pp[85].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[85].setText(" O "); this.pp[85].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[85].setEnabled(false);
} else if (evt.getSource() == this.pp[86]) {
if (this.w == 1) { this.pp[86].setText(" X "); this.pp[86].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[86].setText(" O "); this.pp[86].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[86].setEnabled(false);
} else if (evt.getSource() == this.pp[87]) {
if (this.w == 1) { this.pp[87].setText(" X "); this.pp[87].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[87].setText(" O "); this.pp[87].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[87].setEnabled(false);
} else if (evt.getSource() == this.pp[88]) {
if (this.w == 1) { this.pp[88].setText(" X "); this.pp[88].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[88].setText(" O "); this.pp[88].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[88].setEnabled(false);
} else if (evt.getSource() == this.pp[89]) {
if (this.w == 1) { this.pp[89].setText(" X "); this.pp[89].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[89].setText(" O "); this.pp[89].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[89].setEnabled(false);
} else if (evt.getSource() == this.pp[90]) {
if (this.w == 1) { this.pp[90].setText(" X "); this.pp[90].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[90].setText(" O "); this.pp[90].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[90].setEnabled(false);
} else if (evt.getSource() == this.pp[91]) {
if (this.w == 1) { this.pp[91].setText(" X "); this.pp[91].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[91].setText(" O "); this.pp[91].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[91].setEnabled(false);
} else if (evt.getSource() == this.pp[92]) {
if (this.w == 1) { this.pp[92].setText(" X "); this.pp[92].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[92].setText(" O "); this.pp[92].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[92].setEnabled(false);
} else if (evt.getSource() == this.pp[93]) {
if (this.w == 1) { this.pp[93].setText(" X "); this.pp[93].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[93].setText(" O "); this.pp[93].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[93].setEnabled(false);
} else if (evt.getSource() == this.pp[94]) {
if (this.w == 1) { this.pp[94].setText(" X "); this.pp[94].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[94].setText(" O "); this.pp[94].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[94].setEnabled(false);
} else if (evt.getSource() == this.pp[95]) {
if (this.w == 1) { this.pp[95].setText(" X "); this.pp[95].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[95].setText(" O "); this.pp[95].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[95].setEnabled(false);
} else if (evt.getSource() == this.pp[96]) {
if (this.w == 1) { this.pp[96].setText(" X "); this.pp[96].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[96].setText(" O "); this.pp[96].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[96].setEnabled(false);
} else if (evt.getSource() == this.pp[97]) {
if (this.w == 1) { this.pp[97].setText(" X "); this.pp[97].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[97].setText(" O "); this.pp[97].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[97].setEnabled(false);
} else if (evt.getSource() == this.pp[98]) {
if (this.w == 1) { this.pp[98].setText(" X "); this.pp[98].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[98].setText(" O "); this.pp[98].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[98].setEnabled(false);
} else if (evt.getSource() == this.pp[99]) {
if (this.w == 1) { this.pp[99].setText(" X "); this.pp[99].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[99].setText(" O "); this.pp[99].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[99].setEnabled(false);
} else if (evt.getSource() == this.pp[100]) {
if (this.w == 1) { this.pp[100].setText(" X "); this.pp[100].setBackground(Color.green); this.ln.setText(" Giliran Pemain Kedua"); this.w = 0; } else {
this.pp[100].setText(" O "); this.pp[100].setBackground(Color.yellow); this.ln.setText(" Giliran Pemain Pertama"); this.w = 1;
}this.pp[100].setEnabled(false);
}
}
}

Source codenya Agak panjang ya, udah panjang namun fiturnya masih belum keren. Belum ada sistem kemenangan, Sehingga hanya untuk asal asal klik saja tanpa ada aturan menang. Untuk melihat atau jika anda ingin memainkannya, dapat menuju ke: http://cs.unsyiah.ac.id/~alamri/belajar/TicTac/ (KLIK)

Karena kurang puas, akhirnya tetap saja saya tidak menggunakan source code ini untuk mengumpulkan tugas. Tapi tetap saja googling dan mencari pencerahan. Entar source code game TicTacToe saya, akan diposting pada artikel selanjutnya. Semoga pembahasan kali ini bisa berguna ya.. :)

Selasa, 01 Januari 2013

http://go-program.blogspot.com/2013/01/membuat-panel-dan-button-game-applet-tictactoe-java.html
Menyambung persoalan tugas yang telah selesai, kali ini saya hanya akan mengulas sedikit tentang proses pembuatan tugas membuat game tictactoe. Pada postingan ini membahas tahap sederhana pembuatan game tictactoe, yaitu membuat panel dan button untuk game tictactoe, disini diharuskan mengimport yang namanya java.awt dan javax.swing. 

agar lebih mudah memahami, silahkan lihat saja sourcecode berikut ini.
/*--------------------------------------------------------*/
/*-----Nama : Ahmad Ariful Amri ------------------------*/
/*-----Program: membuat panel dan button game tictactoe---*/
/*------------http://go-program.blogspot.com--------------*/
/*--------------------------------------------------------*/
import java.awt.*;
import java.awt.event.*;
import java.awt.GridLayout;
import javax.swing.*;
import javax.swing.border.LineBorder;

public class PanelButton extends JApplet
{
JButton[][] button = new JButton[10][10];

public void init()
{
JPanel p = new JPanel();
p.setBackground(Color.blue);
p.setLayout(new GridLayout(10, 10, 0, 0));
for (int i=0; i<10; i++)
for (int j=0; j<10; j++)
p.add(button[i][j] = new JButton());

p.setBorder(new LineBorder(Color.red, 1));
this.getContentPane().add(p, BorderLayout.CENTER);
}

}

Untuk melihat hasil dari program diatas silahkan lihat appletnya di: http://cs.unsyiah.ac.id/~alamri/belajar/tictac/ Nah, penjelasan sourcecode diatas saya kira masih dapat dipahami, jika belum begini:

Untuk mengaktifkan berbagai fungsi/method pada SC diatas, kita harus mengimport :

import java.awt.*;
import java.awt.event.*;
import java.awt.GridLayout;
import javax.swing.*;
import javax.swing.border.LineBorder;

Selanjutnya, untuk membuat sebuah wadah atau tempat diletakkannya isi game tersebut, membutuhkan class JPanel, Jpanel sendiri sebenarnya berna,a Panel saja, cum karena disini dijalankan menggunakan browser, karena ada javax.swing. maka semua komponen swing ditambahkan J didepannya.


p.setBackground(Color.blue);

digunakan untuk membuat backgrond, backgroundnya diberi warna biru.


p.setLayout(new GridLayout(10, 10, 0, 0));

Pada halaman nya diberika grid, atau seperti pembatas garis garis


 for (int i=0; i<10; i++)
for (int j=0; j<10; j++)
p.add(button[i][j] = new JButton());


Menambahkan button atau tombol yang dapat diklik.

Semoga tutorial sederhana diatas dapat berguna

Senin, 31 Desember 2012

Ada-ada saja, saya terinspirasi dari sebuah fanspage konyol di facebook. yang bikin hal-hal aneh, kebetulan kali ini pada tanggal 31 desember 2013. Dibikin saja sebuah program java penanda sudah tahun 2013, sebenarnya biasa-biasa aja sih. Tapi dari pada blog ini nganggur postingan selama beberapa minggul Mending saya posting aja, Walaupun naris tak berguna. hahha 

import java.util.*;

public class TahunBaruMasehi2013
{
public static void main(String args[])
{
int year = Calendar.getInstance().get(Calendar.YEAR);
int thonbaro = 2013;

if(year == thonbaro)
{
System.out.println("Selamat Tahun Baru Masehi 2013.. ");
}
else
{
System.out.println("Masih tahun 2012");
}
}
}

Maaf ya, program diatas agak sedikit terdapat unsur bahasa Acehnya, ThonBaro = Tahun Baru. Sekian aja. kalo pingin tau apa hasiknya ya  silahkan kompile dan run sendiri. saya rasa tanpa dikompile pun sudah tau apa keluarannya :D

Rabu, 19 Desember 2012

Masuk ke tahap selanjutnya dari pembelajaran sebelumnya tentang contoh dasar dan pengenalan java applet. Kini masuk step pembelajaran kedua tentang cara membentuk menggambar lingkaran dan segi empat di java applet.  

Sebelum menggambar sebuah lingkaran, kita membutuhkan sebuah kanvas atau media untuk menggambar. Untuk memenuhinya dapat menggunakan method paint() yang diambil class Graphics. Class Graphics memiliki metode  yang digunakan untuk menampilkan grafik. Setelah memiliki kanvas, sekarang kia membutuhkan pena/rol atau apapun itu yang dapat digunakan untuk membentuk lingkaran ataupun segi empat. Untuk membentuk sebuah lingkaran, dibutuhkan method drawOval sedangkan untuk menggambar segi empat dibutuhkan method drawRect. Dan untuk memberi warna pada lingkaran ataupun segiempat dapatmenggunakan method fillOval dan fillRect.
    drawOval Menggambar lingkaran
    fillOval Mengisi warna Gambar lingkaran
    drawRect Menggambar Segi Empat
    fillRect Memberi warna pada segi empat

    Daripada pusing ama teori yuk kita lihat saja pada implementasi source code nya.

    /*----------------------------------------------------------------*/
    /*-------------Nama : Ahmad Ariful Amri ------------------------*/
    /*-------------Program: lingkaran dan segiempat java applet-------*/
    /*-----------------visit: go-program.blogspot.com-----------------*/
    /*----------------------------------------------------------------*/
    import java.awt.*;
    import java.applet.*;

    public class A1 extends Applet {

    public void paint (Graphics g)
    {
    // menggambar lingkaran dengan memberi warna didalamnya
    g.setColor (Color.red);
    g.fillOval (10,10,100,100);
    //titikmulaisampingkiri, mulai atas, panjang, lebar

    // menggambar segiempat dengan memberi warna didalamnya
    g.setColor (Color.blue);
    g.fillRect (10,160,100,100);

    // menggambar lingkaran TANPA memberi warna didalamnya
    g.setColor (Color.green);
    g.drawOval (200,160,100,100);

    // menggambar segiempat TANPA memberi warna didalamnya
    g.setColor (Color.yellow);
    g.drawRect (200,10,100,100);
    }

    }

    Jika agan mau, silahkan donlod file .class nya yang sudah jadi di : http://ohgitu.googlecode.com/files/A1.class
    soalnya di blog berplatform blogger ini, tidak menuliskan sintaks menampilkan applet. selalu gagal
    Menggambar Lingkaran Dan Segi Empat Java Applet

    nah, source code nya yang beberapa baris cuma menghasilkan beberapa gambar kecil dan sederhana saja. sungguh menyedihkan ya. hahaha. Untuk hari ini sekian dulu pembelajarannya, jika ada hal yang ingin ditanyakan, dapat dilayangkan pada kotak komentar. Terima kasih :)

    Kamis, 13 Desember 2012

    Insya Allah Dalam beberapa Hari kedepan saya akan terus memposting artikel pemrograman mengenai Applet. Karena ada sebuah tugas mata kuliah Pemrograman berbasis Objek (PBO). Tugas kali ini pun berkenaan dengan applet. yaitu membuat permainan Tic Tac Toe. 

    Bisa dikatakan saya memulai belajar applet dari dasar alias NOL, dan disinilah jejak-jejak saya belajar applet. Dari postingan ini. 

    Applet Merupakan (Sepengetahuan saya) aplikasi yang dijalankan didalam web browser

    Hal-hal penting yang harus diketahui dari Applet yaitu:
    • Tidak terdapat main method dalam Java applet
    • Applet didesain untuk dijalankan didalam HTML
    • Membutuhkan kelas java.applet.Applet.
    Berikut ini contoh dasar java applet yang akan menampilkan Hello Ahmad di browser. Pertama buatlah sebuah file java, kita beri namanya Hello.java (sesuai nama classnya).

    public class Hello extends java.applet.Applet
    {
    public void paint(java.awt.Graphics g)
    {
    g.drawString("Hello Ahmad..", 50,25);
    }
    }

    Kemudian kompile lah source code diatas.
    javac Hello.java

    Setelah dikompile, akan terbentuk file Hello.class. Nah file .class inilah yang nantinya akan dijalankan pada browser. Unruk menjalankannya, kita harus membuat sbuah struktur HTML sederhana saja, nantinya file.class akan diletakkan pada Tag . Contoh file HTML nya kita buat saja dalam Coba.html
    <HTML>
    <TITLE>Percobaan Belajar Applet</TITLE>
    <BODY>

    <APPLET code ="Hello.class" style="width:1000px; height:500px"></APPLET>
    </BODY>
    <HTML>

    Setelah semuanya beres, sekarang tinggal jalankan file Coba.html pada browser kesayangan anda. Nanti akan muncul seperti ini:

    Java Applet sederhana
    Hahah, hasil diatas masih sangat sederhana, nanti kita akan terus mempelajari lebih dalam tentang java applet ini. Sepertinya akan mengasyikkan. (y)

    Jumat, 07 Desember 2012

    http://go-program.blogspot.com/2012/12/menulis-string-ke-dalam-file-txt-menggunakan-java.html
    Ada banyak sekali fungsi dari Input Output dalam java yang dapat digunakan untuk mencetak String, char, ataupun jenis data lainnua kedalam sebuah file.txt. pada kesempatan kali ini, akan diposting 2 buah contoh sederhana untuk membuat sebuah file txt menggunakan Java. yang satu menggunakan bufferedwriter, dan  write FileOutputStream biasa.
    1. Cetak.java
    /*----------------------------------------------------------------*/
    /*-------------Nama : Ahmad Ariful Amri ------------------------*/
    /*-------------Program: Mencetak string kedalam sebuah file-------*/
    /*-----------------visit: go-program.blogspot.com-----------------*/
    /*----------------------------------------------------------------*/
    import java.io.*;

    public class Cetak
    {
    public static void main(String args[])throws IOException
    {
    Writer output = null;
    String text = "Percoban menulis String ke dalam file.txt";
    File file = new File("file.txt");
    output = new BufferedWriter(new FileWriter(file));
    output.write(text);
    output.close();

    System.out.println("Tulisan anda sudah di tulis ke " +file);
    }
    }
    2. Cetak3.java
    /*----------------------------------------------------------------*/
    /*-------------Nama : Ahmad Ariful Amri ------------------------*/
    /*-------------Program: Mencetak string kedalam sebuah file-------*/
    /*-----------------visit: go-program.blogspot.com-----------------*/
    /*----------------------------------------------------------------*/

    import java.io.*;

    public class Cetak3
    {
    public void tulis(String pesan,String namaBerkas) throws IOException
    {
    FileOutputStream keluaran = null;

    try
    {
    keluaran = new FileOutputStream(namaBerkas);
    for(int cacah = 0; cacah<pesan.length(); ++cacah)
    {
    int karakter = pesan.charAt(cacah);
    keluaran.write(karakter);
    }
    }
    finally
    {
    if(keluaran !=null)
    {
    keluaran.close();
    }
    }
    }

    public static void main (String args[]) throws IOException
    {
    try
    {
    Cetak3 tulisBerkas = new Cetak3();
    tulisBerkas.tulis("Percobaan menulis String kedalam file", "Cetak3.txt");
    }
    catch(IOException kesalahan)
    {
    System.out.printf("Terjadi kesalahan %s", kesalahan);
    }
    }
    }
    Banyak sekali cara lain yang dapat digunakan untuk mencetak file menggunakan java, silahkan berkreasi

    Senin, 26 November 2012

    Go-Program ~ Supaya dapat meggunakan class yang berada diluar package yang sedang dikerjakan, Anda harus mengimport package dimana class tersebut berada. Pada dasarnya, seluruh program JAVA mengimport package java.lang.*, sehingga Anda dapat menggunakan class seperti String dan Integer dalam program meskipun belum mengimport package sama sekali. Untuk urusan input output file seperti pada salah satu contoh program dibawah ini, kita membutuhkan package io dalam java, cara mengimportnya yaitu dengan menuliskan import java.io.* pada bagian paling atas source codenya.

    http://go-program.blogspot.com/2012/11/program-java-untuk-membaca-sebuah-file.htmlBerikut ini contoh sederhana cara membaca sebuah file txt dan menampilkannya ke layar.
    import java.io.*;
    /*--------------------------------------------------------------*/
    /*--------------Nama : Ahmad Ariful Amri----------------------*/
    /*--------------Program: Membaca File dalam pemrograman java----*/
    /*----------------visit: go-program.blogspot.com----------------*/
    /*--------------------------------------------------------------*/

    import java.io.*;

    class BacaFile
    {
    public static void main(String args[])
    {
    try
    {
    //Membuka sebuah file
    FileInputStream fstream = new FileInputStream("input.txt");
    DataInputStream in = new DataInputStream(fstream);

    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;

    //Membaca File baris perbaris
    while((strLine = br.readLine()) != null)
    {
    System.out.println(strLine);
    }

    in.close();
    }

    catch(Exception e)
    {
    System.err.println("Error: "+ e.getMessage());
    }
    }
    }

    Sebelum menjalankan program diatas, sebelumnya siapkanlah sebuah file txt yang akan dibaca, pada program diatas menggunakan file "input.txt".

    semoga tutorial diatas bisa bermanfaat ya.

    Kamis, 22 November 2012

    Ada tugas praktikm Untuk membuat sebuah program sederhana, dimana ada sebuah class contohnya class Biodata yang memiliki variabel Nama, Nim, Jurusan yang bertipe string, nantinya class tersebut di panggil ke dalam classnya Mahasiswa. Sehingga nantinya diclass Mahasiswa tersebut akan dipanggil classnya si Biodata.
    Ada tugas praktikm Untuk membuat sebuah program sederhana, dimana ada sebuah class contohnya class Biodata yang memiliki variabel Nama, Nim, Jurusan yang bertipe string, nantinya class tersebut di panggil ke dalam classnya Mahasiswa. Sehingga nantinya diclass Mahasiswa tersebut akan dipanggil classnya si Biodata.  contoh ilustrasinya seberti ini(Outputnya):  ----------Isi Form Berikut ini ----------- Nama    : (User input) NIM     : (User input) Jurusan : (User input)  ----------Data yang (Nama yang diinput) Masukkan ------- Nama    : Ahmad Ariful Amri NIM     : 11081#$#%*&#@ Jurusan : Informatika  Kira-kira begitulah outputnya, sederhana dan gampang sekali bukan? Berikut ini source code program diatas yang terdiri dari class Input dan class Mahasiswa.  1. Class Input (Input.java) class Input {  String nama,nim,jurusan; }  2. Class Mahasiswa (Mahasiswa.java) import java.util.*;  public class Mahasiswa {     public static void main(String args[])     {                  Input data= new Input();         System.out.println("------------Isi Biodata mu dibawah ini----------");         System.out.print("Nama   t: ");         Scanner in = new Scanner(System.in);         data.nama = in.nextLine();         System.out.print("NIM    t: ");         data.nim = in.nextLine();         System.out.print("Jurusan : ");         data.jurusan = in.nextLine();                  System.out.println("n-----Biodata Yang " +data.nama +" isi adalah-----");         System.out.println("Nama anda t : " +data.nama);         System.out.println("NIM anda  t : " +data.nim);         System.out.println("Jurusan Anda     : " +data.jurusan);     } }   Selesai, Sekarang coba aja dijalanin.

    contoh ilustrasinya seberti ini(Outputnya):

    ----------Isi Form Berikut ini -----------
    Nama    : (User input)
    NIM     : (User input)
    Jurusan : (User input)

    ----------Data yang (Nama yang diinput) Masukkan -------
    Nama    : Ahmad Ariful Amri
    NIM     : 11081#$#%*&#@
    Jurusan : Informatika

    Kira-kira begitulah outputnya, sederhana dan gampang sekali bukan? Berikut ini source code program diatas yang terdiri dari class Input dan class Mahasiswa.

    1. Class Input (Input.java)
    class Input
    {
    String nama,nim,jurusan;
    }

    2. Class Mahasiswa (Mahasiswa.java)
    import java.util.*;

    public class Mahasiswa
    {
    public static void main(String args[])
    {

    Input data= new Input();
    System.out.println("------------Isi Biodata mu dibawah ini----------");
    System.out.print("Nama \t: ");
    Scanner in = new Scanner(System.in);
    data.nama = in.nextLine();
    System.out.print("NIM \t: ");
    data.nim = in.nextLine();
    System.out.print("Jurusan : ");
    data.jurusan = in.nextLine();

    System.out.println("n-----Biodata Yang " +data.nama +" isi adalah-----");
    System.out.println("Nama anda \t : " +data.nama);
    System.out.println("NIM anda \t : " +data.nim);
    System.out.println("Jurusan Anda : " +data.jurusan);
    }
    }


    Selesai, Sekarang coba aja dijalanin.

    Selasa, 20 November 2012

    Contoh Soal Latihan Quiz Pemrograman Java
    Haha, Mungkin judul diatas agak Extrim gimana gitu, mohon dimaklumi ya, judulnya agak ekstrim gitu karena saya sedang nembak keyword, biasanya ada yang cari Contoh soal pemrograman Java, atau Quiz latihan Pemrograman Java, atau lain sebagainya, jadi dengan begitu akan banyak masuk kedalam Listnya pencarian google, gitu.. tapi mungkin soal SEO nya masih kurang ya blog ini. Tapi gapapa, toh nulis ini juga karena Hobi.

    Well, berikut ini ada beberapa contoh soal Latihan Kuis Pemrograman menggunakan bahasa Java, setidaknya bisa dijadikan bahan belajar seblum ujian, atau mungkin cuma iseng ngerjain soal aja. Semoga contoh soal berikut ini bisa bermanfaat. :)


    1. Apa output/keluaran apabila anda menjalankan kode berikut ini

    public class Soal1
    {
    static int x=(int) (2*7%3+21-11/2);
    static double y=(int) (2*7%3+21-11/2);
    public static void main(String args[])
    {
    System.out.println(y/x);
    }
    }

    2. Apa output/keluaran apabila anda menjalankan kode berikut ini
    public class Soal2
    {
    public static void main(String args[])
    {
    int i=0;
    for( ; i<=9;)
    {
    if(i % 3 == 0)
    {
    System.out.println();
    }
    System.out.println(" " +(++i));
    }
    System.out.print(" " + i);
    }
    }

    3. Apa output/keluaran apabila anda menjalankan kode berikut ini
    public class Soal3
    {
    public static void main(String args[])
    {
    int [] [] x ={ {1,2}, {2,4,6}, {3,6,9,12}, {4,8,12,16} };

    for (int i=0; i<x.length; i++)
    {
    for(int j=0; j<x[i].length; j++)
    {
    if(x[i][j] % 2 == 1)
    {
    System.out.println(" " + x[i][j]);
    }
    }
    System.out.println("");
    }
    }
    }

    4. Apa output/keluaran dari program berikut ini
    public class Soal4
    {
    public static void main(String args[])
    {
    String s1 = "contoh "+"Soal "+"dan "+"Kuis "+"Pemrograman "+"javan";
    String s2 = "kunjungi "+" go"+"-Program";
    String s3 = ".blogspot"+".com";
    System.out.println(s1+s2+s3);
    }
    }

    5. Apa output/keluaran dari program berikut ini
    public class Soal5
    {
    protected static String name;
    private static String address;
    public Soal5()
    {
    address = "Banda Aceh";
    }

    static String getName()
    {
    return name;
    }

    public void setName( String temp )
    {
    name = temp;
    }

    public static void main(String args[])
    {
    String s1="Ahmad "+"Ariful ";
    Soal5 s5= new Soal5();
    s5.setName("Amri");
    System.out.println(s1+s5.getName());
    System.out.println(address);
    }
    }

    6. Buatlah sebuah program dalam bahasapemrograman java yang dapat mencetak semua bilangan kelipatan 3, tetapi bukan kelipatan 2 dan 5 yang lebih kecil atau sa dengan bilangan n, dimana 2< n <=100000.

    Nah soalnya hanya 6 saja, bagaimana ? Ayo dikerjakan, dan hasilnya kalau mau boleh juga ke emailnya admin di ahmad.ariful@s1.informatika.unsyiah.ac.id