Java GUI – Program Biodata Mahasiswa

BIODATA MAHASISWA

Kali ini kita membuat sebuah aplikasi dektop dengan judul Biodata Mahasiswa 

adapun properti yang digunakan dalam perancangan formnya adalah :

1. Nama Mahasiswa —–> (Text Field)

2. Jenis Kelamin ——–> (Radio Button)

3. Agama ————> (ComboBox)

4. Alamat  ———> (Text Area)

5.Hobby  ———-> (Text Field)

6. email  ———–> (Text Field )

7. No. Telp  ——–> (Text Field)

8. Tombol Proses ——> (JButton)

9. Tombol Bersihkan ——> (JButton)   untuk memberihkan teks

10. Tombol Keluar ——–> (JButton)

Pada tombol keluar ini dibuat konfirmasi apakah program ini ingin di keluarkan atau tidak.

bentuk formnya dapat dilihat pada gambar berikut :


Listing Program

import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;

/**
 *
 * @author Ade Akbar
 */
public class Program2 extends javax.swing.JFrame {
private ButtonGroup gabung;
 /** Creates new form Program2 */
 public Program2() {

 super("Biodata Mahasiswa");
 initComponents();
 gabung=new ButtonGroup();
 gabung.add(btlaki);
 gabung.add(btpr);

 }

@SuppressWarnings("unchecked")
 // <editor-fold defaultstate="collapsed" desc="Generated Code">
 private void initComponents() {

panel1 = new javax.swing.JPanel();
 jLabel1 = new javax.swing.JLabel();
 txtnama = new javax.swing.JTextField();
 jLabel2 = new javax.swing.JLabel();
 btlaki = new javax.swing.JRadioButton();
 btpr = new javax.swing.JRadioButton();
 box = new javax.swing.JComboBox();
 jLabel3 = new javax.swing.JLabel();
 jLabel5 = new javax.swing.JLabel();
 jLabel7 = new javax.swing.JLabel();
 txtemail = new javax.swing.JTextField();
 jLabel6 = new javax.swing.JLabel();
 txthobi = new javax.swing.JTextField();
 jScrollPane1 = new javax.swing.JScrollPane();
 jTextArea1 = new javax.swing.JTextArea();
 jLabel8 = new javax.swing.JLabel();
 txtnotlp = new javax.swing.JTextField();
 jButton1 = new javax.swing.JButton();
 exit = new javax.swing.JButton();
 jButton2 = new javax.swing.JButton();
 jLabel4 = new javax.swing.JLabel();
 jPanel1 = new javax.swing.JPanel();
 jScrollPane2 = new javax.swing.JScrollPane();
 output1 = new javax.swing.JTextArea();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

panel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Data Mahasiswa"));
 panel1.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
 panel1.setName("panel1"); // NOI18N

jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
 jLabel1.setText("Nama");
 jLabel1.setName("jLabel1"); // NOI18N

txtnama.setName("txtnama"); // NOI18N

jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
 jLabel2.setText("Jenis Kelamin");
 jLabel2.setName("jLabel2"); // NOI18N

btlaki.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
 btlaki.setText("Laki");
 btlaki.setName("btlaki"); // NOI18N

btpr.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
 btpr.setText("Perempuan");
 btpr.setName("btpr"); // NOI18N

box.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
 box.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Islam", "KritenKhatolik", "Kristen Protestan", "Hindu", "Budha", "Konghucu" }));
 box.setName("box"); // NOI18N

jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
 jLabel3.setText("Agama");
 jLabel3.setName("jLabel3"); // NOI18N

jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
 jLabel5.setText("Alamat");
 jLabel5.setName("jLabel5"); // NOI18N

jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
 jLabel7.setText("Email");
 jLabel7.setName("jLabel7"); // NOI18N

txtemail.setName("txtemail"); // NOI18N

jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
 jLabel6.setText("Hobi");
 jLabel6.setName("jLabel6"); // NOI18N

txthobi.setName("txthobi"); // NOI18N

jScrollPane1.setName("jScrollPane1"); // NOI18N

jTextArea1.setColumns(20);
 jTextArea1.setRows(5);
 jTextArea1.setName("jTextArea1"); // NOI18N
 jScrollPane1.setViewportView(jTextArea1);

jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
 jLabel8.setText("No Telepon");
 jLabel8.setName("jLabel8"); // NOI18N

txtnotlp.setName("txtnotlp"); // NOI18N

jButton1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
 jButton1.setText("PROSES");
 jButton1.setName("jButton1"); // NOI18N
 jButton1.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 jButton1ActionPerformed(evt);
 }
 });

exit.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
 exit.setText("KELUAR");
 exit.setName("exit"); // NOI18N
 exit.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 exitActionPerformed(evt);
 }
 });

jButton2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
 jButton2.setText("Bersihkan");
 jButton2.setName("jButton2"); // NOI18N
 jButton2.addActionListener(new java.awt.event.ActionListener() {
 public void actionPerformed(java.awt.event.ActionEvent evt) {
 jButton2ActionPerformed(evt);
 }
 });

javax.swing.GroupLayout panel1Layout = new javax.swing.GroupLayout(panel1);
 panel1.setLayout(panel1Layout);
 panel1Layout.setHorizontalGroup(
 panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(panel1Layout.createSequentialGroup()
 .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addComponent(jLabel1)
 .addComponent(jLabel2)
 .addComponent(jLabel5)
 .addComponent(jLabel6)
 .addComponent(jLabel3)
 .addComponent(jLabel7)
 .addComponent(jLabel8))
 .addGap(18, 18, 18)
 .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(panel1Layout.createSequentialGroup()
 .addComponent(txthobi, javax.swing.GroupLayout.DEFAULT_SIZE, 539, Short.MAX_VALUE)
 .addContainerGap())
 .addComponent(box, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 549, Short.MAX_VALUE)
 .addGroup(panel1Layout.createSequentialGroup()
 .addComponent(btlaki)
 .addGap(18, 18, 18)
 .addComponent(btpr))
 .addComponent(txtnama, javax.swing.GroupLayout.DEFAULT_SIZE, 549, Short.MAX_VALUE)
 .addGroup(panel1Layout.createSequentialGroup()
 .addComponent(txtemail, javax.swing.GroupLayout.DEFAULT_SIZE, 539, Short.MAX_VALUE)
 .addContainerGap())
 .addGroup(panel1Layout.createSequentialGroup()
 .addComponent(txtnotlp, javax.swing.GroupLayout.DEFAULT_SIZE, 539, Short.MAX_VALUE)
 .addContainerGap())))
 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel1Layout.createSequentialGroup()
 .addContainerGap(310, Short.MAX_VALUE)
 .addComponent(jButton1)
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
 .addComponent(jButton2)
 .addGap(13, 13, 13)
 .addComponent(exit)
 .addGap(36, 36, 36))
 );
 panel1Layout.setVerticalGroup(
 panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(panel1Layout.createSequentialGroup()
 .addContainerGap()
 .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 .addComponent(jLabel1)
 .addComponent(txtnama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
 .addGap(18, 18, 18)
 .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 .addComponent(jLabel2)
 .addComponent(btlaki)
 .addComponent(btpr))
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
 .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 .addComponent(jLabel3)
 .addComponent(box, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
 .addGap(12, 12, 12)
 .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addComponent(jLabel5)
 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE))
 .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(panel1Layout.createSequentialGroup()
 .addGap(11, 11, 11)
 .addComponent(jLabel6))
 .addGroup(panel1Layout.createSequentialGroup()
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addComponent(txthobi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
 .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addComponent(txtemail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(jLabel7))
 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 .addComponent(txtnotlp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(jLabel8))
 .addGap(18, 18, 18)
 .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 .addComponent(exit)
 .addComponent(jButton1)
 .addComponent(jButton2))
 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 );

jLabel4.setFont(new java.awt.Font("Tahoma", 3, 14)); // NOI18N
 jLabel4.setText("FORM BIODATA");
 jLabel4.setName("jLabel4"); // NOI18N

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("output"));
 jPanel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
 jPanel1.setName("jPanel1"); // NOI18N

jScrollPane2.setName("jScrollPane2"); // NOI18N

output1.setColumns(20);
 output1.setRows(5);
 output1.setName("output1"); // NOI18N
 jScrollPane2.setViewportView(output1);

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
 jPanel1.setLayout(jPanel1Layout);
 jPanel1Layout.setHorizontalGroup(
 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(jPanel1Layout.createSequentialGroup()
 .addContainerGap()
 .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 542, Short.MAX_VALUE)
 .addContainerGap())
 );
 jPanel1Layout.setVerticalGroup(
 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
 );

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
 getContentPane().setLayout(layout);
 layout.setHorizontalGroup(
 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(layout.createSequentialGroup()
 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(panel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addComponent(jLabel4)))
 );
 layout.setVerticalGroup(
 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 .addGroup(layout.createSequentialGroup()
 .addContainerGap(16, Short.MAX_VALUE)
 .addComponent(jLabel4)
 .addGap(18, 18, 18)
 .addComponent(panel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 .addGap(18, 18, 18)
 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
 );

jPanel1.getAccessibleContext().setAccessibleName("");

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

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:

 String JK, agama;
 if (btlaki.isSelected())
 {
 JK = "Laki-laki";
 }
 else
 {
 JK="Perempuan";

 }
 agama = box.getSelectedItem().toString();

 output1.setText("Nama : " + txtnama.getText() + "\n" + "Jenis Kelamin :"+ JK + "\n" +"Agama :"+ agama +"\n" +"Alamat : " +jTextArea1.getText()+"\n"
 + "Hobi :" +txthobi.getText() +"\n" +"Email :" + txtemail.getText() +"\n" + "No Telepon :" +txtnotlp.getText());
}

private void exitActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
 int mesage=JOptionPane. showConfirmDialog(null, "Apakah Anda Yakin Keluar");
 if (mesage==JOptionPane.OK_OPTION)
 System.exit(1);
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
 txtnama.setText(null);
 jTextArea1.setText(null);
 txthobi.setText(null);
 txtemail.setText(null);
}
 /**
 * @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(Program2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
 } catch (InstantiationException ex) {
 java.util.logging.Logger.getLogger(Program2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
 } catch (IllegalAccessException ex) {
 java.util.logging.Logger.getLogger(Program2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
 java.util.logging.Logger.getLogger(Program2.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 Program2().setVisible(true);
 }
 });
 }
 // Variables declaration - do not modify
 private javax.swing.JComboBox box;
 private javax.swing.JRadioButton btlaki;
 private javax.swing.JRadioButton btpr;
 private javax.swing.JButton exit;
 private javax.swing.JButton jButton1;
 private javax.swing.JButton jButton2;
 private javax.swing.JLabel jLabel1;
 private javax.swing.JLabel jLabel2;
 private javax.swing.JLabel jLabel3;
 private javax.swing.JLabel jLabel4;
 private javax.swing.JLabel jLabel5;
 private javax.swing.JLabel jLabel6;
 private javax.swing.JLabel jLabel7;
 private javax.swing.JLabel jLabel8;
 private javax.swing.JPanel jPanel1;
 private javax.swing.JScrollPane jScrollPane1;
 private javax.swing.JScrollPane jScrollPane2;
 private javax.swing.JTextArea jTextArea1;
 private javax.swing.JTextArea output1;
 private javax.swing.JPanel panel1;
 private javax.swing.JTextField txtemail;
 private javax.swing.JTextField txthobi;
 private javax.swing.JTextField txtnama;
 private javax.swing.JTextField txtnotlp;
 // End of variables declaration
}

Output Program

About Ade Akbar

Hidup, Berarti dan Mati

Posted on Desember 6, 2011, in Program Java. Bookmark the permalink. 2 Komentar.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: