Membuat Kapal dengan Java NetBeans - GAPAPALAH BLOG

Breaking

Thursday, April 25, 2019

Membuat Kapal dengan Java NetBeans



Ikuti Langkah-Langkah Dibawah ini Untuk Membuat Kapal Menggunakan Java NetBeans : 

1. Buatlah project baru di NetBeans, Pilih File > New Project
2. Pilih kategori di Java NetBeans, Pilih Java dan klik project Java Aplication
3. Klik Tombol Next
4. Setelah melakukan Langkah ke 3 buatlah project dengan nama "Kapal" lalu klik Finish
5. Lalu copy script dibawah ini dan masukan ke project yang telah kalian buat tadi

Baca Juga : 

Membuat Bar Chart Menggunakan JavaNetbeans Tanpa JFreechart


Membuat Line Chart Menggunakan JavaNetbeans Tanpa JFreechart


Membuat Pie Chart Menggunakan JavaNetbeans 



import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.geom.GeneralPath;

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

/**
 *
 * @author ASUS
 */
public class Kapal extends javax.swing.JFrame {

    @Override
    public void paint(Graphics g) {
        super.paint(g); //To change body of generated methods, choose Tools | Templates.
   
 
        Graphics2D g2 = (Graphics2D)g;
        g2.setColor(Color.BLUE);
       
 
        g2.translate(50, 50);
        Polygon kapal = new Polygon();
        kapal.addPoint(30, 100);
        kapal.addPoint(100, 100);
        kapal.addPoint(100, 90);
        kapal.addPoint(125, 90);
        kapal.addPoint(125, 60);
        kapal.addPoint(130, 60);
        kapal.addPoint(140, 70);
        kapal.addPoint(130, 75);
        kapal.addPoint(130, 90);
        kapal.addPoint(155, 90);
        kapal.addPoint(155, 100);
        kapal.addPoint(225, 100);
        kapal.addPoint(200, 125);
        kapal.addPoint(55, 125);
        kapal.addPoint(30, 100);
        g2.fill(kapal);
        g2.draw(kapal);

       
 
    }
   
 
   
 

    /**
     * Creates new form Kapal
     */
    public Kapal() {
        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, 434, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 292, 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(Kapal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Kapal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Kapal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Kapal.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 Kapal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                    
 
    // End of variables declaration                  
 
}


Hasilnya :

SELAMAT MENCOBA :)

No comments:

Post a Comment