Laman

Rabu, 17 Oktober 2012

Contoh Program AWT Java

Haloo pembaca..!
Saya diberikan tugas oleh guru Java saya untuk membuat program salah satu program Java menggunakan AWT. Tugas ini juga disuruh dipost sama guru saya, jadi saya post di blog saya deh..

Berikut tugasnya:



import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Panel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author NuRender
 */
public class latihan_kuis extends Panel {
    latihan_kuis(){
        setBackground(new Color(0,255,255));
    }
    @Override
    public void paint(Graphics k){
        k.setColor(Color.GREEN);
        k.fillRect(0, 200, 590, 270);
   
       
        k.setColor(Color.YELLOW);
        k.fillOval(475, 15, 60, 60);
       
        k.setColor(Color.RED);
        int x[] = new int[] {5,55,110};
        int y[] = new int[] {230,130,230};
        k.fillPolygon(x, y, 3);
       
        k.setColor(Color.LIGHT_GRAY);
        k.fillRect(20, 230, 70, 130);
        k.setColor(Color.ORANGE);
        k.fillRect(55, 290, 30, 70);
        k.setColor(Color.DARK_GRAY);
        k.fillOval(74, 325, 7, 7);
        k.setColor(Color.gray);
        int a[] = new int[]{580,240,410,580};
        int b[] = new int[]{200,460,460,320};
        k.fillPolygon(a, b, 4);
       
        k.setColor(Color.WHITE);
        k.fillOval(70, 10, 100, 40);
        k.fillOval(80, 20, 70, 45);
        k.fillOval(120, 20, 70, 45);
        k.fillOval(90, 5, 70, 45);
        k.fillOval(70, 5, 70, 55);
        k.fillOval(140, 10, 70, 45);
        k.fillOval(40, 10, 70, 45);
       
    }
    public static void main(String[] args) {
        Frame f2 = new Frame();
        latihan_kuis F = new latihan_kuis();
        f2.add(F);
        f2.setSize(500,400);
        f2.setVisible(true);
    }
}


Hasilnya akan tampak seperti ini:

2 komentar: