Pengaturan Variable Name:
Klik Kanan > Change Variable Name
Klik Kanan > Change Variable Name
- JTextField (txtnip, txtnama, xtgapok, txtistri, txtjumlah, txtanak, txtgator, txtpajak, txtgaber)
- JComboBox (cmbjabatan)
- JRadioButton (opsi1,opsi2)
- JButton (btnbersih, btnhitung)
- JButton (btnbersih, btnhitung)
- int gapok;
- int gator;
- int pajak;
- int gaber;
- int t_istri;
- int t_anak;
- int j_anak;
- String t_istri_1;
- String t_anak_1;
- String gator_1;
- String pajak_1;
- String gaber_1;
Pastikan atur properties variabel name pada jframe sebelum mengetik kode program dibawah ini:
- public jfrmGaji() {
- setTitle("Aplikasi Perhitungan Gaji");
- initComponents();
- }
- private void gaji(){
- int pilihan=cmbjabatan.getSelectedIndex();
- switch(pilihan){
- case 0:
- txtgapok.setText("7500000");
- break;
- case 1:
- txtgapok.setText("5000000");
- break;
- case 2:
- txtgapok.setText("3000000");
- break;
- case 3:
- txtgapok.setText("2000000");
- break;
- case 4:
- txtgapok.setText("1200000");
- break;
- case 5:
- txtgapok.setText("750000");
- break;
- }
- }
- private void kawin(){
- txtistri.setEnabled(true);
- txtanak.setEnabled(true);
- txtjumlah.setEnabled(true);
- gapok=Integer.valueOf(txtgapok.getText());
- t_istri=(20*gapok)/100;
- t_istri_1=String.valueOf(t_istri);
- txtistri.setText(t_istri_1);
- if(txtjumlah.getText()!=""||txtjumlah.getText()!="0"){
- j_anak=Integer.valueOf(txtjumlah.getText());
- if(j_anak<=2&&j_anak>=1){
- t_anak=((15*gapok)/100)*j_anak;
- }else if(j_anak>2){
- t_anak=((15*gapok)/100)*2;
- }else{
- t_anak=0;
- }
- t_anak_1=String.valueOf(t_anak);
- txtanak.setText(t_anak_1);
- }
- }
- private void tidakkawin(){
- t_istri=0;
- t_anak=0;
- j_anak=0;
- txtistri.setText("0");
- txtanak.setText("0");
- txtjumlah.setText("0");
- txtistri.setEnabled(false);
- txtanak.setEnabled(false);
- txtjumlah.setEnabled(false);
- }
- private void total(){
- gapok=Integer.valueOf(txtgapok.getText());
- if(opsi1.isSelected()==true){
- gator=gapok+t_anak+t_istri;
- }else{
- gator=gapok;
- }
- pajak=(gator*10)/100;
- gaber=gator-pajak;
- gator_1=String.valueOf(gator);
- pajak_1=String.valueOf(pajak);
- gaber_1=String.valueOf(gaber);
- txtgator.setText(gator_1);
- txtpajak.setText(pajak_1);
- txtgaber.setText(gaber_1);
- }
- private void bersih(){
- gapok=0;
- gator=0;
- pajak=0;
- gaber=0;
- t_istri=0;
- t_anak=0;
- j_anak=0;
- txtgapok.setText("0");
- txtistri.setText("0");
- txtjumlah.setText("0");
- txtanak.setText("0");
- txtgator.setText("0");
- txtpajak.setText("0");
- txtgaber.setText("0");
- }
Ketik kode program dibawah @SuppressWarnings("unchecked"):
- private void btnhitungMouseClicked(java.awt.event.MouseEvent evt) {
- // TODO add your handling code here:
- total();
- }
- private void btnbersihMouseClicked(java.awt.event.MouseEvent evt) {
- // TODO add your handling code here:
- bersih();
- }
- private void cmbjabatanItemStateChanged(java.awt.event.ItemEvent evt) {
- // TODO add your handling code here:
- bersih();
- }
- private void cmbjabatanActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- gaji();
- if(opsi1.isSelected()==true){
- kawin();
- }else{
- tidakkawin();
- }
- }
- private void opsi1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- kawin();
- }
- private void opsi2ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- tidakkawin();
- }
- private void txtjumlahKeyReleased(java.awt.event.KeyEvent evt) {
- // TODO add your handling code here:
- kawin();
- }
Selanjutnya, untuk melihat hasil programnya klik kanan Name Project > Run
Semoga berhasil :)