Program GUI ke 2

Pada kesempatan kali  ini kita akan membahas bagaimana cara membuat program GUI menggunakan net-beans.

Berikut ini adalah source code nya:

import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* Program2.java
*
* Created on Dec 5, 2011, 9:20:16 AM
*/

public class Program2 extends javax.swing.JFrame {

/** Creates new form Program2 */
private ButtonGroup gabung;
public Program2() {
initComponents();

gabung = new ButtonGroup();
gabung.add(cewe);
gabung.add(cowo);
}

/** 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() {

jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jNama = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
cowo = new javax.swing.JRadioButton();
cewe = new javax.swing.JRadioButton();
jComboBox1 = new javax.swing.JComboBox();
jLabel4 = new javax.swing.JLabel();
jHobi = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jEmail = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jNo = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
jAlamat = new javax.swing.JTextArea();
jPanel2 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton2 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel1.setBackground(new java.awt.Color(204, 204, 255));
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, “Form Biodata”, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));
jPanel1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jPanel1.setName(“jPanel1”);

jLabel1.setText(“Nama”);
jLabel1.setName(“jLabel1”);

jLabel2.setText(“Jenis Kelamin”);
jLabel2.setName(“jLabel2”);

jNama.setName(“jNama”);

jLabel3.setText(“Agama”);
jLabel3.setName(“jLabel3”);

cowo.setText(“Laki -Laki”);
cowo.setName(“cowo”);

cewe.setText(“Perempuan”);
cewe.setName(“cewe”);

jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { “Islam”, “Kristen”, “Hindu”, “Budha” }));
jComboBox1.setName(“jComboBox1”);
jComboBox1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
jComboBox1PropertyChange(evt);
}
});

jLabel4.setText(“Hobi”);
jLabel4.setName(“jLabel4”);

jHobi.setName(“jHobi”);

jLabel5.setText(“Email”);
jLabel5.setName(“jLabel5”);

jEmail.setName(“jEmail”);

jLabel6.setText(“No Telepon”);
jLabel6.setName(“jLabel6”);

jLabel7.setText(“Alamat”);
jLabel7.setName(“jLabel7”);

jNo.setName(“jNo”);

jButton1.setText(“PROSES”);
jButton1.setName(“jButton1”);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jScrollPane2.setName(“jScrollPane2”);

jAlamat.setColumns(20);
jAlamat.setRows(5);
jAlamat.setName(“jAlamat”);
jScrollPane2.setViewportView(jAlamat);

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(52, 52, 52)
.addComponent(jNama))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel5)
.addComponent(jLabel7))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(cowo)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cewe))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(1, 1, 1)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jHobi)
.addComponent(jEmail)
.addComponent(jNo))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 143, Short.MAX_VALUE))
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE))))
.addComponent(jLabel4)
.addComponent(jLabel6))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(157, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(144, 144, 144))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(cowo)
.addComponent(cewe))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jHobi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(jNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel7)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addComponent(jButton1))
);

jPanel2.setBackground(new java.awt.Color(204, 255, 204));
jPanel2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jPanel2.setName(“jPanel2”);

jScrollPane1.setName(“jScrollPane1”);

jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jTextArea1.setName(“jTextArea1”);
jScrollPane1.setViewportView(jTextArea1);

jButton2.setText(“EXIT”);
jButton2.setName(“jButton2″);
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addComponent(jButton2)
.addGap(156, 156, 156))))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
.addComponent(jButton2)
.addContainerGap())
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

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

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
cek();
String jk =””,agama;{
if (cowo.isSelected())
jk=”Laki-Laki”;
else if (cewe.isSelected())
jk=”Perempuan”;
}
agama = jComboBox1.getSelectedItem().toString();
jTextArea1.setText(“Biodata Anda Adalah :”+”\n”+”Nama : “+jNama.getText()+
“\n”+”Jenis Kelamin : “+jk+”\n”+”Agama : “+agama+”\n”+”Hobi : “+jHobi.getText()+
“\n”+”Alamat Email : “+jEmail.getText()+”\n”+”No Telepon : “+jNo.getText()+
“\n”+”Alamat : “+jAlamat.getText());
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int pan1=JOptionPane.showConfirmDialog(null,”Keluar dari aplikasi?”);
if (pan1==JOptionPane.OK_OPTION){
System.exit(1);}
else {
}
}

private void jComboBox1PropertyChange(java.beans.PropertyChangeEvent evt) {
// TODO add your handling code here:
}
private void cek(){
if (jNama.getText().isEmpty()||jHobi.getText().isEmpty()||
jEmail.getText().isEmpty()||jNo.getText().isEmpty()||jAlamat.getText().isEmpty());
{JOptionPane.showConfirmDialog(null,”Masih ada data yang kosong,harus diisi semua!!!”);
jTextArea1.setText(” “);}
}
/**
* @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.JRadioButton cewe;
private javax.swing.JRadioButton cowo;
private javax.swing.JTextArea jAlamat;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JTextField jEmail;
private javax.swing.JTextField jHobi;
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.JTextField jNama;
private javax.swing.JTextField jNo;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration
}

Algoritma :

program ini untuk memindahkan input dari textfield, radiobutton, combobox, dan area text.

pertama desain 7 label, 4 textfield, 2 radiobutton, 1 combobox, 2 textarea, dan 1 button.

7 label untuk memberi keterangan tiap textfieid, radiobutton, combobox, dan textarea.

pada button listing program nya seperti ini :

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
cek();
String jk =””,agama;{
if (cowo.isSelected())
jk=”Laki-Laki”;
else if (cewe.isSelected())
jk=”Perempuan”;
}
agama = jComboBox1.getSelectedItem().toString();
jTextArea1.setText(“Biodata Anda Adalah :”+”\n”+”Nama : “+jNama.getText()+
“\n”+”Jenis Kelamin : “+jk+”\n”+”Agama : “+agama+”\n”+”Hobi : “+jHobi.getText()+
“\n”+”Alamat Email : “+jEmail.getText()+”\n”+”No Telepon : “+jNo.getText()+
“\n”+”Alamat : “+jAlamat.getText());
}

pada listing ini nilai text dari tiap textfield, radiobutton, combobox, dan textarea akan di masukan ke textarea output.

pada button ke 2 list programnya :
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int pan1=JOptionPane.showConfirmDialog(null,”Keluar dari aplikasi?”);
if (pan1==JOptionPane.OK_OPTION){
System.exit(1);}
else {
}
}

pada button ini berfungsi untuk menutup form dari program aplikasi
pada listing program ini berfungsi untuk validasi:
private void jComboBox1PropertyChange(java.beans.PropertyChangeEvent evt) {
// TODO add your handling code here:
}
private void cek(){
if (jNama.getText().isEmpty()||jHobi.getText().isEmpty()||
jEmail.getText().isEmpty()||jNo.getText().isEmpty()||jAlamat.getText().isEmpty());
{JOptionPane.showConfirmDialog(null,”Masih ada data yang kosong,harus diisi semua!!!”);
jTextArea1.setText(” “);}
}

fungsi dari validasi adalah untuk menentukan bahwa textfield atau semua yang berkaitan dengan input tidak boleh kosong ketika di proses.

import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* Program2.java
*
* Created on Dec 5, 2011, 9:20:16 AM
*/

public class Program2 extends javax.swing.JFrame {

/** Creates new form Program2 */
private ButtonGroup gabung;
public Program2() {
initComponents();

gabung = new ButtonGroup();
gabung.add(cewe);
gabung.add(cowo);
}

/** 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() {

jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jNama = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
cowo = new javax.swing.JRadioButton();
cewe = new javax.swing.JRadioButton();
jComboBox1 = new javax.swing.JComboBox();
jLabel4 = new javax.swing.JLabel();
jHobi = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jEmail = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jNo = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
jAlamat = new javax.swing.JTextArea();
jPanel2 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton2 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel1.setBackground(new java.awt.Color(204, 204, 255));
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, “Form Biodata”, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));
jPanel1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jPanel1.setName(“jPanel1”); // NOI18N

jLabel1.setText(“Nama”);
jLabel1.setName(“jLabel1”); // NOI18N

jLabel2.setText(“Jenis Kelamin”);
jLabel2.setName(“jLabel2”); // NOI18N

jNama.setName(“jNama”); // NOI18N

jLabel3.setText(“Agama”);
jLabel3.setName(“jLabel3”); // NOI18N

cowo.setText(“Laki -Laki”);
cowo.setName(“cowo”); // NOI18N

cewe.setText(“Perempuan”);
cewe.setName(“cewe”); // NOI18N

jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { “Islam”, “Kristen”, “Hindu”, “Budha” }));
jComboBox1.setName(“jComboBox1”); // NOI18N
jComboBox1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
jComboBox1PropertyChange(evt);
}
});

jLabel4.setText(“Hobi”);
jLabel4.setName(“jLabel4”);

jHobi.setName(“jHobi”);

jLabel5.setText(“Email”);
jLabel5.setName(“jLabel5”);

jEmail.setName(“jEmail”);

jLabel6.setText(“No Telepon”);
jLabel6.setName(“jLabel6”);

jLabel7.setText(“Alamat”);
jLabel7.setName(“jLabel7”);

jNo.setName(“jNo”);

jButton1.setText(“PROSES”);
jButton1.setName(“jButton1”);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jScrollPane2.setName(“jScrollPane2”);

jAlamat.setColumns(20);
jAlamat.setRows(5);
jAlamat.setName(“jAlamat”);
jScrollPane2.setViewportView(jAlamat);

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(52, 52, 52)
.addComponent(jNama))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel5)
.addComponent(jLabel7))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(cowo)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cewe))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(1, 1, 1)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jHobi)
.addComponent(jEmail)
.addComponent(jNo))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 143, Short.MAX_VALUE))
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE))))
.addComponent(jLabel4)
.addComponent(jLabel6))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(157, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(144, 144, 144))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(cowo)
.addComponent(cewe))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jHobi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(jNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel7)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addComponent(jButton1))
);

jPanel2.setBackground(new java.awt.Color(204, 255, 204));
jPanel2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jPanel2.setName(“jPanel2”); // NOI18N

jScrollPane1.setName(“jScrollPane1”); // NOI18N

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

jButton2.setText(“EXIT”);
jButton2.setName(“jButton2″); // NOI18N
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addComponent(jButton2)
.addGap(156, 156, 156))))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
.addComponent(jButton2)
.addContainerGap())
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

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

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
cek();
String jk =””,agama;{
if (cowo.isSelected())
jk=”Laki-Laki”;
else if (cewe.isSelected())
jk=”Perempuan”;
}
agama = jComboBox1.getSelectedItem().toString();
jTextArea1.setText(“Biodata Anda Adalah :”+”\n”+”Nama : “+jNama.getText()+
“\n”+”Jenis Kelamin : “+jk+”\n”+”Agama : “+agama+”\n”+”Hobi : “+jHobi.getText()+
“\n”+”Alamat Email : “+jEmail.getText()+”\n”+”No Telepon : “+jNo.getText()+
“\n”+”Alamat : “+jAlamat.getText());
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int pan1=JOptionPane.showConfirmDialog(null,”Keluar dari aplikasi?”);
if (pan1==JOptionPane.OK_OPTION){
System.exit(1);}
else {
}
}

private void jComboBox1PropertyChange(java.beans.PropertyChangeEvent evt) {
// TODO add your handling code here:
}
private void cek(){
if (jNama.getText().isEmpty()||jHobi.getText().isEmpty()||
jEmail.getText().isEmpty()||jNo.getText().isEmpty()||jAlamat.getText().isEmpty());
{JOptionPane.showConfirmDialog(null,”Masih ada data yang kosong,harus diisi semua!!!”);
jTextArea1.setText(” “);}
}
/**
* @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.JRadioButton cewe;
private javax.swing.JRadioButton cowo;
private javax.swing.JTextArea jAlamat;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JTextField jEmail;
private javax.swing.JTextField jHobi;
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.JTextField jNama;
private javax.swing.JTextField jNo;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s