0% found this document useful (0 votes)
30 views12 pages

Template TUGAS 9

Uploaded by

ashurabara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views12 pages

Template TUGAS 9

Uploaded by

ashurabara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

TUGAS 9

Object Oriented Programming B

Disusun Oleh:
Nama: Kadek Wahyu Mahendra
NIM: 2201020051
Soal:
1. Buatlah aplikasi biodata diri pada modul 9.

Screenshot Jform (desain GUI Swing)

Sintak Class Biodata

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

jSeparator1 = new javax.swing.JSeparator();


jScrollBar1 = new javax.swing.JScrollBar();
jLabel1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
ta_hasil = new javax.swing.JTextArea();
txt_nama = new javax.swing.JTextField();
txt_nim = new javax.swing.JTextField();
rb_pria = new javax.swing.JRadioButton();
rb_wanita = new javax.swing.JRadioButton();
cb_makan = new javax.swing.JCheckBox();
cb_balapan = new javax.swing.JCheckBox();
cb_tidur = new javax.swing.JCheckBox();
jScrollPane2 = new javax.swing.JScrollPane();
list_jurusan = new javax.swing.JList<>();
cmb_semester = new javax.swing.JComboBox<>();
btn_bersih = new javax.swing.JButton();
btn_tampil = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N


jLabel1.setText("Data Mahasiswa");

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);

cmb_semester.setModel(new javax.swing.DefaultComboBoxModel<>(new String[]


{ "Semester 1", "Semester 2", "Semester 3", "Semester 4", "Semester 5", "Semester 6",
"Semester 7", "Semester 8", "Semester 9", "Semester 10" }));

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");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());


getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel6)
.addComponent(jLabel7))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addGroup(layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(cb_makan, javax.swing.GroupLayout.PREFERRED_SIZE, 56,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cb_tidur)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELAT
ED)
.addComponent(cb_balapan))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING, false)
.addComponent(txt_nama)
.addComponent(txt_nim, javax.swing.GroupLayout.DEFAULT_SIZE, 195,
Short.MAX_VALUE)
.addComponent(cmb_semester, 0,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE,
195, Short.MAX_VALUE))))
.addComponent(jLabel5)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(rb_pria)
.addGap(18, 18, 18)
.addComponent(rb_wanita)))
.addGap(0, 34, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(btn_bersih)
.addGap(18, 18, 18)
.addComponent(btn_tampil)
.addGap(23, 23, 23))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 224,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1)
.addGap(165, 165, 165))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILIN
G)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BAS
ELINE)
.addComponent(txt_nama, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BAS
ELINE)
.addComponent(txt_nim, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BAS
ELINE)
.addComponent(jLabel4)
.addComponent(rb_pria)
.addComponent(rb_wanita))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BAS
ELINE)
.addComponent(jLabel5)
.addComponent(cb_tidur, javax.swing.GroupLayout.PREFERRED_SIZE, 15,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cb_balapan)
.addComponent(cb_makan, javax.swing.GroupLayout.PREFERRED_SIZE, 20,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(20, 20, 20)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addComponent(jLabel6)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 54,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BAS
ELINE)
.addComponent(jLabel7)
.addComponent(cmb_semester, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 257,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52,
Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELIN
E)
.addComponent(btn_bersih)
.addComponent(btn_tampil))
.addGap(46, 46, 46))
);

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

private void rb_wanitaActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

private void cb_makanActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

private void btn_tampilActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
nama = txt_nama.getText();
nim = txt_nim.getText();

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);

private void btn_bersihActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
txt_nama.setText("");
txt_nim.setText("");
rb_pria.setSelected(false);
rb_wanita.setSelected(false);
cb_makan.setSelected(false);
cb_tidur.setSelected(false);
cb_balapan.setSelected(false);
list_jurusan.clearSelection();
cmb_semester.setSelectedIndex(0);
ta_hasil.setText("");
}

private void rb_priaActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

/**
* @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>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Swing().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.JButton btn_bersih;
private javax.swing.JButton btn_tampil;
private javax.swing.JCheckBox cb_balapan;
private javax.swing.JCheckBox cb_makan;
private javax.swing.JCheckBox cb_tidur;
private javax.swing.JComboBox<String> cmb_semester;
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.JScrollBar jScrollBar1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JList<String> list_jurusan;
private javax.swing.JRadioButton rb_pria;
private javax.swing.JRadioButton rb_wanita;
private javax.swing.JTextArea ta_hasil;
private javax.swing.JTextField txt_nama;
private javax.swing.JTextField txt_nim;
// End of variables declaration
}

Screenshot Hasil Saat Sistem Run

Foto diatas merupakan kondisi Ketika tombol bersihkan di klik

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy