Rio Vian

Rabu, 10 Agustus 2016

Grafis 2D Pemrograman Berorientasi Objek Cara membuat mobil sederhana dalam java menggunakan netbeans





Source Code :


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication2;

import java.awt.Color;
import java.awt.Graphics;

/**
 *
 * @author VRO
 */
public class Frm_geometri extends javax.swing.JFrame {
public void paint(Graphics gr){
    gr.setColor(Color.red);
    gr.fillOval(0, 50, 400 , 400);
   
    gr.setColor(Color.YELLOW);
    gr.fillOval(25, 75, 350 , 350);
   
    gr.setColor(Color.GREEN);
    gr.fillOval(50, 100, 300 , 300);
   
    gr.setColor(Color.BLUE);
    gr.fillOval(75, 125, 250 , 250);
   
    gr.setColor(Color.black);
    gr.fillRect(0, 150, 400, 110);
   
    gr.setColor(Color.white);
    gr.fillRect(0, 260, 400, 80);
   
    int Ax[ ]= {65,55,115,125};
    int Ay[ ]= {200,220,220,200};
    int Ap=Ax.length;
    gr.setColor(Color.white);
    gr.fillPolygon(Ax,Ay,Ap);
   
    int Bx[ ]= {145,135,195,205};
    int By[ ]= {200,220,220,200};
    int Bp=Bx.length;
    gr.setColor(Color.white);
    gr.fillPolygon(Bx,By,Bp);
   
    int Dx[ ]= {315,305,375,385};
    int Dy[ ]= {200,220,220,200};
    int Dp=Dx.length;
    gr.setColor(Color.white);
    gr.fillPolygon(Dx,Dy,Dp);
   
     int Cx[ ]= {225,215,285,295};
    int Cy[ ]= {200,220,220,200};
    int Cp=Cx.length;
    gr.setColor(Color.white);
    gr.fillPolygon(Cx,Cy,Cp);

   
   
    gr.setColor(Color.red);
    gr.fillRect(125, 185, 150, 25);
    int Vx[ ]= {110,125,125,110};
    int Vy[ ]= {185,185,210,195};
    int np=Vx.length;
    gr.setColor(Color.red);
    gr.fillPolygon(Vx,Vy,np);
   
    gr.setColor(Color.white);
    gr.fillOval(140, 195, 25, 25);
    gr.setColor(Color.black);
    gr.fillOval(143, 196, 20, 20);
    gr.setColor(Color.white);
    gr.fillOval(150, 203, 5, 5);
    gr.setColor(Color.white);
    gr.fillOval(220, 195, 25, 25);
    gr.setColor(Color.black);
    gr.fillOval(223, 196, 20, 20);
    gr.setColor(Color.white);
    gr.fillOval(231, 203, 5, 5);
   
    gr.setColor(Color.red);
    gr.fillRect(175, 110, 100, 70);
   
    int Sx[ ]= {170,170,110,110,135};
    int Sy[ ]= {125,180,180,155,125};
    int mp=Sx.length;
    gr.setColor(Color.red);
    gr.fillPolygon(Sx,Sy,mp);
   
    int Px[ ]= {165,165,115,115,135};
    int Py[ ]= {130,155,155,155,130};
    int Pp=Px.length;
    gr.setColor(Color.white);
    gr.fillPolygon(Px,Py,Pp);
   
    int Kx[ ]= {165,165,115,115,135};
    int Ky[ ]= {130,155,155,155,130};
    int Kp=Kx.length;
    gr.setColor(Color.black);
    gr.drawPolygon(Kx,Ky,Kp);
   
    gr.setColor(Color.white);
    gr.fillRect(212, 120, 20, 50);
    gr.fillRect(197, 135, 50, 20);
   
  
}
    public Frm_geometri() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>                       

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Frm_geometri.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Frm_geometri.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Frm_geometri.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Frm_geometri.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Frm_geometri().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                    
    // End of variables declaration                  
}

Tidak ada komentar:

Posting Komentar