package shkalkulator; import java.awt.Color; import javax.swing.*; /** * @author Soni Hendarkanto PTI 4B * With Apache NetBeans IDE 16, Belsoft JAVA JDK 19 * on Linux Mint 21.1 "VERA" Cinnamon Desktop Edition * * My github for this project: https://github.com/Soni-Hendar-Kip/SHKalkulator * * link tutor: * original version from pak dosen rozi */ public class NoxKalkulatorVersiDosenRozi extends javax.swing.JFrame { String TandaHitung=""; //untuk mewakili simbol operator hitung +-/* String LayarAwal; //untuk mewakili layar awal boolean FirstClick=false; double Angka_ke1 = 0; //untuk mewakili angka pertama yg akan di hitung pada kalkulator double Angka_ke2 = 0; //untuk mewakili angka kedua double Hasil_Hitung; //untuk mewakili hasil perhitungan public NoxKalkulatorVersiDosenRozi() { initComponents(); } public void AturTextLayar(String k){ LayarAwal = NoxLayar_.getText(); if(LayarAwal.equals("0")) { LayarAwal=LayarAwal.replace("0",""); } if(!TandaHitung.equals("") && FirstClick) { NoxLayar_.setText(k); FirstClick=false; } else{ NoxLayar_.setText(LayarAwal+k); } } public void AturWarnaTombolAngka(boolean yes_or_no){ setBackground(Color.yellow); } public void HilangkanWarnaTombol(boolean yes_or_no){ NoxBt0_.setBackground(Color.LIGHT_GRAY); NoxBt1_.setBackground(Color.LIGHT_GRAY); NoxBt2_.setBackground(Color.LIGHT_GRAY); NoxBt3_.setBackground(Color.LIGHT_GRAY); NoxBt4_.setBackground(Color.LIGHT_GRAY); NoxBt5_.setBackground(Color.LIGHT_GRAY); NoxBt6_.setBackground(Color.LIGHT_GRAY); NoxBt7_.setBackground(Color.LIGHT_GRAY); NoxBt8_.setBackground(Color.LIGHT_GRAY); NoxBt9_.setBackground(Color.LIGHT_GRAY); NoxBtBagi_.setBackground(Color.LIGHT_GRAY); NoxBtClear_.setBackground(Color.LIGHT_GRAY); NoxBtKali_.setBackground(Color.LIGHT_GRAY); NoxBtKoma_.setBackground(Color.LIGHT_GRAY); NoxBtKurang_.setBackground(Color.LIGHT_GRAY); NoxBtPersen_.setBackground(Color.LIGHT_GRAY); NoxBtSamaDengan_.setBackground(Color.LIGHT_GRAY); NoxBtTambah_.setBackground(Color.LIGHT_GRAY); } /** * 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. */ private void NoxBt9_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: AturTextLayar("9"); HilangkanWarnaTombol(true); NoxBt9_.setBackground(Color.GREEN); } private void NoxBt6_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: AturTextLayar("6"); HilangkanWarnaTombol(true); NoxBt6_.setBackground(Color.GREEN); } private void NoxBt5_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: AturTextLayar("5"); HilangkanWarnaTombol(true); NoxBt5_.setBackground(Color.GREEN); } private void NoxBt2_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: AturTextLayar("2"); HilangkanWarnaTombol(true); NoxBt2_.setBackground(Color.GREEN); } private void NoxBt3_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: AturTextLayar("3"); HilangkanWarnaTombol(true); NoxBt3_.setBackground(Color.GREEN); } private void NoxBtClear_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: NoxLayar_.setText(""); HilangkanWarnaTombol(true); NoxBtClear_.setBackground(Color.blue); } private void NoxBtTambah_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: TandaHitung = "+"; FirstClick = true; Angka_ke1=Double.parseDouble(NoxLayar_.getText()); HilangkanWarnaTombol(true); NoxBtTambah_.setBackground(Color.YELLOW); } private void NoxBtKurang_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: TandaHitung = "-"; FirstClick = true; Angka_ke1 = Double.parseDouble(NoxLayar_.getText()); HilangkanWarnaTombol(true); NoxBtKurang_.setBackground(Color.YELLOW); } private void NoxBtKali_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: TandaHitung = "*"; FirstClick = true; Angka_ke1 = Double.parseDouble(NoxLayar_.getText()); HilangkanWarnaTombol(true); NoxBtKali_.setBackground(Color.YELLOW); } private void NoxBtBagi_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: TandaHitung = "/"; FirstClick = true; Angka_ke1 = Double.parseDouble(NoxLayar_.getText()); HilangkanWarnaTombol(true); NoxBtBagi_.setBackground(Color.YELLOW); } private void NoxBtKoma_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: AturTextLayar("."); //koma dalam inggris menjadi . (titik) HilangkanWarnaTombol(true); NoxBtKoma_.setBackground(Color.YELLOW); } private void NoxBtPersen_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: JOptionPane.showMessageDialog(null, "sorry belum berfungsi"); } private void NoxBtSamaDengan_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Hasil_Hitung = 0; Angka_ke2 = Double.parseDouble(NoxLayar_.getText()); if (TandaHitung == "+"){ Hasil_Hitung = Angka_ke1 + Angka_ke2 ; } else if (TandaHitung == "-"){ Hasil_Hitung = Angka_ke1 - Angka_ke2 ; } else if (TandaHitung == "*"){ Hasil_Hitung = Angka_ke1 * Angka_ke2 ; } else if (TandaHitung == "/"){ Hasil_Hitung = Angka_ke1 / Angka_ke2 ; } String SHasil = Double.toString(Hasil_Hitung); NoxLayar_.setText(SHasil); HilangkanWarnaTombol(true); NoxBtSamaDengan_.setBackground(Color.RED); } private void NoxBtAbout_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void NoxBt7_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: AturTextLayar("7"); HilangkanWarnaTombol(true); NoxBt7_.setBackground(Color.GREEN); } private void NoxBt8_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: AturTextLayar("8"); HilangkanWarnaTombol(true); NoxBt8_.setBackground(Color.GREEN); } private void NoxBt4_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: AturTextLayar("4"); HilangkanWarnaTombol(true); NoxBt4_.setBackground(Color.GREEN); } private void NoxBt1_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: AturTextLayar("1"); HilangkanWarnaTombol(true); NoxBt1_.setBackground(Color.GREEN); } private void NoxBt0_ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: AturTextLayar("0"); HilangkanWarnaTombol(true); NoxBt0_.setBackground(Color.GREEN); } /** * @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(NoxKalkulatorVersiDosenRozi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(NoxKalkulatorVersiDosenRozi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(NoxKalkulatorVersiDosenRozi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(NoxKalkulatorVersiDosenRozi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new NoxKalkulatorVersiDosenRozi().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton NoxBt0_; private javax.swing.JButton NoxBt1_; private javax.swing.JButton NoxBt2_; private javax.swing.JButton NoxBt3_; private javax.swing.JButton NoxBt4_; private javax.swing.JButton NoxBt5_; private javax.swing.JButton NoxBt6_; private javax.swing.JButton NoxBt7_; private javax.swing.JButton NoxBt8_; private javax.swing.JButton NoxBt9_; private javax.swing.JButton NoxBtAbout_; private javax.swing.JButton NoxBtBagi_; private javax.swing.JButton NoxBtClear_; private javax.swing.JButton NoxBtKali_; private javax.swing.JButton NoxBtKoma_; private javax.swing.JButton NoxBtKurang_; private javax.swing.JButton NoxBtPersen_; private javax.swing.JButton NoxBtSamaDengan_; private javax.swing.JButton NoxBtTambah_; private javax.swing.JTextField NoxLayar_; private javax.swing.JLabel jLabel1; private javax.swing.JPanel jPanel1; // End of variables declaration }
Selasa, 23 Mei 2023
Kalkulator Anti Mumet V-Dos
Langganan:
Posting Komentar (Atom)

Tidak ada komentar:
Posting Komentar