Download Week2-3 Bahasa Pemrograman

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Bahasa Pemrograman
Pertemuan 2-3
Chaerul Anwar
Bahasa Pemrograman , Chaerul Anwar, MTI
Pengenalan Netbean
1
2
3
4
Project -> source project click kanan -> new -> jframe form
Bahasa Pemrograman , Chaerul Anwar, MTI
JCombo

The "JComboBox" in Netbeans displays a list of items for users.

The user chooses one of the items in the combo box that submits to your
processing form.

Netbeans has a graphical interface with a toolbox, so you only need to drag
and drop a JComboBox from the toolbox and add the items you want to
display without manually creating the code.
Bahasa Pemrograman , Chaerul Anwar, MTI
Menambah Item

Bahasa Pemrograman , Chaerul Anwar, MTI
Untuk mengganti item
Event

private void ComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
txtKeterangan.setText(jComboBox1.getSelectedItem()+"") ;
txtKeterangan1.setText(jComboBox1.getSelectedIndex()+"") ;
}
object jtxtField: txtKeterangan
object jtxtField: txtKeterangan1
Bahasa Pemrograman , Chaerul Anwar, MTI
Event cont…
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
txtKeterangan.setText(jComboBox1.getSelectedItem()+"");
txtKeterangan1.setText(jComboBox1.getSelectedIndex()+"");
int a=jComboBox1.getSelectedIndex();
if (a==0)
{txtGaji.setText(3000000+"");}
else if (a==1)
{txtGaji.setText(2400000+"");}
else
{txtGaji.setText(2000000+"");}
Object jtextField:txtGaji
Bahasa Pemrograman , Chaerul Anwar, MTI
}
Pallete
2
Radio Button
txtKeterangan1
txtKeterangan1.setText(jRadioButton1.getText()+"");
txtKeterangan1.setText(jRadioButton2.getText()+"");
Bahasa Pemrograman , Chaerul Anwar, MTI
1
private void
jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String result= " ";
if (jRadioButton1.isSelected())
{
result = jRadioButton1.getText();
}
if (jRadioButton2.isSelected())
{
result = jRadioButton2.getText();
}
JOptionPane.showMessageDialog(null,result);
}
Radio Button
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Container a = this.getContentPane();
a.setBackground(Color.RED);
}
private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt)
{
Container a = this.getContentPane();
a.setBackground(Color.YELLOW);
Bahasa Pemrograman , Chaerul Anwar, MTI
}
Latihan :

Buatlah form Ubah Warna Tulisan

====================================================
Untuk memberikan nilai kuning pada tulisan object jlabel gunakan method jLabel.setForeground(Color.yellow)
Untuk memberikan nilai kuning pada background jlabel gunakan method jLabel.setBackground(Color.yellow)
Centang opague pada properti jlabel
Latihan

Buatlah form mencari Deret

====================================================
JText Area
Bahasa Pemrograman , Chaerul Anwar, MTI
• Bersihkan nilai jTextArea terlebih dahulu untuk menghapus
nilai sebelumnya (jika sudah pernah dijalankan )
• Gunakan if untuk menentukan nilai tertinggi dan terendah
• Gunakan loop for ()
• Gunakan method append untuk mengisi nilai
Pada JTextArea
jTextArea1.append(String.valueOf(i) + " ");
Latihan

Buatlah form mencari Deret

====================================================
Bahasa Pemrograman , Chaerul Anwar, MTI
Latihan :

Buatlah form Penggajian :

====================================================
Nama : [
]
Jenis kelamin : option : () Lelaki
() Perempuan
Status Karyawan : combobox : Tetap, Tidak tetap
Status Perkawinan : combobox : menikah , lajang
Jumlah Tanggungan : text box [
]
Gaji Pokok : text box [
]
Tunjangan Keluarga : [
]
Simpan
Keluar

Ket : jika status karyawan tetap , maka gaji pokok 2,5 juta, jika tidak tetap : 1
juta

Jika status perkawinan menikah , anak 0 , tunjangan keluarga 2 juta

Jika status perkawinan menikah + anak max 3 , junjangan keluarga 2 juta+ jumlah
anak * 500 ribu

Jika status perkawinan lajang : tunjangan keluarga = 0
Hint : gunakan event lost focus pada text box jumlah tanggungan untuk mengisi
tunjangan
keluarga
Bahasa
Pemrograman , Chaerul
Anwar, MTI


Simpan ke file Gaji.txt
Related documents