Template TUGAS 9
Template TUGAS 9
Disusun Oleh:
Nama: Kadek Wahyu Mahendra
NIM: 2201020051
Soal:
1. Buatlah aplikasi biodata diri pada modul 9.
import javax.swing.JOptionPane;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*/
public class Swing extends javax.swing.JFrame {
private String nama,nim,jurusan,hobby,info,jeniskelamin,semester;
/**
* Creates new form Swing
*/
public Swing() {
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);
ta_hasil.setColumns(20);
ta_hasil.setRows(5);
jScrollPane1.setViewportView(ta_hasil);
rb_pria.setText("Pria");
rb_pria.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rb_priaActionPerformed(evt);
}
});
rb_wanita.setText("Wanita");
rb_wanita.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rb_wanitaActionPerformed(evt);
}
});
cb_makan.setText("Makan");
cb_makan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cb_makanActionPerformed(evt);
}
});
cb_balapan.setText("Balapan");
cb_tidur.setText("Tidur");
list_jurusan.setModel(new javax.swing.AbstractListModel<String>() {
String[] strings = { "TI - MDI", "TI - DGM", "TI - KAB", "TI - Par", "Sistem Komputer",
"Bisnis Digital", "Desain Komunikasi Visual" };
public int getSize() { return strings.length; }
public String getElementAt(int i) { return strings[i]; }
});
jScrollPane2.setViewportView(list_jurusan);
btn_bersih.setText("Bersihkan");
btn_bersih.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_bersihActionPerformed(evt);
}
});
btn_tampil.setText("Tampilkan");
btn_tampil.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_tampilActionPerformed(evt);
}
});
jLabel2.setText("Nama");
jLabel3.setText("NIM");
jLabel4.setText("Jenis Kelamin");
jLabel5.setText("Hobby");
jLabel6.setText("Jurusan");
jLabel7.setText("Semester");
pack();
}// </editor-fold>
if (rb_pria.isSelected())
jeniskelamin = "Pria";
else
jeniskelamin = "Wanita";
if (rb_wanita.isSelected())
jeniskelamin = "Wanita";
else
jeniskelamin = "Pria";
if (cb_makan.isSelected())
hobby = "Tidur";
if (cb_tidur.isSelected())
hobby = "Tidur";
if (cb_balapan.isSelected())
hobby = "Balapan";
jurusan = list_jurusan.getSelectedValue().toString();
semester = cmb_semester.getSelectedItem().toString();
info = "Nama : " +nama+"\n";
info += "NIM : " +nim+"\n";
info += "Jenis Kelamin : " +jeniskelamin+"\n";
info += "Hobby : " +hobby+"\n";
info += "Jurusan : " +jurusan+"\n";
info += "Semester : " +semester+"\n";
ta_hasil.setText(info);
JOptionPane.showMessageDialog(null, info);
/**
* @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(Swing.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Swing.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Swing.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Swing.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>