LISNING CARA BUAT RUMAH DAN MOBIL MENGGUNAKAN JAVA.AWT

Selasa, 24 September 2013

                                                     Nama : Herdiyanto P.S Gaddy
                                                     Nim : 11110076
                                                     Kelas : B


Lisning cara buat Rumah
/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package tugas_buat_rumah;

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

/**
 *
 * @author Toshiba
 */
public class Tugas_buat_rumah extends Panel
{
    
    Tugas_buat_rumah () {
        setBackground (Color.cyan);
    }
   
    public void paint(Graphics u)
    {
   
    //Rumput
    u.setColor(Color.GREEN);
    u.fillRect(0, 200, 590, 270);
   
   
    //Matahari
    u.setColor(Color.yellow);
    u.fillOval(430, 50, 80, 80);
   
    u.setColor(new Color(245,135,14));  //cahaya matahari
    u.drawLine(430, 90, 380, 90);   //garis kiri
    u.drawLine(440, 60, 380, 30);   //kiri atas
    u.drawLine(440, 120, 380, 150);   //kiri bawah
    u.drawLine(560, 90, 510, 90);   //garis kanan
    u.drawLine(560, 30, 500, 60);   //kanan atas
    u.drawLine(560, 150, 500, 120);   //kanan bawah
    u.drawLine(470, 10, 470, 50);   //utara
    u.drawLine(470, 130, 470, 170); //selatan
   
    //Awan
    u.setColor(Color.white);
    u.fillOval(20, 15, 70, 70);
    u.fillOval(50, 15, 70, 75);
    u.fillOval(100, 15, 70, 70);
   
    //Rumah
    u.setColor(Color.RED);
    u.fillRect(10, 300, 100, 150);
   
    //Pintu Rumah
    u.setColor(Color.DARK_GRAY);
    u.fillRect(50, 374, 50, 75);
   
    //Gagang Pintu
    u.setColor(Color.YELLOW);
    u.fillOval(88, 400, 10, 10);
   
    //Atap Rumah
    u.setColor(Color.ORANGE);
    int x[] = new int[] {10,60,110};
    int y[] = new int [] {300,250,300};
    u.fillPolygon(x, y, 3);
   
    //Jalan
    u.setColor(Color.gray);
    int a[] = new int[]{580,240,410,580};
    int b[] = new int[]{200,460,460,320};
    u.fillPolygon(a, b, 4);
   
    //Garis Jalan 1
    u.setColor(Color.white);
    int c[] = new int[]{530,560,570,540};
    int d[] = new int[]{280,260,260,280};
    u.fillPolygon(c, d, 4);
   
    //Garis Jalan 2
    int e[] = new int[]{440,470,480,450};
    int f[] = new int[]{360,340,340,360};
    u.fillPolygon(e, f, 4);
   
    //Garis Jalan 3
    int g[] = new int[]{340,370,380,350};
    int h[] = new int[]{450,430,430,450};
    u.fillPolygon(g, h, 4);
   
   
    }
   
      public static void main(String[] args) {
     Frame f1 = new Frame("Tugas = Herdiyanto P.S Gaddy");
     Tugas_buat_rumah H = new Tugas_buat_rumah();
     f1.add(H);
     f1.setSize(600, 500);
     f1.setVisible(true);
     
}
}

                                                                   Hasil Outputnya :




                                                                  Lisning cara buat mobil
package gambar_mobil;
import java.awt.*;
import java.awt.event.*;
public class Gambar_mobil extends Frame implements ActionListener{
    int x = 100;
    int y = 100;
public static void main(String[] args) {
    Frame frame = new Gambar_mobil();
    frame.setSize(640, 480);
    frame.setVisible(true);
}
public Gambar_mobil() {
      setBackground (Color.YELLOW);
setTitle("Gambar_mobil");
// create menu
    MenuBar mb = new MenuBar();
    setMenuBar(mb);
    Menu menu = new Menu("File");
    mb.add(menu);
    MenuItem mi = new MenuItem("Exit");
    mi.addActionListener(this);
    menu.add(mi);
// end program when window is closed
    WindowListener l = new WindowAdapter()  {
    public void windowClosing(WindowEvent ev) {
    System.exit(0);
    }
    };
this.addWindowListener(l);
// mouse event handler
MouseListener mouseListener = new MouseAdapter() {
public void mouseClicked(MouseEvent ev) {
    x = ev.getX();
    y = ev.getY();
    repaint();
}
};
addMouseListener(mouseListener);
}
public void paint(Graphics g) {
g.setColor(Color.BLUE);
g.fillRect(550, 250, 550, 270); //g.drawRect(x, y, WIDTH, WIDTH)
g.setColor(Color.RED);
g.drawRect(299, 320, 250, 200);
g.setColor(Color.black);
g.fillOval(349, 520, 100, 100);
g.setColor(Color.black);
g.fillOval(470, 520, 100, 100);
g.drawOval(349, 560, 200, WIDTH);
g.setColor(Color.black);
g.fillOval(930, 520, 100, 100);
g.setColor(Color.black);
g.fillOval(800, 520, 100, 100);
g.drawOval(800, 560, 200, WIDTH);
}
public void actionPerformed(ActionEvent ev) {
String command = ev.getActionCommand();
if ("Exit".equals(command)) {
System.exit(0);
}
}
}

                                                               Hasil Outputnya :


0 komentar: