Archives

Membuat Lingkaran dan Bola dengan Java NetBeans

Cuma pengen share ilmu aja nih . Yang mau belajar membuat bangun datar dan bangun ruang dengan menggunakan java NetBeans terutama membuat Lingkaran dan Bola.
Yukkkk belajar bareng bareng :)

Langkah :

  1. buka Java NetBeans
  2. klik File – New Project…
  3. pilih Java pada Categories dan Java Class Library pada Projects, setelah itu klik Next
  4. isi Project Name dengan TerserahElu, lalu Klik Finish
  5. untuk membuat tampilan gui, kita harus masuk ke tampilan GUI, klik kanan pada project – New – Jframe Form…
  6. isi Class Name dengan buatdibagi, lalu klik Finish
  7. pada halaman JFrame sebelah kiri atas, klik Soure
  8. masukkan koding seperti ini
Lanjut yoook ke tahap berikutnya. Enjoyed.

LINGKARAN
import java.awt.Graphics;

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

/*
* lingkaran.java
*
* Created on Dec 28, 2010, 11:46:47 AM
*/

/**
*
* @author user
*/
public class lingkaran extends javax.swing.JFrame {
public void paint (Graphics g) {
g.drawOval(100, 100, 100, 100);
}
/** Creates new form lingkaran */
public lingkaran() {
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")
//
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();
}//

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new lingkaran().setVisible(true);
}
});
}

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

}

BOLA


import java.awt.Graphics;

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

/*
* bola.java
*
* Created on Dec 28, 2010, 11:51:22 AM
*/

/**
*
* @author user
*/
public class bola extends javax.swing.JFrame {
public void paint (Graphics g) {
g.drawOval(100, 100, 100, 100);
g.drawOval(125, 100, 50, 100);
g.drawOval(100, 125, 100, 50);
}

/** Creates new form bola */
public bola() {
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")
//
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();
}//

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new bola().setVisible(true);
}
});
}

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

}

Nih klo udah jadi penampakannya kaya begini. Please cek this out :)