faiz14

uas

Jan 12th, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 36.30 KB | None | 0 0
  1.  
  2. import java.awt.event.KeyEvent;
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import javax.swing.JOptionPane;
  8. import java.sql.Statement;
  9. import javax.swing.table.DefaultTableModel;
  10. import java.awt.event.KeyEvent;
  11.  
  12. /*
  13.  * To change this license header, choose License Headers in Project Properties.
  14.  * To change this template file, choose Tools | Templates
  15.  * and open the template in the editor.
  16.  */
  17.  
  18. /**
  19.  *
  20.  * @author User
  21.  */
  22. public class madusiswa extends javax.swing.JFrame {
  23.     private Connection koneksi;
  24.     /**
  25.      * Creates new form biodata
  26.      */
  27.     public madusiswa() {
  28.         initComponents();
  29.         KoneksiDatabase();
  30.         TampilDatabase();
  31.         this.setLocationRelativeTo(null);
  32.     }        
  33.         void filterhuruf(KeyEvent a){
  34.         if(Character.isAlphabetic(a.getKeyChar())){
  35.             a.consume();
  36.             JOptionPane.showMessageDialog(null,"Pada Kolom Umur Hanya Bisa Memasukan Karakter Angka");
  37.         }
  38.     }
  39.         void filterangka(KeyEvent b){
  40.         if(Character.isDigit(b.getKeyChar())){
  41.             b.consume();
  42.             JOptionPane.showMessageDialog(null,"Pada Kolom Nama Hanya Bisa Memasukan Karakter Huruf");
  43.         }
  44.     }
  45.        
  46.        
  47.  
  48.     /**
  49.      * This method is called from within the constructor to initialize the form.
  50.      * WARNING: Do NOT modify this code. The content of this method is always
  51.      * regenerated by the Form Editor.
  52.      */
  53.     @SuppressWarnings("unchecked")
  54.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  55.     private void initComponents() {
  56.  
  57.         buttonGroup1 = new javax.swing.ButtonGroup();
  58.         buttonGroup2 = new javax.swing.ButtonGroup();
  59.         buttonGroup3 = new javax.swing.ButtonGroup();
  60.         jPanel1 = new javax.swing.JPanel();
  61.         jLabel1 = new javax.swing.JLabel();
  62.         jLabel2 = new javax.swing.JLabel();
  63.         jLabel3 = new javax.swing.JLabel();
  64.         jLabel4 = new javax.swing.JLabel();
  65.         jLabel5 = new javax.swing.JLabel();
  66.         txtnama = new javax.swing.JTextField();
  67.         txtmapel = new javax.swing.JTextField();
  68.         simpan = new javax.swing.JButton();
  69.         keluar = new javax.swing.JButton();
  70.         jLabel7 = new javax.swing.JLabel();
  71.         txtnis = new javax.swing.JTextField();
  72.         jLabel8 = new javax.swing.JLabel();
  73.         txtjurusan = new javax.swing.JComboBox<String>();
  74.         hapus = new javax.swing.JButton();
  75.         edit = new javax.swing.JButton();
  76.         jLabel6 = new javax.swing.JLabel();
  77.         jLabel9 = new javax.swing.JLabel();
  78.         txtkelas = new javax.swing.JComboBox<String>();
  79.         jButton1 = new javax.swing.JButton();
  80.         jScrollPane1 = new javax.swing.JScrollPane();
  81.         tabelsiswa = new javax.swing.JTable();
  82.         txtketerangan = new javax.swing.JTextField();
  83.         jLabel10 = new javax.swing.JLabel();
  84.         txtnilai = new javax.swing.JTextField();
  85.         jLabel11 = new javax.swing.JLabel();
  86.         txtsemester = new javax.swing.JComboBox<String>();
  87.  
  88.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  89.  
  90.         jPanel1.setBackground(new java.awt.Color(0, 102, 51));
  91.  
  92.         jLabel1.setFont(new java.awt.Font("Cooper Black", 0, 20)); // NOI18N
  93.         jLabel1.setForeground(new java.awt.Color(255, 255, 255));
  94.         jLabel1.setText("APLIKASI INPUT NILAI SISWA");
  95.  
  96.         jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  97.         jLabel2.setForeground(new java.awt.Color(240, 240, 240));
  98.         jLabel2.setText("Nama");
  99.  
  100.         jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  101.         jLabel3.setForeground(new java.awt.Color(255, 255, 255));
  102.         jLabel3.setText("Kelas ");
  103.  
  104.         jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  105.         jLabel4.setForeground(new java.awt.Color(255, 255, 255));
  106.         jLabel4.setText("Jurusan ");
  107.  
  108.         jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  109.         jLabel5.setForeground(new java.awt.Color(255, 255, 255));
  110.         jLabel5.setText("Mata Pelajaran ");
  111.  
  112.         txtnama.addActionListener(new java.awt.event.ActionListener() {
  113.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  114.                 txtnamaActionPerformed(evt);
  115.             }
  116.         });
  117.         txtnama.addKeyListener(new java.awt.event.KeyAdapter() {
  118.             public void keyTyped(java.awt.event.KeyEvent evt) {
  119.                 txtnamaKeyTyped(evt);
  120.             }
  121.         });
  122.  
  123.         txtmapel.setPreferredSize(new java.awt.Dimension(6, 28));
  124.         txtmapel.addActionListener(new java.awt.event.ActionListener() {
  125.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  126.                 txtmapelActionPerformed(evt);
  127.             }
  128.         });
  129.  
  130.         simpan.setText("Simpan");
  131.         simpan.addMouseListener(new java.awt.event.MouseAdapter() {
  132.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  133.                 simpanMouseClicked(evt);
  134.             }
  135.         });
  136.         simpan.addActionListener(new java.awt.event.ActionListener() {
  137.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  138.                 simpanActionPerformed(evt);
  139.             }
  140.         });
  141.  
  142.         keluar.setText("Keluar");
  143.         keluar.addActionListener(new java.awt.event.ActionListener() {
  144.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  145.                 keluarActionPerformed(evt);
  146.             }
  147.         });
  148.  
  149.         jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  150.         jLabel7.setForeground(new java.awt.Color(240, 240, 240));
  151.         jLabel7.setText("NIS");
  152.  
  153.         txtnis.addActionListener(new java.awt.event.ActionListener() {
  154.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  155.                 txtnisActionPerformed(evt);
  156.             }
  157.         });
  158.         txtnis.addKeyListener(new java.awt.event.KeyAdapter() {
  159.             public void keyPressed(java.awt.event.KeyEvent evt) {
  160.                 txtnisKeyPressed(evt);
  161.             }
  162.             public void keyTyped(java.awt.event.KeyEvent evt) {
  163.                 txtnisKeyTyped(evt);
  164.             }
  165.         });
  166.  
  167.         jLabel8.setFont(new java.awt.Font("Cooper Black", 0, 20)); // NOI18N
  168.         jLabel8.setForeground(new java.awt.Color(255, 255, 255));
  169.         jLabel8.setText("MA DARUL ULUM PURWOGONDO");
  170.  
  171.         txtjurusan.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 12)); // NOI18N
  172.         txtjurusan.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MIPA", "IPS 1", "IPS 2", "BAHASA" }));
  173.         txtjurusan.addActionListener(new java.awt.event.ActionListener() {
  174.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  175.                 txtjurusanActionPerformed(evt);
  176.             }
  177.         });
  178.  
  179.         hapus.setText("Hapus");
  180.         hapus.addActionListener(new java.awt.event.ActionListener() {
  181.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  182.                 hapusActionPerformed(evt);
  183.             }
  184.         });
  185.  
  186.         edit.setText("Edit");
  187.         edit.addActionListener(new java.awt.event.ActionListener() {
  188.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  189.                 editActionPerformed(evt);
  190.             }
  191.         });
  192.  
  193.         jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  194.         jLabel6.setForeground(new java.awt.Color(255, 255, 255));
  195.         jLabel6.setText("Nilai");
  196.  
  197.         jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
  198.         jLabel9.setForeground(new java.awt.Color(255, 255, 255));
  199.         jLabel9.setText("* KKM 70");
  200.  
  201.         txtkelas.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 12)); // NOI18N
  202.         txtkelas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "X", "XI", "XII", " " }));
  203.         txtkelas.addActionListener(new java.awt.event.ActionListener() {
  204.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  205.                 txtkelasActionPerformed(evt);
  206.             }
  207.         });
  208.  
  209.         jButton1.setText("Export");
  210.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  211.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  212.                 jButton1ActionPerformed(evt);
  213.             }
  214.         });
  215.  
  216.         tabelsiswa.setModel(new javax.swing.table.DefaultTableModel(
  217.             new Object [][] {
  218.                 {null, null, null, null, null, null, null, null},
  219.                 {null, null, null, null, null, null, null, null},
  220.                 {null, null, null, null, null, null, null, null},
  221.                 {null, null, null, null, null, null, null, null}
  222.             },
  223.             new String [] {
  224.                 "NIS", "NAMA", "KELAS", "JURUSAN", "MATA PELAJARAN", "SEMESTER", "NILAI", "KETERANGAN"
  225.             }
  226.         ));
  227.         tabelsiswa.addMouseListener(new java.awt.event.MouseAdapter() {
  228.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  229.                 tabelsiswaMouseClicked(evt);
  230.             }
  231.         });
  232.         jScrollPane1.setViewportView(tabelsiswa);
  233.  
  234.         txtketerangan.addMouseListener(new java.awt.event.MouseAdapter() {
  235.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  236.                 txtketeranganMouseClicked(evt);
  237.             }
  238.         });
  239.         txtketerangan.addActionListener(new java.awt.event.ActionListener() {
  240.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  241.                 txtketeranganActionPerformed(evt);
  242.             }
  243.         });
  244.  
  245.         jLabel10.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  246.         jLabel10.setForeground(new java.awt.Color(255, 255, 255));
  247.         jLabel10.setText("Keterangan");
  248.  
  249.         txtnilai.addActionListener(new java.awt.event.ActionListener() {
  250.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  251.                 txtnilaiActionPerformed(evt);
  252.             }
  253.         });
  254.  
  255.         jLabel11.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  256.         jLabel11.setForeground(new java.awt.Color(255, 255, 255));
  257.         jLabel11.setText("Semester");
  258.  
  259.         txtsemester.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 12)); // NOI18N
  260.         txtsemester.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2" }));
  261.         txtsemester.addActionListener(new java.awt.event.ActionListener() {
  262.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  263.                 txtsemesterActionPerformed(evt);
  264.             }
  265.         });
  266.  
  267.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  268.         jPanel1.setLayout(jPanel1Layout);
  269.         jPanel1Layout.setHorizontalGroup(
  270.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  271.             .addComponent(jScrollPane1)
  272.             .addGroup(jPanel1Layout.createSequentialGroup()
  273.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  274.                     .addGroup(jPanel1Layout.createSequentialGroup()
  275.                         .addGap(48, 48, 48)
  276.                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  277.                             .addGroup(jPanel1Layout.createSequentialGroup()
  278.                                 .addComponent(jLabel8)
  279.                                 .addGap(19, 19, 19))
  280.                             .addGroup(jPanel1Layout.createSequentialGroup()
  281.                                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  282.                                     .addComponent(simpan, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
  283.                                     .addGroup(jPanel1Layout.createSequentialGroup()
  284.                                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  285.                                             .addComponent(jLabel3)
  286.                                             .addComponent(jLabel4)
  287.                                             .addComponent(jLabel5)
  288.                                             .addComponent(jLabel2)
  289.                                             .addComponent(jLabel7)
  290.                                             .addComponent(jLabel6)
  291.                                             .addComponent(jLabel10)
  292.                                             .addComponent(jLabel11))
  293.                                         .addGap(14, 14, 14))
  294.                                     .addComponent(hapus, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
  295.                                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  296.                                     .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
  297.                                         .addGap(18, 18, 18)
  298.                                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  299.                                             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  300.                                                 .addGap(0, 0, Short.MAX_VALUE)
  301.                                                 .addComponent(edit, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
  302.                                             .addGroup(jPanel1Layout.createSequentialGroup()
  303.                                                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  304.                                                     .addComponent(txtjurusan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  305.                                                     .addComponent(txtmapel, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)
  306.                                                     .addComponent(txtnama, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)
  307.                                                     .addComponent(txtkelas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  308.                                                     .addComponent(txtnis, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
  309.                                                     .addComponent(txtketerangan, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
  310.                                                     .addGroup(jPanel1Layout.createSequentialGroup()
  311.                                                         .addComponent(txtnilai, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
  312.                                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  313.                                                         .addComponent(jLabel9))
  314.                                                     .addComponent(txtsemester, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  315.                                                 .addGap(0, 0, Short.MAX_VALUE))))
  316.                                     .addGroup(jPanel1Layout.createSequentialGroup()
  317.                                         .addGap(99, 99, 99)
  318.                                         .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
  319.                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 112, Short.MAX_VALUE)
  320.                                         .addComponent(keluar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))))))
  321.                     .addGroup(jPanel1Layout.createSequentialGroup()
  322.                         .addGap(123, 123, 123)
  323.                         .addComponent(jLabel1)))
  324.                 .addGap(114, 114, 114))
  325.         );
  326.         jPanel1Layout.setVerticalGroup(
  327.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  328.             .addGroup(jPanel1Layout.createSequentialGroup()
  329.                 .addContainerGap()
  330.                 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
  331.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  332.                 .addComponent(jLabel8)
  333.                 .addGap(18, 18, 18)
  334.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  335.                     .addComponent(txtnis, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
  336.                     .addComponent(jLabel7))
  337.                 .addGap(26, 26, 26)
  338.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  339.                     .addComponent(txtnama, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
  340.                     .addComponent(jLabel2))
  341.                 .addGap(11, 11, 11)
  342.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  343.                     .addComponent(txtkelas, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
  344.                     .addComponent(jLabel3))
  345.                 .addGap(18, 18, 18)
  346.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  347.                     .addComponent(txtjurusan, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
  348.                     .addComponent(jLabel4))
  349.                 .addGap(18, 18, 18)
  350.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  351.                     .addComponent(jLabel5)
  352.                     .addComponent(txtmapel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
  353.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  354.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  355.                     .addComponent(jLabel11)
  356.                     .addComponent(txtsemester, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
  357.                 .addGap(13, 13, 13)
  358.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  359.                     .addComponent(jLabel6)
  360.                     .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  361.                         .addComponent(txtnilai, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
  362.                         .addComponent(jLabel9)))
  363.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, 16, Short.MAX_VALUE)
  364.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  365.                     .addComponent(txtketerangan, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
  366.                     .addComponent(jLabel10))
  367.                 .addGap(29, 29, 29)
  368.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  369.                     .addComponent(keluar, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  370.                     .addComponent(simpan, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  371.                     .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
  372.                 .addGap(36, 36, 36)
  373.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  374.                     .addComponent(hapus, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  375.                     .addComponent(edit, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
  376.                 .addGap(28, 28, 28)
  377.                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
  378.                 .addGap(52, 52, 52))
  379.         );
  380.  
  381.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  382.         getContentPane().setLayout(layout);
  383.         layout.setHorizontalGroup(
  384.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  385.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  386.                 .addContainerGap(89, Short.MAX_VALUE)
  387.                 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  388.                 .addContainerGap())
  389.         );
  390.         layout.setVerticalGroup(
  391.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  392.             .addGroup(layout.createSequentialGroup()
  393.                 .addContainerGap()
  394.                 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  395.                 .addContainerGap())
  396.         );
  397.  
  398.         pack();
  399.     }// </editor-fold>                        
  400.  
  401.     private void txtjurusanActionPerformed(java.awt.event.ActionEvent evt) {                                          
  402.         // TODO add your handling code here:
  403.     }                                          
  404.  
  405.     private void txtnisKeyTyped(java.awt.event.KeyEvent evt) {                                
  406.         // TODO add your handling code here:
  407.         filterhuruf(evt);
  408.     }                              
  409.  
  410.     private void keluarActionPerformed(java.awt.event.ActionEvent evt) {                                      
  411.         System.exit(0);
  412.         // TODO add your handling code here:
  413.     }                                      
  414.  
  415.     private void simpanActionPerformed(java.awt.event.ActionEvent evt) {                                      
  416.         // TODO add your handling code here:
  417.         String nis = txtnis.getText();
  418.         String nama = txtnama.getText();
  419.         String kelas = (String) txtkelas.getSelectedItem();
  420.         String jurusan = (String) txtjurusan.getSelectedItem();
  421.         String mapel = txtmapel.getText();
  422.         String semester = (String) txtsemester.getSelectedItem();
  423.         String nilai = txtnilai.getText();
  424.         String keterangan = txtketerangan.getText();
  425.         if (txtnis.getText().trim().equals("")) {
  426.             JOptionPane.showMessageDialog(null, "Mohon Masukkan Data untuk di Input", "PERHATIAN", JOptionPane.WARNING_MESSAGE);
  427.         } else{
  428.             try {
  429.                 java.sql.Statement stat = koneksi.createStatement();
  430.                 ResultSet data = stat.executeQuery("SELECT * FROM nilai_siswa WHERE nis ='" + txtnis.getText() + "'");  
  431.                 if (data.next()) {
  432.                      JOptionPane.showMessageDialog(null, "NIS Sudah Ada", "PERHATIAN", JOptionPane.WARNING_MESSAGE);
  433.                      txtnis.requestFocus();
  434.                 }else {
  435.                     String sql = "INSERT INTO nilai_siswa (nis,nama,kelas,jurusan,mata_pelajaran,semester,nilai,keterangan) VALUES('" + nis + "'"
  436.                            + ",'" + nama + "'"
  437.                            + ",'" + kelas + "'"
  438.                            + ",'" + jurusan + "'"
  439.                            + ",'" + mapel + "'"
  440.                            + ",'" + semester + "'"
  441.                            + ",'" + nilai + "'"
  442.                            + ",'" + keterangan + "')";
  443.                     stat.executeUpdate(sql);
  444.                     txtnis.setText("");
  445.                     txtnama.setText("");
  446.                     txtkelas.setSelectedIndex(-0);
  447.                     txtjurusan.setSelectedIndex(-0);
  448.                     txtmapel.setText("");
  449.                     txtsemester.setSelectedIndex(-0);
  450.                     txtnilai.setText("");
  451.                     txtketerangan.setText("");
  452.                     txtnis.requestFocus();
  453.                     JOptionPane.showMessageDialog(null, "Data Berhasil Di Simpan", "SUKSES", JOptionPane.INFORMATION_MESSAGE);
  454.                     TampilDatabase();
  455.             }stat.close();
  456.                 } catch (Exception exc) {
  457.                     System.err.println("Terjadi Kesalahan :" + exc);
  458.         }
  459.         }
  460.            
  461.     }                                      
  462.  
  463.     private void simpanMouseClicked(java.awt.event.MouseEvent evt) {                                    
  464.        
  465.                     // TODO add your handling code here:
  466.     }                                  
  467.  
  468.     private void txtnamaKeyTyped(java.awt.event.KeyEvent evt) {                                
  469.         // TODO add your handling code here:
  470.         filterangka(evt);
  471.     }                                
  472.  
  473.     private void txtnamaActionPerformed(java.awt.event.ActionEvent evt) {                                        
  474.         // TODO add your handling code here:
  475.     }                                      
  476.  
  477.     private void hapusActionPerformed(java.awt.event.ActionEvent evt) {                                      
  478.         // TODO add your handling code here:
  479.        
  480.         int ok = JOptionPane.showConfirmDialog(null, "Apakah anda yakin ingin menghapus data ini?", "Konfirmasi Dialog", JOptionPane.YES_NO_OPTION);
  481.         if (ok == 0) {
  482.             String sql = "DELETE FROM nilai_siswa WHERE nis='" + txtnis.getText().trim() + "'";
  483.             try {
  484.                  Statement stat = koneksi.createStatement();
  485.                  stat.executeUpdate(sql);
  486.                  JOptionPane.showMessageDialog(null, "Data Berhasil di Hapus", "Hapus Data", JOptionPane.INFORMATION_MESSAGE);
  487.                  stat.close();
  488.                  txtnis.setText("");
  489.                  txtnama.setText("");
  490.                  txtkelas.setSelectedIndex(-0);
  491.                  txtjurusan.setSelectedIndex(-0);
  492.                  txtmapel.setText("");
  493.                  txtsemester.setSelectedIndex(-0);
  494.                  txtnilai.setText("");
  495.                  txtketerangan.setText("");
  496.                  txtnis.requestFocus();
  497.                  TampilDatabase();
  498.               } catch (SQLException exc) {
  499.                   System.err.println(sql);
  500.                   System.err.println("Error : " + exc);
  501.               }
  502.         }
  503.     }                                    
  504.  
  505.     private void txtmapelActionPerformed(java.awt.event.ActionEvent evt) {                                        
  506.         // TODO add your handling code here:
  507.     }                                        
  508.  
  509.     private void txtkelasActionPerformed(java.awt.event.ActionEvent evt) {                                        
  510.         // TODO add your handling code here:
  511.     }                                        
  512.  
  513.     private void editActionPerformed(java.awt.event.ActionEvent evt) {                                    
  514.         // TODO add your handling code here:
  515.         int ok = JOptionPane.showConfirmDialog(null, "Apakah anda yakin ingin mengubah data ini?", "Konfirmasi Dialog", JOptionPane.YES_NO_OPTION);
  516.         if (ok == 0) {
  517.         String sql = "update nilai_siswa set nama='" + txtnama.getText()
  518.                 + "',kelas='" + txtkelas.getSelectedItem()
  519.                 + "',jurusan='" + txtjurusan.getSelectedItem()
  520.                 + "',mata_pelajaran='" + txtmapel.getText()
  521.                 + "',semester='" + txtsemester.getSelectedItem()
  522.                 + "',nilai='" + txtnilai.getText()
  523.                 + "',keterangan='" + txtketerangan.getText()
  524.                 + "'where nis='" + txtnis.getText().trim() + "'";
  525.         if (txtnis.getText().trim().equals("")) {
  526.             JOptionPane.showMessageDialog(null, "Data Masih Kosong!", "Ubah Data", JOptionPane.WARNING_MESSAGE);
  527.             txtnis.requestFocus();
  528.         } else {
  529.             try {
  530.                  Statement stat = koneksi.createStatement();
  531.                  stat.executeUpdate(sql);
  532.                  JOptionPane.showMessageDialog(null, "Data Berhasil di Ubah", "Ubah Data", JOptionPane.INFORMATION_MESSAGE);
  533.                  stat.close();
  534.                  txtnis.requestFocus();
  535.                  TampilDatabase();
  536.             } catch (Exception exc) {
  537.                 System.err.println("Error :" + exc);
  538.             }
  539.           }
  540.         }
  541.     }                                    
  542.  
  543.     private void txtketeranganActionPerformed(java.awt.event.ActionEvent evt) {                                              
  544.         // TODO add your handling code here:
  545.     }                                            
  546.  
  547.     private void txtketeranganMouseClicked(java.awt.event.MouseEvent evt) {                                          
  548.         // TODO add your handling code here:
  549.         double NilaiAkhir=Integer.parseInt(txtnilai.getText());
  550.         if(NilaiAkhir>=70){
  551.             txtketerangan.setText("Lulus");
  552.         }else{
  553.             txtketerangan.setText("Tidak Lulus");
  554.         }
  555.     }                                          
  556.  
  557.     private void tabelsiswaMouseClicked(java.awt.event.MouseEvent evt) {                                        
  558.         // TODO add your handling code here:
  559.  
  560.         int baris = tabelsiswa.getSelectedRow();
  561.         if (baris != -1) {
  562.             txtnis.setText(tabelsiswa.getValueAt(baris, 0).toString());
  563.             txtnama.setText(tabelsiswa.getValueAt(baris, 1).toString());
  564.             txtkelas.setSelectedItem(tabelsiswa.getValueAt(baris, 2).toString());
  565.             txtjurusan.setSelectedItem(tabelsiswa.getValueAt(baris, 3).toString());
  566.             txtmapel.setText(tabelsiswa.getValueAt(baris, 4).toString());
  567.             txtsemester.setSelectedItem(tabelsiswa.getValueAt(baris, 5).toString());
  568.             txtnilai.setText(tabelsiswa.getValueAt(baris, 6).toString());
  569.             txtketerangan.setText(tabelsiswa.getValueAt(baris, 7).toString());
  570.         }
  571.     }                                      
  572.  
  573.     private void txtnisKeyPressed(java.awt.event.KeyEvent evt) {                                  
  574.         // TODO add your handling code here:
  575.     }                                
  576.  
  577.     private void txtnilaiActionPerformed(java.awt.event.ActionEvent evt) {                                        
  578.         // TODO add your handling code here:
  579.     }                                        
  580.  
  581.     private void txtsemesterActionPerformed(java.awt.event.ActionEvent evt) {                                            
  582.         // TODO add your handling code here:
  583.     }                                          
  584.  
  585.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  586.  
  587.         // TODO add your handling code here:
  588.     }                                        
  589.  
  590.     private void txtnisActionPerformed(java.awt.event.ActionEvent evt) {                                      
  591.         // TODO add your handling code here:
  592.     }                                      
  593.  
  594.     /**
  595.      * @param args the command line arguments
  596.      */
  597.     public static void main(String args[]) {
  598.         /* Set the Nimbus look and feel */
  599.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  600.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  601.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  602.          */
  603.         try {
  604.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  605.                 if ("Nimbus".equals(info.getName())) {
  606.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  607.                     break;
  608.                 }
  609.             }
  610.         } catch (ClassNotFoundException ex) {
  611.             java.util.logging.Logger.getLogger(madusiswa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  612.         } catch (InstantiationException ex) {
  613.             java.util.logging.Logger.getLogger(madusiswa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  614.         } catch (IllegalAccessException ex) {
  615.             java.util.logging.Logger.getLogger(madusiswa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  616.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  617.             java.util.logging.Logger.getLogger(madusiswa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  618.         }
  619.         //</editor-fold>
  620.         //</editor-fold>
  621.  
  622.         /* Create and display the form */
  623.         java.awt.EventQueue.invokeLater(new Runnable() {
  624.             public void run() {
  625.                 new madusiswa().setVisible(true);
  626.             }
  627.         });
  628.     }
  629.  
  630.     // Variables declaration - do not modify                    
  631.     private javax.swing.ButtonGroup buttonGroup1;
  632.     private javax.swing.ButtonGroup buttonGroup2;
  633.     private javax.swing.ButtonGroup buttonGroup3;
  634.     private javax.swing.JButton edit;
  635.     private javax.swing.JButton hapus;
  636.     private javax.swing.JButton jButton1;
  637.     private javax.swing.JLabel jLabel1;
  638.     private javax.swing.JLabel jLabel10;
  639.     private javax.swing.JLabel jLabel11;
  640.     private javax.swing.JLabel jLabel2;
  641.     private javax.swing.JLabel jLabel3;
  642.     private javax.swing.JLabel jLabel4;
  643.     private javax.swing.JLabel jLabel5;
  644.     private javax.swing.JLabel jLabel6;
  645.     private javax.swing.JLabel jLabel7;
  646.     private javax.swing.JLabel jLabel8;
  647.     private javax.swing.JLabel jLabel9;
  648.     private javax.swing.JPanel jPanel1;
  649.     private javax.swing.JScrollPane jScrollPane1;
  650.     private javax.swing.JButton keluar;
  651.     private javax.swing.JButton simpan;
  652.     private javax.swing.JTable tabelsiswa;
  653.     private javax.swing.JComboBox<String> txtjurusan;
  654.     private javax.swing.JComboBox<String> txtkelas;
  655.     private javax.swing.JTextField txtketerangan;
  656.     private javax.swing.JTextField txtmapel;
  657.     private javax.swing.JTextField txtnama;
  658.     private javax.swing.JTextField txtnilai;
  659.     private javax.swing.JTextField txtnis;
  660.     private javax.swing.JComboBox<String> txtsemester;
  661.     // End of variables declaration                  
  662.  
  663.     private void KoneksiDatabase() {
  664.                 try {
  665.             Class.forName("com.mysql.jdbc.Driver");
  666.         } catch (ClassNotFoundException cnf) {
  667.     }
  668.         try {
  669.             koneksi = DriverManager.getConnection("jdbc:mysql://localhost/db_madusiswa", "root", "");
  670.             JOptionPane.showMessageDialog(null, "Koneksi Database Berhasil");
  671.         } catch (SQLException se) {
  672.             JOptionPane.showMessageDialog(null, "Koneksi Database Gagal");
  673.         } catch (Exception e) {
  674.         }}
  675.  
  676.     private void TampilDatabase() {
  677.                 //membuat tampilan model tabel
  678.         DefaultTableModel model = new DefaultTableModel();
  679.         model.addColumn("NIS");
  680.         model.addColumn("NAMA");
  681.         model.addColumn("KELAS");
  682.         model.addColumn("JURUSAN");
  683.         model.addColumn("MATA PELAJARAN");
  684.         model.addColumn("SEMESTER");
  685.         model.addColumn("NILAI");
  686.         model.addColumn("KETERANGAN");
  687.         tabelsiswa.setModel(model);
  688.  
  689.         //menampilkan data database kedalam tabel
  690.         try {
  691.             java.sql.Statement stat = koneksi.createStatement();
  692.             ResultSet data = stat.executeQuery("SELECT * FROM nilai_siswa");
  693.             while (data.next()) {
  694.                  model.addRow(new Object[]{
  695.                     data.getString("nis"),
  696.                     data.getString("nama"),
  697.                     data.getString("kelas"),
  698.                     data.getString("jurusan"),
  699.                     data.getString("mata_pelajaran"),
  700.                     data.getString("semester"),
  701.                     data.getString("nilai"),
  702.                     data.getString("keterangan")
  703.                  });
  704.                  tabelsiswa.setModel(model);
  705.             }
  706.         } catch (Exception e) {
  707.             System.err.println("Terjadi Kesalahan :" + e);
  708.         }
  709.     }}
Advertisement
Add Comment
Please, Sign In to add comment