Chat Box

User Yang Sedang Online
Total 1 user online :: 0 Terdaftar, 0 Tersembunyi dan 1 Tamu

Tidak ada

[ View the whole list ]


User online terbanyak adalah 24 pada Mon Oct 04, 2010 10:03 am
Total Pengunjung
Website counter
Visitor

Source Code Ular Tangga

Topik sebelumnya Topik selanjutnya Go down

default Source Code Ular Tangga

Post by risdo on Sun Apr 11, 2010 3:34 am

Ini program ular tangga dari kelompok gw (echa,dudhy,azzhari) berhubung klo di tulis semua gak muat jd gw pecah jd 2 bagian ya.. nnti tinggal di gabung aja.


Part1
Spoiler:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.*;
import javax.swing.KeyStroke;
import static java.awt.event.InputEvent.*;
import java.io.*;
import java.util.*;


class UlarTangga extends JFrame implements ActionListener {

int posP1=1;
int posP2=1;

String nmp1;
String nmp2;
int turn=1;
public static int dc;
public static Boolean stp=false;

JFileChooser jfc = new JFileChooser(".");

// panggil image
ImageIcon jdl[] = { new ImageIcon("img/ular.png"), new ImageIcon("img/tangga.png") };
public static ImageIcon dadu[] = { new ImageIcon("img/1.jpg"), new ImageIcon("img/2.jpg"), new ImageIcon("img/3.jpg"), new ImageIcon("img/4.jpg"), new ImageIcon("img/5.jpg"), new ImageIcon("img/6.jpg") };

// image papan kosong
ImageIcon PapanB1[] = { new ImageIcon("papan/1.gif"), new ImageIcon("papan/2.gif"), new ImageIcon("papan/3.gif"), new ImageIcon("papan/4.gif"), new ImageIcon("papan/5.gif"), new ImageIcon("papan/6.gif"), new ImageIcon("papan/7.gif"), new ImageIcon("papan/8.gif"), new ImageIcon("papan/9.gif"), new ImageIcon("papan/10.gif") };
ImageIcon PapanB2[] = { new ImageIcon("papan/20.gif"), new ImageIcon("papan/19.gif"), new ImageIcon("papan/18.gif"), new ImageIcon("papan/17.gif"), new ImageIcon("papan/16.gif"), new ImageIcon("papan/15.gif"), new ImageIcon("papan/14.gif"), new ImageIcon("papan/13.gif"), new ImageIcon("papan/12.gif"), new ImageIcon("papan/11.gif") };
ImageIcon PapanB3[] = { new ImageIcon("papan/21.gif"), new ImageIcon("papan/22.gif"), new ImageIcon("papan/23.gif"), new ImageIcon("papan/24.gif"), new ImageIcon("papan/25.gif"), new ImageIcon("papan/26.gif"), new ImageIcon("papan/27.gif"), new ImageIcon("papan/28.gif"), new ImageIcon("papan/29.gif"), new ImageIcon("papan/30.gif") };
ImageIcon PapanB4[] = { new ImageIcon("papan/40.gif"), new ImageIcon("papan/39.gif"), new ImageIcon("papan/38.gif"), new ImageIcon("papan/37.gif"), new ImageIcon("papan/36.gif"), new ImageIcon("papan/35.gif"), new ImageIcon("papan/34.gif"), new ImageIcon("papan/33.gif"), new ImageIcon("papan/32.gif"), new ImageIcon("papan/31.gif") };
ImageIcon PapanB5[] = { new ImageIcon("papan/41.gif"), new ImageIcon("papan/42.gif"), new ImageIcon("papan/43.gif"), new ImageIcon("papan/44.gif"), new ImageIcon("papan/45.gif"), new ImageIcon("papan/46.gif"), new ImageIcon("papan/47.gif"), new ImageIcon("papan/48.gif"), new ImageIcon("papan/49.gif"), new ImageIcon("papan/50.gif") };

ImageIcon PapanB6[] = { new ImageIcon("papan/60.gif"), new ImageIcon("papan/59.gif"), new ImageIcon("papan/58.gif"), new ImageIcon("papan/57.gif"), new ImageIcon("papan/56.gif"), new ImageIcon("papan/55.gif"), new ImageIcon("papan/54.gif"), new ImageIcon("papan/53.gif"), new ImageIcon("papan/52.gif"), new ImageIcon("papan/51.gif") };
ImageIcon PapanB7[] = { new ImageIcon("papan/61.gif"), new ImageIcon("papan/62.gif"), new ImageIcon("papan/63.gif"), new ImageIcon("papan/64.gif"), new ImageIcon("papan/65.gif"), new ImageIcon("papan/66.gif"), new ImageIcon("papan/67.gif"), new ImageIcon("papan/68.gif"), new ImageIcon("papan/69.gif"), new ImageIcon("papan/70.gif") };
ImageIcon PapanB8[] = { new ImageIcon("papan/80.gif"), new ImageIcon("papan/79.gif"), new ImageIcon("papan/78.gif"), new ImageIcon("papan/77.gif"), new ImageIcon("papan/76.gif"), new ImageIcon("papan/75.gif"), new ImageIcon("papan/74.gif"), new ImageIcon("papan/73.gif"), new ImageIcon("papan/72.gif"), new ImageIcon("papan/71.gif") };
ImageIcon PapanB9[] = { new ImageIcon("papan/81.gif"), new ImageIcon("papan/82.gif"), new ImageIcon("papan/83.gif"), new ImageIcon("papan/84.gif"), new ImageIcon("papan/85.gif"), new ImageIcon("papan/86.gif"), new ImageIcon("papan/87.gif"), new ImageIcon("papan/88.gif"), new ImageIcon("papan/89.gif"), new ImageIcon("papan/90.gif") };
ImageIcon PapanB10[] = { new ImageIcon("papan/100.gif"), new ImageIcon("papan/99.gif"), new ImageIcon("papan/98.gif"), new ImageIcon("papan/97.gif"), new ImageIcon("papan/96.gif"), new ImageIcon("papan/95.gif"), new ImageIcon("papan/94.gif"), new ImageIcon("papan/93.gif"), new ImageIcon("papan/92.gif"), new ImageIcon("papan/91.gif") };

// image papan diletaki P1
ImageIcon PapanP1B1[] = { new ImageIcon("papanP1/1.gif"), new ImageIcon("papanP1/2.gif"), new ImageIcon("papanP1/3.gif"), new ImageIcon("papanP1/4.gif"), new ImageIcon("papanP1/5.gif"), new ImageIcon("papanP1/6.gif"), new ImageIcon("papanP1/7.gif"), new ImageIcon("papanP1/8.gif"), new ImageIcon("papanP1/9.gif"), new ImageIcon("papanP1/10.gif") };
ImageIcon PapanP1B2[] = { new ImageIcon("papanP1/20.gif"), new ImageIcon("papanP1/19.gif"), new ImageIcon("papanP1/18.gif"), new ImageIcon("papanP1/17.gif"), new ImageIcon("papanP1/16.gif"), new ImageIcon("papanP1/15.gif"), new ImageIcon("papanP1/14.gif"), new ImageIcon("papanP1/13.gif"), new ImageIcon("papanP1/12.gif"), new ImageIcon("papanP1/11.gif") };
ImageIcon PapanP1B3[] = { new ImageIcon("papanP1/21.gif"), new ImageIcon("papanP1/22.gif"), new ImageIcon("papanP1/23.gif"), new ImageIcon("papanP1/24.gif"), new ImageIcon("papanP1/25.gif"), new ImageIcon("papanP1/26.gif"), new ImageIcon("papanP1/27.gif"), new ImageIcon("papanP1/28.gif"), new ImageIcon("papanP1/29.gif"), new ImageIcon("papanP1/30.gif") };
ImageIcon PapanP1B4[] = { new ImageIcon("papanP1/40.gif"), new ImageIcon("papanP1/39.gif"), new ImageIcon("papanP1/38.gif"), new ImageIcon("papanP1/37.gif"), new ImageIcon("papanP1/36.gif"), new ImageIcon("papanP1/35.gif"), new ImageIcon("papanP1/34.gif"), new ImageIcon("papanP1/33.gif"), new ImageIcon("papanP1/32.gif"), new ImageIcon("papanP1/31.gif") };
ImageIcon PapanP1B5[] = { new ImageIcon("papanP1/41.gif"), new ImageIcon("papanP1/42.gif"), new ImageIcon("papanP1/43.gif"), new ImageIcon("papanP1/44.gif"), new ImageIcon("papanP1/45.gif"), new ImageIcon("papanP1/46.gif"), new ImageIcon("papanP1/47.gif"), new ImageIcon("papanP1/48.gif"), new ImageIcon("papanP1/49.gif"), new ImageIcon("papanP1/50.gif") };

ImageIcon PapanP1B6[] = { new ImageIcon("papanP1/60.gif"), new ImageIcon("papanP1/59.gif"), new ImageIcon("papanP1/58.gif"), new ImageIcon("papanP1/57.gif"), new ImageIcon("papanP1/56.gif"), new ImageIcon("papanP1/55.gif"), new ImageIcon("papanP1/54.gif"), new ImageIcon("papanP1/53.gif"), new ImageIcon("papanP1/52.gif"), new ImageIcon("papanP1/51.gif") };
ImageIcon PapanP1B7[] = { new ImageIcon("papanP1/61.gif"), new ImageIcon("papanP1/62.gif"), new ImageIcon("papanP1/63.gif"), new ImageIcon("papanP1/64.gif"), new ImageIcon("papanP1/65.gif"), new ImageIcon("papanP1/66.gif"), new ImageIcon("papanP1/67.gif"), new ImageIcon("papanP1/68.gif"), new ImageIcon("papanP1/69.gif"), new ImageIcon("papanP1/70.gif") };
ImageIcon PapanP1B8[] = { new ImageIcon("papanP1/80.gif"), new ImageIcon("papanP1/79.gif"), new ImageIcon("papanP1/78.gif"), new ImageIcon("papanP1/77.gif"), new ImageIcon("papanP1/76.gif"), new ImageIcon("papanP1/75.gif"), new ImageIcon("papanP1/74.gif"), new ImageIcon("papanP1/73.gif"), new ImageIcon("papanP1/72.gif"), new ImageIcon("papanP1/71.gif") };
ImageIcon PapanP1B9[] = { new ImageIcon("papanP1/81.gif"), new ImageIcon("papanP1/82.gif"), new ImageIcon("papanP1/83.gif"), new ImageIcon("papanP1/84.gif"), new ImageIcon("papanP1/85.gif"), new ImageIcon("papanP1/86.gif"), new ImageIcon("papanP1/87.gif"), new ImageIcon("papanP1/88.gif"), new ImageIcon("papanP1/89.gif"), new ImageIcon("papanP1/90.gif") };
ImageIcon PapanP1B10[] = { new ImageIcon("papanP1/100.gif"), new ImageIcon("papanP1/99.gif"), new ImageIcon("papanP1/98.gif"), new ImageIcon("papanP1/97.gif"), new ImageIcon("papanP1/96.gif"), new ImageIcon("papanP1/95.gif"), new ImageIcon("papanP1/94.gif"), new ImageIcon("papanP1/93.gif"), new ImageIcon("papanP1/92.gif"), new ImageIcon("papanP1/91.gif") };

// image papan diletaki P2
ImageIcon PapanP2B1[] = { new ImageIcon("papanP2/1.gif"), new ImageIcon("papanP2/2.gif"), new ImageIcon("papanP2/3.gif"), new ImageIcon("papanP2/4.gif"), new ImageIcon("papanP2/5.gif"), new ImageIcon("papanP2/6.gif"), new ImageIcon("papanP2/7.gif"), new ImageIcon("papanP2/8.gif"), new ImageIcon("papanP2/9.gif"), new ImageIcon("papanP2/10.gif") };
ImageIcon PapanP2B2[] = { new ImageIcon("papanP2/20.gif"), new ImageIcon("papanP2/19.gif"), new ImageIcon("papanP2/18.gif"), new ImageIcon("papanP2/17.gif"), new ImageIcon("papanP2/16.gif"), new ImageIcon("papanP2/15.gif"), new ImageIcon("papanP2/14.gif"), new ImageIcon("papanP2/13.gif"), new ImageIcon("papanP2/12.gif"), new ImageIcon("papanP2/11.gif") };
ImageIcon PapanP2B3[] = { new ImageIcon("papanP2/21.gif"), new ImageIcon("papanP2/22.gif"), new ImageIcon("papanP2/23.gif"), new ImageIcon("papanP2/24.gif"), new ImageIcon("papanP2/25.gif"), new ImageIcon("papanP2/26.gif"), new ImageIcon("papanP2/27.gif"), new ImageIcon("papanP2/28.gif"), new ImageIcon("papanP2/29.gif"), new ImageIcon("papanP2/30.gif") };
ImageIcon PapanP2B4[] = { new ImageIcon("papanP2/40.gif"), new ImageIcon("papanP2/39.gif"), new ImageIcon("papanP2/38.gif"), new ImageIcon("papanP2/37.gif"), new ImageIcon("papanP2/36.gif"), new ImageIcon("papanP2/35.gif"), new ImageIcon("papanP2/34.gif"), new ImageIcon("papanP2/33.gif"), new ImageIcon("papanP2/32.gif"), new ImageIcon("papanP2/31.gif") };
ImageIcon PapanP2B5[] = { new ImageIcon("papanP2/41.gif"), new ImageIcon("papanP2/42.gif"), new ImageIcon("papanP2/43.gif"), new ImageIcon("papanP2/44.gif"), new ImageIcon("papanP2/45.gif"), new ImageIcon("papanP2/46.gif"), new ImageIcon("papanP2/47.gif"), new ImageIcon("papanP2/48.gif"), new ImageIcon("papanP2/49.gif"), new ImageIcon("papanP2/50.gif") };

ImageIcon PapanP2B6[] = { new ImageIcon("papanP2/60.gif"), new ImageIcon("papanP2/59.gif"), new ImageIcon("papanP2/58.gif"), new ImageIcon("papanP2/57.gif"), new ImageIcon("papanP2/56.gif"), new ImageIcon("papanP2/55.gif"), new ImageIcon("papanP2/54.gif"), new ImageIcon("papanP2/53.gif"), new ImageIcon("papanP2/52.gif"), new ImageIcon("papanP2/51.gif") };
ImageIcon PapanP2B7[] = { new ImageIcon("papanP2/61.gif"), new ImageIcon("papanP2/62.gif"), new ImageIcon("papanP2/63.gif"), new ImageIcon("papanP2/64.gif"), new ImageIcon("papanP2/65.gif"), new ImageIcon("papanP2/66.gif"), new ImageIcon("papanP2/67.gif"), new ImageIcon("papanP2/68.gif"), new ImageIcon("papanP2/69.gif"), new ImageIcon("papanP2/70.gif") };
ImageIcon PapanP2B8[] = { new ImageIcon("papanP2/80.gif"), new ImageIcon("papanP2/79.gif"), new ImageIcon("papanP2/78.gif"), new ImageIcon("papanP2/77.gif"), new ImageIcon("papanP2/76.gif"), new ImageIcon("papanP2/75.gif"), new ImageIcon("papanP2/74.gif"), new ImageIcon("papanP2/73.gif"), new ImageIcon("papanP2/72.gif"), new ImageIcon("papanP2/71.gif") };
ImageIcon PapanP2B9[] = { new ImageIcon("papanP2/81.gif"), new ImageIcon("papanP2/82.gif"), new ImageIcon("papanP2/83.gif"), new ImageIcon("papanP2/84.gif"), new ImageIcon("papanP2/85.gif"), new ImageIcon("papanP2/86.gif"), new ImageIcon("papanP2/87.gif"), new ImageIcon("papanP2/88.gif"), new ImageIcon("papanP2/89.gif"), new ImageIcon("papanP2/90.gif") };
ImageIcon PapanP2B10[] = { new ImageIcon("papanP2/100.gif"), new ImageIcon("papanP2/99.gif"), new ImageIcon("papanP2/98.gif"), new ImageIcon("papanP2/97.gif"), new ImageIcon("papanP2/96.gif"), new ImageIcon("papanP2/95.gif"), new ImageIcon("papanP2/94.gif"), new ImageIcon("papanP2/93.gif"), new ImageIcon("papanP2/92.gif"), new ImageIcon("papanP2/91.gif") };

// image papak diletaki P1 dan P2
ImageIcon PapanP1P2B1[] = { new ImageIcon("papanP1P2/1.gif"), new ImageIcon("papanP1P2/2.gif"), new ImageIcon("papanP1P2/3.gif"), new ImageIcon("papanP1P2/4.gif"), new ImageIcon("papanP1P2/5.gif"), new ImageIcon("papanP1P2/6.gif"), new ImageIcon("papanP1P2/7.gif"), new ImageIcon("papanP1P2/8.gif"), new ImageIcon("papanP1P2/9.gif"), new ImageIcon("papanP1P2/10.gif") };
ImageIcon PapanP1P2B2[] = { new ImageIcon("papanP1P2/20.gif"), new ImageIcon("papanP1P2/19.gif"), new ImageIcon("papanP1P2/18.gif"), new ImageIcon("papanP1P2/17.gif"), new ImageIcon("papanP1P2/16.gif"), new ImageIcon("papanP1P2/15.gif"), new ImageIcon("papanP1P2/14.gif"), new ImageIcon("papanP1P2/13.gif"), new ImageIcon("papanP1P2/12.gif"), new ImageIcon("papanP1P2/11.gif") };
ImageIcon PapanP1P2B3[] = { new ImageIcon("papanP1P2/21.gif"), new ImageIcon("papanP1P2/22.gif"), new ImageIcon("papanP1P2/23.gif"), new ImageIcon("papanP1P2/24.gif"), new ImageIcon("papanP1P2/25.gif"), new ImageIcon("papanP1P2/26.gif"), new ImageIcon("papanP1P2/27.gif"), new ImageIcon("papanP1P2/28.gif"), new ImageIcon("papanP1P2/29.gif"), new ImageIcon("papanP1P2/30.gif") };
ImageIcon PapanP1P2B4[] = { new ImageIcon("papanP1P2/40.gif"), new ImageIcon("papanP1P2/39.gif"), new ImageIcon("papanP1P2/38.gif"), new ImageIcon("papanP1P2/37.gif"), new ImageIcon("papanP1P2/36.gif"), new ImageIcon("papanP1P2/35.gif"), new ImageIcon("papanP1P2/34.gif"), new ImageIcon("papanP1P2/33.gif"), new ImageIcon("papanP1P2/32.gif"), new ImageIcon("papanP1P2/31.gif") };
ImageIcon PapanP1P2B5[] = { new ImageIcon("papanP1P2/41.gif"), new ImageIcon("papanP1P2/42.gif"), new ImageIcon("papanP1P2/43.gif"), new ImageIcon("papanP1P2/44.gif"), new ImageIcon("papanP1P2/45.gif"), new ImageIcon("papanP1P2/46.gif"), new ImageIcon("papanP1P2/47.gif"), new ImageIcon("papanP1P2/48.gif"), new ImageIcon("papanP1P2/49.gif"), new ImageIcon("papanP1P2/50.gif") };

ImageIcon PapanP1P2B6[] = { new ImageIcon("papanP1P2/60.gif"), new ImageIcon("papanP1P2/59.gif"), new ImageIcon("papanP1P2/58.gif"), new ImageIcon("papanP1P2/57.gif"), new ImageIcon("papanP1P2/56.gif"), new ImageIcon("papanP1P2/55.gif"), new ImageIcon("papanP1P2/54.gif"), new ImageIcon("papanP1P2/53.gif"), new ImageIcon("papanP1P2/52.gif"), new ImageIcon("papanP1P2/51.gif") };
ImageIcon PapanP1P2B7[] = { new ImageIcon("papanP1P2/61.gif"), new ImageIcon("papanP1P2/62.gif"), new ImageIcon("papanP1P2/63.gif"), new ImageIcon("papanP1P2/64.gif"), new ImageIcon("papanP1P2/65.gif"), new ImageIcon("papanP1P2/66.gif"), new ImageIcon("papanP1P2/67.gif"), new ImageIcon("papanP1P2/68.gif"), new ImageIcon("papanP1P2/69.gif"), new ImageIcon("papanP1P2/70.gif") };
ImageIcon PapanP1P2B8[] = { new ImageIcon("papanP1P2/80.gif"), new ImageIcon("papanP1P2/79.gif"), new ImageIcon("papanP1P2/78.gif"), new ImageIcon("papanP1P2/77.gif"), new ImageIcon("papanP1P2/76.gif"), new ImageIcon("papanP1P2/75.gif"), new ImageIcon("papanP1P2/74.gif"), new ImageIcon("papanP1P2/73.gif"), new ImageIcon("papanP1P2/72.gif"), new ImageIcon("papanP1P2/71.gif") };
ImageIcon PapanP1P2B9[] = { new ImageIcon("papanP1P2/81.gif"), new ImageIcon("papanP1P2/82.gif"), new ImageIcon("papanP1P2/83.gif"), new ImageIcon("papanP1P2/84.gif"), new ImageIcon("papanP1P2/85.gif"), new ImageIcon("papanP1P2/86.gif"), new ImageIcon("papanP1P2/87.gif"), new ImageIcon("papanP1P2/88.gif"), new ImageIcon("papanP1P2/89.gif"), new ImageIcon("papanP1P2/90.gif") };
ImageIcon PapanP1P2B10[] = { new ImageIcon("papanP1P2/100.gif"), new ImageIcon("papanP1P2/99.gif"), new ImageIcon("papanP1P2/98.gif"), new ImageIcon("papanP1P2/97.gif"), new ImageIcon("papanP1P2/96.gif"), new ImageIcon("papanP1P2/95.gif"), new ImageIcon("papanP1P2/94.gif"), new ImageIcon("papanP1P2/93.gif"), new ImageIcon("papanP1P2/92.gif"), new ImageIcon("papanP1P2/91.gif") };

ImageIcon P1 = new ImageIcon("img/P1.gif");
ImageIcon P2 = new ImageIcon("img/P2.gif");

ImageIcon hati1 = new ImageIcon("img/greenheart.gif");
ImageIcon hati2 = new ImageIcon("img/redheart.gif");

// pesen object buttonnya

JButton btnGo = new JButton("Go");
JButton btnStop = new JButton("Stop");

// pesen object menu bar

JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenu helpMenu = new JMenu("Help");
JMenuItem menuNew = new JMenuItem("New Game");
JMenuItem menuOpen = new JMenuItem("Open");
JMenuItem menuSave = new JMenuItem("Save");
JMenuItem menuExit = new JMenuItem("Exit");
JMenuItem menuHelp = new JMenuItem("How to Play");
JMenuItem menuAbout = new JMenuItem("About");

// pembuatan container
Container c = getContentPane();

// pembuatan label2 yang digunakan bwat masukin image ke object
JLabel lUlar = new JLabel(jdl[0]);
JLabel lTangga = new JLabel(jdl[1]);
public static JLabel dice = new JLabel();
JLabel lArrPapan[][] = new JLabel[10][10];

JLabel p1 = new JLabel(P1);
JLabel p2 = new JLabel(P2);

JLabel name1;
JLabel name2;

JLabel h1 = new JLabel();
JLabel h2 = new JLabel();

// pembuatan panel-panel

JPanel pNorth = new JPanel();
JPanel pJudul = new JPanel();

JPanel pCenter = new JPanel();
JPanel pPapan = new JPanel();

JPanel pDadu = new JPanel();
JPanel pButton = new JPanel();
JPanel pInButton = new JPanel();

JPanel pHati1 = new JPanel();
JPanel pHati2 = new JPanel();

JPanel pP1name = new JPanel();
JPanel pP2name = new JPanel();

JPanel pP1pic = new JPanel();
JPanel pP2pic = new JPanel();

// constructor
UlarTangga(int t,String player1,String player2,int posisiP1,int posisiP2,Boolean tanda,int jalan,Boolean open) {
setTitle("Vanessa �");

http://c.setLayout(new BorderLayout());
c.setLayout(null);

// bwat menu bar...
setJMenuBar(menuBar);
menuBar.add(fileMenu);
menuBar.add(helpMenu);

fileMenu.add(menuNew);
fileMenu.add(menuOpen);
fileMenu.add(menuSave);
fileMenu.add(menuExit);

helpMenu.add(menuHelp);
helpMenu.add(menuAbout);

//buat shortcut menu
fileMenu.setMnemonic('F');
helpMenu.setMnemonic('H');

menuNew.setAccelerator(KeyStroke.getKeyStroke('N', CTRL_DOWN_MASK ));
menuOpen.setAccelerator(KeyStroke.getKeyStroke('O', CTRL_DOWN_MASK ));
menuSave.setAccelerator(KeyStroke.getKeyStroke('S', CTRL_DOWN_MASK ));

// pesen action listener
menuNew.addActionListener(this);
menuOpen.addActionListener(this);
menuSave.addActionListener(this);
menuExit.addActionListener(this);

menuHelp.addActionListener(this);
menuAbout.addActionListener(this);

btnGo.addActionListener(this);
btnStop.addActionListener(this);

// masukin panel-panel yang udah dibuat
// panel papan
pCenter.setBounds(10,70,460,470);
pCenter.add(pPapan);
pPapan.setLayout(new GridLayout(10,10));

for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
Dimension imgSize = new Dimension(46,46);

if(i==9) { lArrPapan[i][j] = new JLabel(PapanB1[j]); }
else if(i==Cool { lArrPapan[i][j] = new JLabel(PapanB2[j]); }
else if(i==7) { lArrPapan[i][j] = new JLabel(PapanB3[j]); }
else if(i==6) { lArrPapan[i][j] = new JLabel(PapanB4[j]); }
else if(i==5) { lArrPapan[i][j] = new JLabel(PapanB5[j]); }

else if(i==4) { lArrPapan[i][j] = new JLabel(PapanB6[j]); }
else if(i==3) { lArrPapan[i][j] = new JLabel(PapanB7[j]); }
else if(i==2) { lArrPapan[i][j] = new JLabel(PapanB8[j]); }
else if(i==1) { lArrPapan[i][j] = new JLabel(PapanB9[j]); }
else if(i==0) { lArrPapan[i][j] = new JLabel(PapanB10[j]); }

lArrPapan[i][j].setPreferredSize(imgSize);
lArrPapan[i][j].setBorder(BorderFactory.createEtchedBorder(Color.RED,null));

pPapan.add(lArrPapan[i][j]);

}
}

if(tanda==true && open==false) { lArrPapan[9][0].setIcon(PapanP1P2B1[0]); }
if(open==true) { new RUN(posisiP1,posisiP2,true); }

c.add(pCenter,"North");


// panel dadu
Dimension diceSize = new Dimension(110,110);
pDadu.setBounds(490,80,122,122);
dice.setIcon(dadu[0]);
dice.setPreferredSize(diceSize);
pDadu.add(dice);
pDadu.setBorder(BorderFactory.createEtchedBorder(Color.BLACK,Color.BLACK));
c.add(pDadu,"North");

// panel player pic
pP1pic.setBounds(490,250,30,30);
pP1pic.add(p1);
c.add(pP1pic,"North");

pP2pic.setBounds(490,280,30,30);
pP2pic.add(p2);
c.add(pP2pic,"North");

// panel hati pic
pHati1.setBounds(600,253,25,25);
h1.setIcon(hati1);
pHati1.add(h1);
c.add(pHati1,"North");

pHati2.setBounds(600,283,25,25);
h2.setIcon(hati2);
pHati2.add(h2);
c.add(pHati2,"North");

// panel nama player - > akan tampil bila sudah di imput
name1 = new JLabel(player1);
pP1name.setBounds(525,253,65,30);
pP1name.add(name1);
c.add(pP1name,"EAST");

name2 = new JLabel(player2);
pP2name.setBounds(525,283,65,30);
pP2name.add(name2);
c.add(pP2name,"EAST");

// simpan nama player ke variabel global
nmp1=player1;
nmp2=player2;

// panel button

pButton.setBounds(490,200,125,125);
pButton.add(pInButton);
// pake gridbag layout
GridBagLayout gridbag = new GridBagLayout(); // create a layout manager
GridBagConstraints constraints = new GridBagConstraints();
pInButton.setLayout(gridbag);

constraints.ipadx = 70;
constraints.gridwidth = 2;
constraints.gridheight = 2;
gridbag.setConstraints(btnGo, constraints); // set the constraints
pInButton.add(btnGo); // add button to content pane


constraints.ipadx = 60;
constraints.gridx = 1;
constraints.gridy = 1;
constraints.gridwidth = 2;
constraints.gridheight = 2;
gridbag.setConstraints(btnStop, constraints);
pInButton.add(btnStop);

c.add(pButton,"North");

if(t==0) { btnGo.setEnabled(false); btnStop.setVisible(false); }


// panel judul

pNorth.setBounds(10, 0, 650, 100); // x position,y position, lebar, panjang
pNorth.add(pJudul);
pJudul.setLayout(new GridLayout(1,2));
pJudul.add(lUlar);
pJudul.add(lTangga);

c.add(pNorth,"North");



setSize(650,600);
setResizable(false);
setVisible(true);
show();
//pack();
setDefaultCloseOperation(3);

}


Terakhir diubah oleh risdo tanggal Sun Apr 18, 2010 1:41 am, total 1 kali diubah
avatar
risdo
Admin
Admin

Posts : 209
Reputasi : 377
Cendol : 1
Join date : 26.10.09
Location : Bekasi

Lihat profil user http://c0b4d1b4c4.indonesianforum.net

Kembali Ke Atas Go down

default Re: Source Code Ular Tangga

Post by risdo on Sun Apr 11, 2010 3:43 am

Ular Tangga Part 2
[spoiler]
//-----------------------------------------------------------------------VOID RUN
public class RUN {

RUN(int posisiP1,int posisiP2,Boolean tanda) {

if(tanda==true) {
if(posisiP1==posisiP2) {
if(posisiP1<=10) { lArrPapan[9][posisiP1-1].setIcon(PapanP1P2B1[posisiP1-1]); }
else if(posisiP1<=20) { if(posisiP1%10 == 0){ lArrPapan[8][0].setIcon(PapanP1P2B2[0]); } else { lArrPapan[8][10-(posisiP1%10)].setIcon(PapanP1P2B2[10-(posisiP1%10)]); } }
else if(posisiP1<=30) { if(posisiP1%10 == 0){ lArrPapan[7][9].setIcon(PapanP1P2B3[9]); } else { lArrPapan[7][(posisiP1%10)-1].setIcon(PapanP1P2B3[(posisiP1%10)-1]); } }
else if(posisiP1<=40) { if(posisiP1%10 == 0){ lArrPapan[6][0].setIcon(PapanP1P2B4[0]); } else { lArrPapan[6][10-(posisiP1%10)].setIcon(PapanP1P2B4[10-(posisiP1%10)]); } }
else if(posisiP1<=50) { if(posisiP1%10 == 0){ lArrPapan[5][9].setIcon(PapanP1P2B5[9]); } else { lArrPapan[5][(posisiP1%10)-1].setIcon(PapanP1P2B5[(posisiP1%10)-1]); } }

else if(posisiP1<=60) { if(posisiP1%10 == 0){ lArrPapan[4][0].setIcon(PapanP1P2B6[0]); } else { lArrPapan[4][10-(posisiP1%10)].setIcon(PapanP1P2B6[10-(posisiP1%10)]); } }
else if(posisiP1<=70) { if(posisiP1%10 == 0){ lArrPapan[3][9].setIcon(PapanP1P2B7[9]); } else { lArrPapan[3][(posisiP1%10)-1].setIcon(PapanP1P2B7[(posisiP1%10)-1]); } }
else if(posisiP1<=80) { if(posisiP1%10 == 0){ lArrPapan[2][0].setIcon(PapanP1P2B8[0]); } else { lArrPapan[2][10-(posisiP1%10)].setIcon(PapanP1P2B8[10-(posisiP1%10)]); } }
else if(posisiP1<=90) { if(posisiP1%10 == 0){ lArrPapan[1][9].setIcon(PapanP1P2B9[9]); } else { lArrPapan[1][(posisiP1%10)-1].setIcon(PapanP1P2B9[(posisiP1%10)-1]); } }
else if(posisiP1<=100){ if(posisiP1%10 == 0){ lArrPapan[0][0].setIcon(PapanP1P2B10[0]); } else { lArrPapan[0][10-(posisiP1%10)].setIcon(PapanP1P2B10[10-(posisiP1%10)]); } }
}
else {
//set posisi player 1 ke papan
if(posisiP1<=10) { lArrPapan[9][posisiP1-1].setIcon(PapanP1B1[posisiP1-1]); }
else if(posisiP1<=20) { if(posisiP1%10 == 0){ lArrPapan[8][0].setIcon(PapanP1B2[0]); } else { lArrPapan[8][10-(posisiP1%10)].setIcon(PapanP1B2[10-(posisiP1%10)]); } }
else if(posisiP1<=30) { if(posisiP1%10 == 0){ lArrPapan[7][9].setIcon(PapanP1B3[9]); } else { lArrPapan[7][(posisiP1%10)-1].setIcon(PapanP1B3[(posisiP1%10)-1]); } }
else if(posisiP1<=40) { if(posisiP1%10 == 0){ lArrPapan[6][0].setIcon(PapanP1B4[0]); } else { lArrPapan[6][10-(posisiP1%10)].setIcon(PapanP1B4[10-(posisiP1%10)]); } }
else if(posisiP1<=50) { if(posisiP1%10 == 0){ lArrPapan[5][9].setIcon(PapanP1B5[9]); } else { lArrPapan[5][(posisiP1%10)-1].setIcon(PapanP1B5[(posisiP1%10)-1]); } }

else if(posisiP1<=60) { if(posisiP1%10 == 0){ lArrPapan[4][0].setIcon(PapanP1B6[0]); } else { lArrPapan[4][10-(posisiP1%10)].setIcon(PapanP1B6[10-(posisiP1%10)]); } }
else if(posisiP1<=70) { if(posisiP1%10 == 0){ lArrPapan[3][9].setIcon(PapanP1B7[9]); } else { lArrPapan[3][(posisiP1%10)-1].setIcon(PapanP1B7[(posisiP1%10)-1]); } }
else if(posisiP1<=80) { if(posisiP1%10 == 0){ lArrPapan[2][0].setIcon(PapanP1B8[0]); } else { lArrPapan[2][10-(posisiP1%10)].setIcon(PapanP1B8[10-(posisiP1%10)]); } }
else if(posisiP1<=90) { if(posisiP1%10 == 0){ lArrPapan[1][9].setIcon(PapanP1B9[9]); } else { lArrPapan[1][(posisiP1%10)-1].setIcon(PapanP1B9[(posisiP1%10)-1]); } }
else if(posisiP1<=100){ if(posisiP1%10 == 0){ lArrPapan[0][0].setIcon(PapanP1B10[0]); } else { lArrPapan[0][10-(posisiP1%10)].setIcon(PapanP1B10[10-(posisiP1%10)]); } }

//set posisi player 2 ke papan
if(posisiP2<=10) { lArrPapan[9][posisiP2-1].setIcon(PapanP2B1[posisiP2-1]); }
else if(posisiP2<=20) { if(posisiP2%10 == 0){ lArrPapan[8][0].setIcon(PapanP2B2[0]); } else { lArrPapan[8][10-(posisiP2%10)].setIcon(PapanP2B2[10-(posisiP2%10)]); } }
else if(posisiP2<=30) { if(posisiP2%10 == 0){ lArrPapan[7][9].setIcon(PapanP2B3[9]); } else { lArrPapan[7][(posisiP2%10)-1].setIcon(PapanP2B3[(posisiP2%10)-1]); } }
else if(posisiP2<=40) { if(posisiP2%10 == 0){ lArrPapan[6][0].setIcon(PapanP2B4[0]); } else { lArrPapan[6][10-(posisiP2%10)].setIcon(PapanP2B4[10-(posisiP2%10)]); } }
else if(posisiP2<=50) { if(posisiP2%10 == 0){ lArrPapan[5][9].setIcon(PapanP2B5[9]); } else { lArrPapan[5][(posisiP2%10)-1].setIcon(PapanP2B5[(posisiP2%10)-1]); } }

else if(posisiP2<=60) { if(posisiP2%10 == 0){ lArrPapan[4][0].setIcon(PapanP2B6[0]); } else { lArrPapan[4][10-(posisiP2%10)].setIcon(PapanP2B6[10-(posisiP2%10)]); } }
else if(posisiP2<=70) { if(posisiP2%10 == 0){ lArrPapan[3][9].setIcon(PapanP2B7[9]); } else { lArrPapan[3][(posisiP2%10)-1].setIcon(PapanP2B7[(posisiP2%10)-1]); } }
else if(posisiP2<=80) { if(posisiP2%10 == 0){ lArrPapan[2][0].setIcon(PapanP2B8[0]); } else { lArrPapan[2][10-(posisiP2%10)].setIcon(PapanP2B8[10-(posisiP2%10)]); } }
else if(posisiP2<=90) { if(posisiP2%10 == 0){ lArrPapan[1][9].setIcon(PapanP2B9[9]); } else { lArrPapan[1][(posisiP2%10)-1].setIcon(PapanP2B9[(posisiP2%10)-1]); } }
else if(posisiP2<=100){ if(posisiP2%10 == 0){ lArrPapan[0][0].setIcon(PapanP2B10[0]); } else { lArrPapan[0][10-(posisiP2%10)].setIcon(PapanP2B10[10-(posisiP2%10)]); } }

}


}

}

}
public class HAPUS {

HAPUS(int posisiP1,int posisiP2) {
if(turn == 1) {
if(posisiP1==posisiP2) {
// code di bawah akn tampilkan Papan P2 pada posisi p1
if(posisiP1<=10) { lArrPapan[9][posisiP1-1].setIcon(PapanP2B1[posisiP1-1]); }
else if(posisiP1<=20) { if(posisiP1%10 == 0){ lArrPapan[8][0].setIcon(PapanP2B2[0]); } else { lArrPapan[8][10-(posisiP1%10)].setIcon(PapanP2B2[10-(posisiP1%10)]); } }
else if(posisiP1<=30) { if(posisiP1%10 == 0){ lArrPapan[7][9].setIcon(PapanP2B3[9]); } else { lArrPapan[7][(posisiP1%10)-1].setIcon(PapanP2B3[(posisiP1%10)-1]); } }
else if(posisiP1<=40) { if(posisiP1%10 == 0){ lArrPapan[6][0].setIcon(PapanP2B4[0]); } else { lArrPapan[6][10-(posisiP1%10)].setIcon(PapanP2B4[10-(posisiP1%10)]); } }
else if(posisiP1<=50) { if(posisiP1%10 == 0){ lArrPapan[5][9].setIcon(PapanP2B5[9]); } else { lArrPapan[5][(posisiP1%10)-1].setIcon(PapanP2B5[(posisiP1%10)-1]); } }

else if(posisiP1<=60) { if(posisiP1%10 == 0){ lArrPapan[4][0].setIcon(PapanP2B6[0]); } else { lArrPapan[4][10-(posisiP1%10)].setIcon(PapanP2B6[10-(posisiP1%10)]); } }
else if(posisiP1<=70) { if(posisiP1%10 == 0){ lArrPapan[3][9].setIcon(PapanP2B7[9]); } else { lArrPapan[3][(posisiP1%10)-1].setIcon(PapanP2B7[(posisiP1%10)-1]); } }
else if(posisiP1<=80) { if(posisiP1%10 == 0){ lArrPapan[2][0].setIcon(PapanP2B8[0]); } else { lArrPapan[2][10-(posisiP1%10)].setIcon(PapanP2B8[10-(posisiP1%10)]); } }
else if(posisiP1<=90) { if(posisiP1%10 == 0){ lArrPapan[1][9].setIcon(PapanP2B9[9]); } else { lArrPapan[1][(posisiP1%10)-1].setIcon(PapanP2B9[(posisiP1%10)-1]); } }
else if(posisiP1<=100){ if(posisiP1%10 == 0){ lArrPapan[0][0].setIcon(PapanP2B10[0]); } else { lArrPapan[0][10-(posisiP1%10)].setIcon(PapanP2B10[10-(posisiP1%10)]); } }

}
else {
// code di bawah akn tampilkan Papan Kosong pada posisi P1
if(posisiP1<=10) { lArrPapan[9][posisiP1-1].setIcon(PapanB1[posisiP1-1]); }
else if(posisiP1<=20) { if(posisiP1%10 == 0){ lArrPapan[8][0].setIcon(PapanB2[0]); } else { lArrPapan[8][10-(posisiP1%10)].setIcon(PapanB2[10-(posisiP1%10)]); } }
else if(posisiP1<=30) { if(posisiP1%10 == 0){ lArrPapan[7][9].setIcon(PapanB3[9]); } else { lArrPapan[7][(posisiP1%10)-1].setIcon(PapanB3[(posisiP1%10)-1]); } }
else if(posisiP1<=40) { if(posisiP1%10 == 0){ lArrPapan[6][0].setIcon(PapanB4[0]); } else { lArrPapan[6][10-(posisiP1%10)].setIcon(PapanB4[10-(posisiP1%10)]); } }
else if(posisiP1<=50) { if(posisiP1%10 == 0){ lArrPapan[5][9].setIcon(PapanB5[9]); } else { lArrPapan[5][(posisiP1%10)-1].setIcon(PapanB5[(posisiP1%10)-1]); } }

else if(posisiP1<=60) { if(posisiP1%10 == 0){ lArrPapan[4][0].setIcon(PapanB6[0]); } else { lArrPapan[4][10-(posisiP1%10)].setIcon(PapanB6[10-(posisiP1%10)]); } }
else if(posisiP1<=70) { if(posisiP1%10 == 0){ lArrPapan[3][9].setIcon(PapanB7[9]); } else { lArrPapan[3][(posisiP1%10)-1].setIcon(PapanB7[(posisiP1%10)-1]); } }
else if(posisiP1<=80) { if(posisiP1%10 == 0){ lArrPapan[2][0].setIcon(PapanB8[0]); } else { lArrPapan[2][10-(posisiP1%10)].setIcon(PapanB8[10-(posisiP1%10)]); } }
else if(posisiP1<=90) { if(posisiP1%10 == 0){ lArrPapan[1][9].setIcon(PapanB9[9]); } else { lArrPapan[1][(posisiP1%10)-1].setIcon(PapanB9[(posisiP1%10)-1]); } }
else if(posisiP1<=100){ if(posisiP1%10 == 0){ lArrPapan[0][0].setIcon(PapanB10[0]); } else { lArrPapan[0][10-(posisiP1%10)].setIcon(PapanB10[10-(posisiP1%10)]); } }

}

}
else if(turn == 2) {
if(posisiP1==posisiP2) {
// code di bawah akn tampilkan Papan P1 pada posisi p2
if(posisiP2<=10) { lArrPapan[9][posisiP2-1].setIcon(PapanP1B1[posisiP2-1]); }
else if(posisiP2<=20) { if(posisiP2%10 == 0){ lArrPapan[8][0].setIcon(PapanP1B2[0]); } else { lArrPapan[8][10-(posisiP2%10)].setIcon(PapanP1B2[10-(posisiP2%10)]); } }
else if(posisiP2<=30) { if(posisiP2%10 == 0){ lArrPapan[7][9].setIcon(PapanP1B3[9]); } else { lArrPapan[7][(posisiP2%10)-1].setIcon(PapanP1B3[(posisiP2%10)-1]); } }
else if(posisiP2<=40) { if(posisiP2%10 == 0){ lArrPapan[6][0].setIcon(PapanP1B4[0]); } else { lArrPapan[6][10-(posisiP2%10)].setIcon(PapanP1B4[10-(posisiP2%10)]); } }
else if(posisiP2<=50) { if(posisiP2%10 == 0){ lArrPapan[5][9].setIcon(PapanP1B5[9]); } else { lArrPapan[5][(posisiP2%10)-1].setIcon(PapanP1B5[(posisiP2%10)-1]); } }

else if(posisiP2<=60) { if(posisiP2%10 == 0){ lArrPapan[4][0].setIcon(PapanP1B6[0]); } else { lArrPapan[4][10-(posisiP2%10)].setIcon(PapanP1B6[10-(posisiP2%10)]); } }
else if(posisiP2<=70) { if(posisiP2%10 == 0){ lArrPapan[3][9].setIcon(PapanP1B7[9]); } else { lArrPapan[3][(posisiP2%10)-1].setIcon(PapanP1B7[(posisiP2%10)-1]); } }
else if(posisiP2<=80) { if(posisiP2%10 == 0){ lArrPapan[2][0].setIcon(PapanP1B8[0]); } else { lArrPapan[2][10-(posisiP2%10)].setIcon(PapanP1B8[10-(posisiP2%10)]); } }
else if(posisiP2<=90) { if(posisiP2%10 == 0){ lArrPapan[1][9].setIcon(PapanP1B9[9]); } else { lArrPapan[1][(posisiP2%10)-1].setIcon(PapanP1B9[(posisiP2%10)-1]); } }
else if(posisiP2<=100){ if(posisiP2%10 == 0){ lArrPapan[0][0].setIcon(PapanP1B10[0]); } else { lArrPapan[0][10-(posisiP2%10)].setIcon(PapanP1B10[10-(posisiP2%10)]); } }

}
else {
// code di bawah akn tampilkan Papan Kosong pada posisi P2
if(posisiP2<=10) { lArrPapan[9][posisiP2-1].setIcon(PapanB1[posisiP2-1]); }
else if(posisiP2<=20) { if(posisiP2%10 == 0){ lArrPapan[8][0].setIcon(PapanB2[0]); } else { lArrPapan[8][10-(posisiP2%10)].setIcon(PapanB2[10-(posisiP2%10)]); } }
else if(posisiP2<=30) { if(posisiP2%10 == 0){ lArrPapan[7][9].setIcon(PapanB3[9]); } else { lArrPapan[7][(posisiP2%10)-1].setIcon(PapanB3[(posisiP2%10)-1]); } }
else if(posisiP2<=40) { if(posisiP2%10 == 0){ lArrPapan[6][0].setIcon(PapanB4[0]); } else { lArrPapan[6][10-(posisiP2%10)].setIcon(PapanB4[10-(posisiP2%10)]); } }
else if(posisiP2<=50) { if(posisiP2%10 == 0){ lArrPapan[5][9].setIcon(PapanB5[9]); } else { lArrPapan[5][(posisiP2%10)-1].setIcon(PapanB5[(posisiP2%10)-1]); } }

else if(posisiP2<=60) { if(posisiP2%10 == 0){ lArrPapan[4][0].setIcon(PapanB6[0]); } else { lArrPapan[4][10-(posisiP2%10)].setIcon(PapanB6[10-(posisiP2%10)]); } }
else if(posisiP2<=70) { if(posisiP2%10 == 0){ lArrPapan[3][9].setIcon(PapanB7[9]); } else { lArrPapan[3][(posisiP2%10)-1].setIcon(PapanB7[(posisiP2%10)-1]); } }
else if(posisiP2<=80) { if(posisiP2%10 == 0){ lArrPapan[2][0].setIcon(PapanB8[0]); } else { lArrPapan[2][10-(posisiP2%10)].setIcon(PapanB8[10-(posisiP2%10)]); } }
else if(posisiP2<=90) { if(posisiP2%10 == 0){ lArrPapan[1][9].setIcon(PapanB9[9]); } else { lArrPapan[1][(posisiP2%10)-1].setIcon(PapanB9[(posisiP2%10)-1]); } }
else if(posisiP2<=100){ if(posisiP2%10 == 0){ lArrPapan[0][0].setIcon(PapanB10[0]); } else { lArrPapan[0][10-(posisiP2%10)].setIcon(PapanB10[10-(posisiP2%10)]); } }

}
}
}
}
class OPEN {
OPEN(int t,String player1,String player2,int posisiP1,int posisiP2,Boolean tanda,int jalan,Boolean open) {

for(int i=0;i<10;i++) {
for(int j=0;j<10;j++) {

if(i==9) { lArrPapan[i][j].setIcon(PapanB1[j]); }
else if(i==Cool { lArrPapan[i][j].setIcon(PapanB2[j]); }
else if(i==7) { lArrPapan[i][j].setIcon(PapanB3[j]); }
else if(i==6) { lArrPapan[i][j].setIcon(PapanB4[j]); }
else if(i==5) { lArrPapan[i][j].setIcon(PapanB5[j]); }

else if(i==4) { lArrPapan[i][j].setIcon(PapanB6[j]); }
else if(i==3) { lArrPapan[i][j].setIcon(PapanB7[j]); }
else if(i==2) { lArrPapan[i][j].setIcon(PapanB8[j]); }
else if(i==1) { lArrPapan[i][j].setIcon(PapanB9[j]); }
else if(i==0) { lArrPapan[i][j].setIcon(PapanB10[j]); }


}
}

//--- code
new RUN(posisiP1,posisiP2,true);

//ganti hati jika dipencet stop + end turn
if(jalan==1) { h1.setIcon(hati1);
h2.setIcon(hati2);
}
else { h1.setIcon(hati2);
h2.setIcon(hati1);
}



}

}


public static void main(String[]args) {



String nm1 = "";
String nm2 = "";


new UlarTangga(0,nm1,nm2,1,1,false,1,false);

//------------------------------------------------------------------------------------------------ test INPUT-----
}

// untuk animasi acak dadu menggunakan thread
public static class BasicThread1 extends Thread {
// This method is called when the thread runs


public void run() {
while(true) {
// do work acak dadu
dc = (int)(Math.random() * 6);
dice.setIcon(dadu[dc]);
if(stp==true) {return;}
}
//return; //jgn

}
}




public void actionPerformed(ActionEvent e) {


// action listener File menu
if(e.getSource()==menuNew) {
dispose();

nmp1 = JOptionPane.showInputDialog(null,"Input First Player's Name :");
nmp2 = JOptionPane.showInputDialog(null,"Input Second Player's Name :");
if(nmp1.equals(" ") || nmp2.equals(" ")) {
JOptionPane.showMessageDialog(this,"Nama Player Harus Diisi");

dispose();
String nm1 = "";
String nm2 = "";
new UlarTangga(0,nm1,nm2,1,1,false,1,false);
}
else if(nmp1.equals(nmp2)) {
JOptionPane.showMessageDialog(this,"Nama First Player dan Second Player Tidak Boleh Sama");

dispose();
String nm1 = "";
String nm2 = "";
new UlarTangga(0,nm1,nm2,1,1,false,1,false);
}
else if( nmp1.equals(nmp2)==false ) {

btnGo.setEnabled(true);
btnGo.setVisible(true);
btnStop.setVisible(false);
btnStop.setEnabled(false);

turn=1;

posP1=1; // posisi 1-100
posP2=1;
new UlarTangga(1,nmp1,nmp2,posP1,posP2,true,turn,false);
}

}
else if(e.getSource()==menuOpen) {
try {
int result = jfc.showOpenDialog(this);
if(result == jfc.APPROVE_OPTION) {
BufferedReader buf = new BufferedReader(new FileReader(jfc.getSelectedFile()));
String line = null;
Vector data = new Vector();

new HAPUS(posP1,posP2);

while((line=buf.readLine())!=null) {
data.add(line);
}


String data1 = (String) data.elementAt(0);

String split[] = data1.split(";");

turn = Integer.parseInt(split[0]);
nmp1 = split[1].toString();
posP1 = Integer.parseInt(split[2]);

nmp2 = split[3].toString();
posP2 = Integer.parseInt(split[4]);


new OPEN(1,nmp1,nmp2,posP1,posP2,true,turn,true);

// panel nama player - > akan tampil bila sudah di imput

name1 = new JLabel(nmp1);
pP1name.add(name1);

name2 = new JLabel(nmp2);
pP2name.add(name2);

btnGo.setEnabled(true);
btnGo.setVisible(true);
btnStop.setVisible(false);
btnStop.setEnabled(false);

buf.close();
}
}catch(Exception ex) {
dispose();
String nm1 = "";
String nm2 = "";
new UlarTangga(0,nm1,nm2,1,1,false,1,false);

JOptionPane.showMessageDialog(this,"Error loading file");
}



}
else if(e.getSource()==menuSave) {

try {
int result = jfc.showSaveDialog(this);
if(result == jfc.APPROVE_OPTION) {
PrintWriter p = new PrintWriter(new FileWriter(jfc.getSelectedFile()));

p.print(turn+";");

p.print(nmp1+";");
p.print(posP1+";");

p.print(nmp2+";");
p.print(posP2);

p.println();
p.close();
}
}catch(Exception ex) {
JOptionPane.showMessageDialog(this,"Error saving file");
}

}
else if(e.getSource()==menuExit) {
dispose();
System.exit(0);
}

// action listener Help Menu
else if(e.getSource()==menuHelp) {
JOptionPane.showMessageDialog(null,"How to Play :\n\nClick File -> New Game\n\nAnd Play it!");
}
else if(e.getSource()==menuAbout) {
JOptionPane.showMessageDialog(null,"UlarTangga\n\nCreated By : Unknown\nups_in_blues@yahoo.com ^_^!");
}

// action listener Button
else if(e.getSource()==btnGo) {

btnStop.setVisible(true);
btnStop.setEnabled(true);
btnGo.setEnabled(false);
btnGo.setVisible(false);

stp=false;
Thread thread = new BasicThread1();
thread.start();


}
else if(e.getSource()==btnStop) {


stp = true;

if(turn==1) {

new HAPUS(posP1,posP2);
posP1 = posP1+dc+1;
if(posP1>100) { posP1=100-(posP1-100); }
else if(posP1==100) {
JOptionPane.showMessageDialog(this,"Player "+turn+" MENANG!");
dispose();
String noName="";
new UlarTangga(0,noName,noName,1,1,false,1,false);
}


}
else if(turn==2) {

new HAPUS(posP1,posP2);
posP2 = posP2+dc+1;
if(posP2>100) { posP2=100-(posP2-100); }
else if(posP2==100) {
JOptionPane.showMessageDialog(this,"Player "+turn+" MENANG!");
dispose();
String noName="";
new UlarTangga(0,noName,noName,1,1,false,1,false);
}

}

switch(posP1) {
case 3 : posP1=39; break;
case 7 : posP1=34; break;
case 64 : posP1=96; break;
case 47 : posP1=17; break;
case 65 : posP1=38; break;
case 86 : posP1=12; break;
case 99 : posP1=43; break;
}

switch(posP2) {
case 3 : posP2=39; break;
case 7 : posP2=34; break;
case 64 : posP2=96; break;
case 47 : posP2=17; break;
case 65 : posP2=38; break;
case 86 : posP2=12; break;
case 99 : posP2=43; break;
}

new RUN(posP1,posP2,true);

//ganti hati jika dipencet stop + end turn
if(turn==1) { h1.setIcon(hati2);
h2.setIcon(hati1);
turn=2;
}
else { h1.setIcon(hati1);
h2.setIcon(hati2);
turn=1;
}

btnGo.setEnabled(true);
btnGo.setVisible(true);
btnStop.setVisible(false);
btnStop.setEnabled(false);



}

}



}
[/spolier]


Terakhir diubah oleh risdo tanggal Sun Apr 18, 2010 1:45 am, total 1 kali diubah
avatar
risdo
Admin
Admin

Posts : 209
Reputasi : 377
Cendol : 1
Join date : 26.10.09
Location : Bekasi

Lihat profil user http://c0b4d1b4c4.indonesianforum.net

Kembali Ke Atas Go down

default Re: Source Code Ular Tangga

Post by fahrizal_gg on Mon Apr 12, 2010 10:06 pm

panjang amat..
>.<

di spoiler donk
avatar
fahrizal_gg

Posts : 32
Reputasi : 36
Cendol : 0
Join date : 28.10.09
Age : 28
Location : dunia DOTA

Lihat profil user

Kembali Ke Atas Go down

default Re: Source Code Ular Tangga

Post by danjoh on Fri Apr 16, 2010 4:55 pm

hacim,,, panjang aje ulernye...
avatar
danjoh

Posts : 14
Reputasi : 20
Cendol : 0
Join date : 14.11.09
Location : jakarta

Lihat profil user

Kembali Ke Atas Go down

default Re: Source Code Ular Tangga

Post by Sponsored content


Sponsored content


Kembali Ke Atas Go down

Topik sebelumnya Topik selanjutnya Kembali Ke Atas

- Similar topics

 
Permissions in this forum:
Anda tidak dapat menjawab topik