• Terbaru

    Membuat Papan Catur (Java - Komputer Grafik)

    Membuat papan catur :
    Cara paling praktis adalah menggunakan looping, ini akan meringkas kode yang di ulang ulang, silakan cari sendiri, cara susahnya seperti di bawah :



    public void paint(Graphics g){
            g.setColor(Color.black);
         
            Graphics2D g2d = (Graphics2D) g;
         
            //garis
            g2d.draw(new Line2D.Double(20,40,20,300)); //vertikal kiri 1
            g2d.draw(new Line2D.Double(30,50,30,290)); //vertikal kiri2
            g2d.draw(new Line2D.Double(60,50,60,290)); //vertikal kiri3
            g2d.draw(new Line2D.Double(90,50,90,290)); //vertikal kiri4
            g2d.draw(new Line2D.Double(120,50,120,290)); //vertikal kiri5
            g2d.draw(new Line2D.Double(150,50,150,290)); //vertikal kiri6
            g2d.draw(new Line2D.Double(180,50,180,290)); //vertikal kiri7
            g2d.draw(new Line2D.Double(210,50,210,290)); //vertikal kiri8
            g2d.draw(new Line2D.Double(240,50,240,290)); //vertikal kiri9
            g2d.draw(new Line2D.Double(270,50,270,290)); //vertikal kiri10
            g2d.draw(new Line2D.Double(280,40,280,300)); //vertikal kiri11
         
         
            g2d.draw(new Line2D.Double(20,40,280,40)); //atas 1      
            g2d.draw(new Line2D.Double(30,50,270,50)); // atas2
            g2d.draw(new Line2D.Double(30,80,270,80)); // atas3
            g2d.draw(new Line2D.Double(30,110,270,110)); // atas4
            g2d.draw(new Line2D.Double(30,140,270,140)); // atas5
            g2d.draw(new Line2D.Double(30,170,270,170)); // atas6
            g2d.draw(new Line2D.Double(30,200,270,200)); // atas7
            g2d.draw(new Line2D.Double(30,230,270,230)); // atas8
            g2d.draw(new Line2D.Double(30,260,270,260)); // atas9
            g2d.draw(new Line2D.Double(30,290,270,290)); // atas10
            g2d.draw(new Line2D.Double(20,300,280,300)); // bawah
         
         
            //kolom 1
            g2d.fillRect(30, 80, 30, 30);
            g2d.fillRect(30, 140, 30, 30);
            g2d.fillRect(30, 200, 30, 30);
            g2d.fillRect(30, 260, 30, 30);
         
         
            //kolom 2
            g2d.fillRect(60, 50, 30, 30);
            g2d.fillRect(60, 110, 30, 30);
            g2d.fillRect(60, 170, 30, 30);
            g2d.fillRect(60, 230, 30, 30);
         
            //kolom 3
            g2d.fillRect(90, 80, 30, 30);
            g2d.fillRect(90, 140, 30, 30);
            g2d.fillRect(90, 200, 30, 30);
            g2d.fillRect(90, 260, 30, 30);
         
            //kolom 4
            g2d.fillRect(120, 50, 30, 30);
            g2d.fillRect(120, 110, 30, 30);
            g2d.fillRect(120, 170, 30, 30);
            g2d.fillRect(120, 230, 30, 30);
         
            //kolom 5
            g2d.fillRect(150, 80, 30, 30);
            g2d.fillRect(150, 140, 30, 30);
            g2d.fillRect(150, 200, 30, 30);
            g2d.fillRect(150, 260, 30, 30);
         
            //kolom 7
             g2d.fillRect(180, 50, 30, 30);
            g2d.fillRect(180, 110, 30, 30);
            g2d.fillRect(180, 170, 30, 30);
            g2d.fillRect(180, 230, 30, 30);
         
            //kolom 9
            g2d.fillRect(210, 80, 30, 30);
            g2d.fillRect(210, 140, 30, 30);
            g2d.fillRect(210, 200, 30, 30);
            g2d.fillRect(210, 260, 30, 30);
         
            //kolom 10
             g2d.fillRect(240, 50, 30, 30);
            g2d.fillRect(240, 110, 30, 30);
            g2d.fillRect(240, 170, 30, 30);
            g2d.fillRect(240, 230, 30, 30);
    }

    5 comments:

    1. kok saya gagal yaa
      class, interface, or unexpected
      pas di void nya

      ReplyDelete
      Replies
      1. unexpected biasanya ada tanda yang kurang itu bero

        Delete
    2. Bang bisa bikin polygon menggunakan for if, gambarnya sma sperti papan catur tapi didialam papan catur ada garis segitiga warna hitam terus seblahnya lagi warna putih sebelahnya lagi hitam, bisa gak bang ?ane soalnya ada kepentingan buat itu matakuliah

      ReplyDelete

    Saya sangat berterimakasih apabila sahabat sekalian bersedia untuk tidak meninggalkan spam dan meninggalkan komentar yang berhubungan dengan artikel di atas.