package pmodul3;
import javax.swing.DefaultListModel;
public class fDaftar extends javax.swing.JFrame {
DefaultListModel pilih;
/** Creates new form fDaftar */
public fDaftar() {
initComponents();
pilih = new DefaultListModel();
lstPilih.setModel(pilih);
txtKuliah.setEditable(false);
txtTerpilih.setEditable(false);
txtTerpilih.setText("0");
txtResume.setEditable(false);
}
private void lstKuliahValueChanged(javax.swing.event.ListSelectionEvent evt) {
// TODO add your handling code here:
int index = lstKuliah.getSelectedIndex();
String kuliah = lstKuliah.getSelectedValue().toString();
txtKuliah.setText(kuliah);
}
private void btnCopyActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
pilih.addElement(lstKuliah.getSelectedValue().toString());
int size = pilih.getSize();
txtTerpilih.setText(Integer.toString(size));
}
private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int index = lstPilih.getSelectedIndex();
pilih.remove(index);
int size = pilih.getSize();
txtTerpilih.setText(Integer.toString(size));
}
private void btnHitungActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int nPilih = Integer.parseInt(txtTerpilih.getText());
int i = cboAngkatan.getSelectedIndex();
String isian = cboAngkatan.getSelectedItem().toString();
// hitung Biaya
int nPerMK = 0;
switch (i) {
case 0:nPerMK = 100000;break;
case 1:nPerMK = 90000;break;
case 2:nPerMK = 75000;break;
default : nPerMK = 50000;
}
int nBiaya = nPerMK * nPilih;
// Isikan Resume Ke textArea txtResume
String sResume = "Anda Angkatan : "+isian+"\n"+
"Banyak Mata Kuliah dipilih :"+
Integer.toString(nPilih)+"\n"+
"Biaya Per Mata Kuliah : "+
Integer.toString(nPerMK)+"\n"+
"TOTAL BIAYA : "+Integer.toString(nBiaya);
txtResume.setText(sResume);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new fDaftar().setVisible(true);
}
});
}
private javax.swing.JButton btnCopy;
private javax.swing.JButton btnHapus;
private javax.swing.JButton btnHitung;
private javax.swing.JComboBox cboAngkatan;
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.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JList lstKuliah;
private javax.swing.JList lstPilih;
private javax.swing.JTextField txtKuliah;
private javax.swing.JTextArea txtResume;
private javax.swing.JTextField txtTerpilih;
output
Latihan
packagelatihan;
importjavax.swing.DefaultListModel;
public class latihan extends javax.swing.JFrame {
DefaultListModelpilih,kuliah;
/** Creates new
form latihan */
publiclatihan() {
initComponents();
kuliah = new DefaultListModel();
lstKuliah.setModel(kuliah);
pilih = new DefaultListModel();
lstPilih.setModel(pilih);
kuliah.addElement("Java Dekstop");
kuliah.addElement("Pemograman Web");
kuliah.addElement("BahasaInggris");
kuliah.addElement("LogikadanAlgoritma");
kuliah.addElement("OrganisasiKomputer");
}
private void
btnPindahActionPerformed(java.awt.event.ActionEventevt) {
// TODO add
your handling code here:
pilih.addElement(lstKuliah.getSelectedValue().toString());
kuliah.removeElementAt(lstKuliah.getSelectedIndex());
lstKuliah.updateUI();
}
private void
lstKuliahValueChanged(javax.swing.event.ListSelectionEventevt) {
// TODO add
your handling code here:
}
private void
btnHapusActionPerformed(java.awt.event.ActionEventevt) {
// TODO add
your handling code here:
kuliah.addElement(lstPilih.getSelectedValue().toString());
pilih.removeElementAt(lstPilih.getSelectedIndex());
lstPilih.updateUI();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
newlatihan().setVisible(true);
}
});
}
// Variables
declaration - do not modify
privatejavax.swing.JButtonbtnHapus;
privatejavax.swing.JButtonbtnPindah;
privatejavax.swing.JLabel jLabel1;
privatejavax.swing.JLabel jLabel2;
privatejavax.swing.JScrollPane jScrollPane1;
privatejavax.swing.JScrollPane jScrollPane2;
privatejavax.swing.JListlstKuliah;
privatejavax.swing.JListlstPilih;
// End of
variables declaration
}
output
Tidak ada komentar:
Posting Komentar