Thursday, June 7, 2012

Buku Telepon GUI - Netbeans Java Program

NetBeans adalah suatu aplikasi pengembangan perangkat lunak yang ditulis dalam bahasa pemrograman Java. Aplikasi NetBeans IDE tak hanya digunakan bagi pengembangan dalam Java. Namun, aplikasi ini juga mendukung program-program pembuatan bahasa lain secara khusus seperti PHP, C/C++ dan HTML5.

Ini adalah source code java unuk buat BUKU TELEPON dengan GUI, disini ada cara meletakkan JLabel, JButton sama JTextField pada java, semoga bermanfaat !


----------------------------------------------------------------------------------------------------------
kelas pertama



import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;


public class bukuTelepon extends javax.swing.JFrame implements ActionListener {
JLabel lblNama = new JLabel("Nama \t\t: ");
JTextField txtNama = new JTextField(20);
JLabel lblNmr = new JLabel("Nomor Telepon \t\t: ");
JTextField txtNmr = new JTextField(20);
JLabel lblJK = new JLabel("Jenis Kelamin \t\t: ");
JTextField txtJK = new JTextField(20);
JLabel lblAlamat = new JLabel("Alamat \t\t: ");
JTextField txtAlamat = new JTextField(20);
JLabel lblTGL = new JLabel("Tanggal Lahir \t\t: ");
JTextField txtTGL = new JTextField(20);
JLabel lblEmail = new JLabel("Email \t\t: ");
JTextField txtEmail = new JTextField(20);
JButton btnOK = new JButton("\nSimpan");
public bukuTelepon(){
super("Form Pendaftaran");
setLayout (null);
add(lblNama);add(txtNama);
add(lblNmr);add(txtNmr);
add(lblJK);add(txtJK);
add(lblAlamat);add(txtAlamat);
add(lblTGL);add(txtTGL);
add(lblEmail);add(txtEmail);
setLayout (null);
add(btnOK);
btnOK.addActionListener(this);
lblNama.setBounds(10,10,140,20);
txtNama.setBounds(120,10,140,20);
lblNmr.setBounds(10,40,140,20);
txtNmr.setBounds(120,40,140,20);
lblJK.setBounds(10,70,140,20);
txtJK.setBounds(120,70,140,20);
lblAlamat.setBounds(10, 100, 140, 20);
txtAlamat.setBounds(120, 100, 140, 20);
lblTGL.setBounds(10, 130, 140, 20);
txtTGL.setBounds(120, 130, 140, 20);
lblEmail.setBounds(10, 160, 140, 20);
txtEmail.setBounds(120, 160, 140, 20);
btnOK.setBounds(150, 190, 100, 20);
}

@Override
public void actionPerformed(ActionEvent e) {
String file = "Buku Telepon.txt";
try {
FileWriter data = new FileWriter(file , true);
try(PrintWriter out = new PrintWriter(data)){
out.println("Nama :"+txtNama.getText());
out.println("Nomor Telepon :"+txtNmr.getText());
out.println("Jenis Kelamin :"+txtJK.getText());
out.println("Alamat :"+txtAlamat.getText());
out.println("Tanggal Lahir :"+txtTGL.getText());
out.println("Email :"+txtEmail.getText());
out.println("========================================");
out.close();
}
} catch (IOException ex) {
Logger.getLogger(bukuTelepon.class.getName()).log(Level.SEVERE, null, ex);
}
JOptionPane.showMessageDialog(null, "Telah Tersimpan", "Pemberitahuan", JOptionPane.INFORMATION_MESSAGE);
}}
==============================================================
main classnya


package tugas;

import javax.swing.JFrame;
public class mainBukuTelepon {
public static void main (String[]Args ) {
bukuTelepon jframe = new bukuTelepon();
jframe.setTitle("Buku Telepon");
jframe.setSize (300,280);
jframe.setVisible(true);
jframe.setResizable(false);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
----------------------------------------------------------------------------------------------------


No comments:

Post a Comment