1. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Here are the other part of the code:

    Code:
    for (int m = 0; m <5; m++)  
    {  
    jawabAlternatif[m][0].setEditable(false);  
    jawabAlternatif[m][1].setEditable(false);  
    }  
    for (int hki = 0; hki < 4; hki++)  
    {  
        jawabKriteria[hki][0].setEditable(false);  
        jawabKriteria[hki][1].setEditable(false);  
    }  
    // Tanda Alternatif Harga Myocardial Infarction  
    kriteria[0][0].setBounds(1,200,100,25);  
    kriteria[1][0].setBounds(1,230,100,25);  
    kriteria[2][0].setBounds(1,260,100,25);  
    kriteria[3][0].setBounds(1,290,100,25);  
    for (int lop = 0; lop < 4; lop++)  
    {  
    konten.add(kriteria[lop][0]);  
    }  
    // Alternatif Sakit Harga Myocardial Infarction  
    jawabKriteria[0][0].setBounds(101,200,70,25);  
    jawabKriteria[1][0].setBounds(101,230,70,25);  
    jawabKriteria[2][0].setBounds(101,260,70,25);  
    jawabKriteria[3][0].setBounds(101,290,70,25);  
    for (int jki = 0; jki < 4; jki++)  
    {  
    konten.add(jawabKriteria[jki][0]);  
    }  
    // Kriteria Sakit Myocardial Infarction  
    alternatif[0][0].setBounds(200,200,100,25);  
    alternatif[1][0].setBounds(200,230,100,25);  
    alternatif[2][0].setBounds(200,260,100,25);  
    alternatif[3][0].setBounds(200,290,100,25);  
    alternatif[4][0].setBounds(200,320,100,25);  
      
    for (int loyo = 0; loyo < 5; loyo++)  
    {  
    konten.add(alternatif[loyo][0]);  
    }  
    jawabAlternatif[0][0].setBounds(360,200,70,25);  
    jawabAlternatif[1][0].setBounds(360,230,70,25);  
    jawabAlternatif[2][0].setBounds(360,260,70,25);  
    jawabAlternatif[3][0].setBounds(360,290,70,25);  
    jawabAlternatif[4][0].setBounds(360,320,70,25);  
    for (int gfk = 0; gfk < 5; gfk++)  
    {  
        konten.add(jawabAlternatif[gfk][0]);  
    }  
    // Awal Stroke  
    stroke.setBounds(0,380,200,25);  
    konten.add(stroke);  
    // Tanda Kriteria Stroke  
    kriteria[0][1].setBounds(1,420,200,25);  
    kriteria[1][1].setBounds(1,450,200,25);  
    kriteria[2][1].setBounds(1,480,200,25);  
    kriteria[3][1].setBounds(1,510,200,25);  
    for (int gdu = 0; gdu < 4; gdu++)  
    {  
    konten.add(kriteria[gdu][1]);  
    }  
    // Kriteria Sakit Stroke  
    jawabKriteria[0][1].setBounds(101,420,60,25);  
    jawabKriteria[1][1].setBounds(101,450,60,25);  
    jawabKriteria[2][1].setBounds(101,480,60,25);  
    jawabKriteria[3][1].setBounds(101,510,60,25);  
    for (int jku = 0; jku < 4; jku++)  
    {  
    konten.add(jawabKriteria[jku][1]);  
    }  
    alternatif[0][1].setBounds(200,420,100,25);  
    alternatif[1][1].setBounds(200,450,100,25);  
    alternatif[2][1].setBounds(200,480,100,25);  
    alternatif[3][1].setBounds(200,510,100,25);  
    alternatif[4][1].setBounds(200,540,100,25);  
    for (int loyom = 0; loyom < 5; loyom++)  
    {  
    konten.add(alternatif[loyom][1]);  
    }  
    jawabAlternatif[0][1].setBounds(360,420,70,25);  
    jawabAlternatif[1][1].setBounds(360,450,70,25);  
    jawabAlternatif[2][1].setBounds(360,480,70,25);  
    jawabAlternatif[3][1].setBounds(360,510,70,25);  
    jawabAlternatif[4][1].setBounds(360,540,70,25);  
    for (int gfki = 0; gfki < 5; gfki++)  
    {  
        konten.add(jawabAlternatif[gfki][1]);  
    }  
    lanjut.setBounds(880,560,100,25);  
    konten.add(lanjut);  
    lanjut.setEnabled(false);  
      
    } //Akhir Konstruktor  
    
    public static void main(String[] args)  
    {  
            ProgramTesisBaru tesis = new ProgramTesisBaru();   
            tesis.setTitle("Program Pemilihan Obat dengan Cara Analytic Hierarchycal Process");  
            tesis.setSize(1024,768);  
            tesis.setVisible(true);  
            tesis.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
            tesis.setLocationRelativeTo(null);  
    }};
    Please help me as soon as possible.
  2. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    Please don't start working on new programs until the NewMain program is working.

    The ProgramTesisBaru program is too big for easy testing.
    Another problem with the code in ProgramTesisBaru is that it is not properly formatted. Too many statements start in the first column. Nested statements should be indented so the code can easily be read and understood.
  3. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Originally Posted by NormR
    Please don't start working on new programs until the NewMain program is working.

    The ProgramTesisBaru program is too big for easy testing.
    Another problem with the code in ProgramTesisBaru is that it is not properly formatted. Too many statements start in the first column. Nested statements should be indented so the code can easily be read and understood.
    That is working already and I am integrating it to my project. I have a new problem and the code is posted before. In prior post, I post my problem either. I cannot break it any longer because it is useless. Please help me immediately.

    I post the formatted code:

    Code:
    package programtesisbaru;  
      
      
    import java.awt.*;  
    import java.sql.*;  
    import java.util.logging.Level;  
    import java.util.logging.Logger;  
    import javax.swing.*;
    
    /** 
    * 
    * @author Tawi 
    */  
    public class ProgramTesisBaru extends FrameBaru {  
    Container konten = getContentPane();  
    JLabel lblNama = new JLabel("Nama : ");  
    JTextField txtNama = new JTextField();  
    JLabel kataSandi = new JLabel("Kata Sandi : ");  
    JPasswordField sandiKata = new JPasswordField();  
    JButton masuk = new JButton("Masuk");  
    JButton keluar = new JButton("Keluar");  
    int i;  
    JButton tombolHubungkankePadukData = new JButton("Hubungkan ke Paduk Data");  
    JButton putuskanKoneksiKePadukData = new JButton("Putuskan Koneksi ke Paduk Data");  
    JButton tombolUbahPadukData = new JButton("Ubah Paduk Data");  
    JButton tombolBatal = new JButton("Batal");  
    JButton lanjut = new JButton("Lanjut");  
    JComboBox jcboURL = new JComboBox (new String[] {"jdbc:odbc:DatabaseKlinik"});  
    JComboBox jcboDriver = new JComboBox (new String[] {"sun.jdbc.odbc.JdbcOdbcDriver"});  
    Connection connection;  
    Statement statement;  
    Statement pernyataan;
    JLabel statusKoneksi = new JLabel("Tidak ada Koneksi ke Paduk Data");  
    JLabel padukData = new JLabel("Paduk Data Belum Diubah");  
    String namaPengguna1 = new String();  
    String passwordPengguna1 = new String();  
    JLabel myocardialInfarction = new JLabel("Myocardial Infarction");  
    JLabel stroke = new JLabel("Stroke");  
    JLabel[][] kriteria = new JLabel[4][2];  
    JLabel[][] alternatif = new JLabel[5][2];  
    JTextField[][]jawabKriteria = new JTextField [4][2];  
    JTextField[][] jawabAlternatif = new JTextField[5][2];  
    JLabel statusMasuk = new JLabel("Belum Masuk");  
    String ax = "Kata Sandi Belum Dimasukkan";  
    String bx = "Nama Dokter Belum Dimasukkan";  
    String cx = "Nama Dokter dan Kata Sandi tidak Diisi";  
    String dx = "Nama Dokter atau Kata Sandi tidak Benar"; 
    String ex = "Kesalahan";
    String usrname = new String();
    String psswrd = new String();
    String uniRL = (String)jcboURL.getSelectedItem();  
    String driver = (String) jcboDriver.getSelectedItem(); 
    
    public void connectToDB() {  
                    //String uniRL = (String)jcboURL.getSelectedItem();  
                    //String driver = (String) jcboDriver.getSelectedItem();  
                    //URL uniRL = (URL)jcboURL.getSelectedItem();  
                    try {  
                        Class.forName(driver);  
                        connection = DriverManager.getConnection(uniRL, usrname, psswrd);  
                        //rowSet.setURL(uniRL);  
                        statusKoneksi.setText("Terhubung ke Paduk Data"); 
                        //statement = connection.createStatement();
                    }  
                    catch (java.lang.Exception ex) { 
                        ex.printStackTrace();
                        statusKoneksi.setText("Gagal Terhubung ke Paduk Data");  
                    }  
                }  
                
    public ProgramTesisBaru()  
    {   
       konten.setLayout(null); 
       // Atur letak beberapa komponen  
    
       for (int tlo = 0; tlo < 2; tlo++)  
       {  
           kriteria[0][tlo] = new JLabel("Kriteria 1");  
           kriteria[1][tlo] = new JLabel("Kriteria 2");  
           kriteria[2][tlo] = new JLabel("Kriteria 3");  
           kriteria[3][tlo] = new JLabel("Kriteria 4");  
           alternatif[0][tlo] = new JLabel("Alternatif 1");  
           alternatif[1][tlo] = new JLabel("Alternatif 2");  
           alternatif[2][tlo] = new JLabel("Alternatif 3");  
           alternatif[3][tlo] = new JLabel("Alternatif 4");  
           alternatif[4][tlo] = new JLabel("Alternatif 5");  
       }    
       lblNama.setBounds(0,10,100,25);    
       txtNama.setBounds(130,10,200,25);  
       kataSandi.setBounds(330,10,100,25);   
       sandiKata.setBounds(410,10,200,25);    
       masuk.setBounds(600,10,100,25);  
       keluar.setBounds(700,10,100,25);    
       tombolHubungkankePadukData.setBounds(0,50,250,25);    
       putuskanKoneksiKePadukData.setBounds(250,50,250,25);    
       tombolUbahPadukData.setBounds(480,50,250,25);    
       tombolBatal.setBounds(730,50,250,25);    
       statusKoneksi.setBounds(800,10,200,25);    
       padukData.setBounds(0,70,200,25);  
       statusMasuk.setBounds(160,70,200,25);  
       myocardialInfarction.setBounds(0,120,200,25);
       konten.add(lblNama);
       konten.add(txtNama);
       konten.add(txtNama);
       konten.add(kataSandi); 
       konten.add(sandiKata);
       konten.add(masuk);
       konten.add(keluar);
       konten.add(tombolHubungkankePadukData);
       konten.add(putuskanKoneksiKePadukData);
       konten.add(tombolUbahPadukData);
       konten.add(tombolBatal);
       konten.add(statusKoneksi);
       konten.add(myocardialInfarction);  
       konten.add(padukData);  
       tombolHubungkankePadukData.setEnabled(false);  
       tombolBatal.setEnabled(false);  
       tombolUbahPadukData.setEnabled(false);  
       putuskanKoneksiKePadukData.setEnabled(false);  
       for (int jwbKri = 0; jwbKri < 4; jwbKri++)  
       {  
           jawabKriteria[jwbKri][0] = new JTextField(10);  
           jawabKriteria[jwbKri][1] = new JTextField(10);  
       }  
       for (int jwbAlt = 0; jwbAlt < 5; jwbAlt++)  
       {  
           jawabAlternatif[jwbAlt][0] = new JTextField(10);  
           jawabAlternatif[jwbAlt][1] = new JTextField(10);  
       }  
       for (int jwbKrif = 0; jwbKrif < 4; jwbKrif++)  
       {  
           jawabKriteria[jwbKrif][0].setVisible(false);  
           jawabKriteria[jwbKrif][1].setVisible(false);  
       }  
       for (int jwbAlt = 0; jwbAlt < 5; jwbAlt++)  
       {  
           jawabAlternatif[jwbAlt][0].setVisible(false);  
           jawabAlternatif[jwbAlt][1].setVisible(false);  
       }  
       lblNama.setVisible(true);  
       txtNama.setVisible(true);  
       kataSandi.setVisible(true);  
       sandiKata.setVisible(true);  
       masuk.setVisible(true);  
       keluar.setVisible(true);  
       tombolHubungkankePadukData.setVisible(true);  
       putuskanKoneksiKePadukData.setVisible(true);  
       tombolUbahPadukData.setVisible(true);  
       tombolBatal.setVisible(true);  
       lanjut.setVisible(false);  
       jcboURL.setVisible(true);  
       jcboDriver.setVisible(true);  
       statusKoneksi.setVisible(true);  
       padukData.setVisible(true);  
       myocardialInfarction.setVisible(false);  
       stroke.setVisible(false);  
       for (int hklma = 0; hklma < kriteria.length; hklma++) 
       {        
           kriteria[hklma][0].setVisible(false);    
           kriteria[hklma][1].setVisible(false);    
       }  
       for (int hklma = 0; hklma < alternatif.length; hklma++)     
       {    
           alternatif[hklma][0].setVisible(false);    
           alternatif[hklma][1].setVisible(false);
       }     
       statusMasuk.setVisible(true);  
       labelPerhitunganKriteria.setVisible(false);  
       tampilKriteria.setVisible(false);  
       tampilKriteria1.setVisible(false);  
       ubah.setVisible(false);  
       kembali.setVisible(false);  
       lanjutlah.setVisible(false);  
       lanjutlah1.setVisible(false);  
       perhitunganKriteria.setVisible(false);  
       perhitunganKriteria1.setVisible(false);  
       kmbl.setVisible(false);  
       kmbl1.setVisible(false);  
       update.setVisible(false);  
       update1.setVisible(false);  
       myocardInfarc.setVisible(false);  
       stroke1.setVisible(false);  
       for (int hklma = 0; hklma < jawabKriteria1.length; hklma++) 
       {    
           for (int nyola = 0; nyola < jawabKriteria1[hklma].length; nyola++) 
           {    
              jawabKriteria1[hklma][nyola].setVisible(false);    
           }    
       }  
       for (int hklma = 0; hklma < jawabAlternatif1.length; hklma++) 
       {    
           for (int nyola = 0; nyola < jawabAlternatif1[hklma].length; nyola++) 
           {    
               jawabAlternatif1[hklma][nyola].setVisible(false);    
           }    
       }  
       for (int hklma = 0; hklma < labelLuarKriteria.length; hklma++) 
       {    
           for (int nyola = 0; nyola < labelLuarKriteria[hklma].length; nyola++) 
           {    
               labelLuarKriteria[hklma][nyola].setVisible(false);    
           }    
       }  
       for (int hklma = 0; hklma < labelLuarAlternatif.length; hklma++) 
       {    
            for (int nyola = 0; nyola < labelLuarAlternatif[hklma].length; nyola++) 
            {    
               labelLuarAlternatif[hklma][nyola].setVisible(false);    
            }    
       }  
       for (int hklma = 0; hklma < labelLuarAlternatif1.length; hklma++) 
       {    
           for (int nyola = 0; nyola < labelLuarAlternatif1[hklma].length; nyola++) 
           {    
               labelLuarAlternatif1[hklma][nyola].setVisible(false);    
           }    
       }  
       for (int hklm = 0; hklm < labelLuarKriteria1.length; hklm++) 
       {    
           for (int nyol = 0; nyol < labelLuarKriteria1[hklm].length; nyol++) 
           {    
               labelLuarKriteria1[hklm][nyol].setVisible(false);    
           }    
       }  
       kriteriaLanjut.setVisible(false);  
       kriteriaLanjut1.setVisible(false);
       lanjut.addActionListener(new java.awt.event.ActionListener() 
       {  
          @Override  
          public void actionPerformed(java.awt.event.ActionEvent evt) 
          {  
              kontinu();  
          }  
          private void kontinu() 
          {  
              String[][] passCriteriaVariables = new String[4][2];  
              String[][] passAlternativeVariables = new String[5][2];  
              for (int ijkl = 0; ijkl < passCriteriaVariables.length; ijkl++) 
                  {    
                      for (int ikjl = 0; ikjl < passCriteriaVariables[ijkl].length; ikjl++) 
                          {    
                              passCriteriaVariables[ijkl][ikjl] = new String();    
                          }    
                  }  
              for (int aijkl = 0; aijkl < passCriteriaVariables.length; aijkl++) 
                  {    
                     for (int aikjl = 0; aikjl < passCriteriaVariables[aijkl].length; aikjl++) 
                         {    
                             passCriteriaVariables[aijkl][aikjl] = jawabKriteria[aijkl][aikjl].getText();    
                         }    
                  }  
              for (int laijkl = 0; laijkl < passAlternativeVariables.length; laijkl++) 
                  {    
                      for (int laikjl = 0; laikjl < passAlternativeVariables[laijkl].length; laikjl++) 
                          {    
                             passAlternativeVariables[laijkl][laikjl] = new String();    
                          }    
                  }  
              for (int lijkl = 0; lijkl < passAlternativeVariables.length; lijkl++) 
                  {    
                      for (int likjl = 0; likjl < passAlternativeVariables[lijkl].length; likjl++) 
                          {    
                               passAlternativeVariables[lijkl][likjl] = jawabAlternatif[lijkl][likjl].getText();    
                          }    
                  }  
              lblKriteria = passCriteriaVariables;  
              lblAlternatif = passAlternativeVariables;  
              lblNama.setVisible(false);  
              txtNama.setVisible(false);  
              kataSandi.setVisible(false);  
              sandiKata.setVisible(false);  
              masuk.setVisible(false);  
              keluar.setVisible(false);  
              tombolHubungkankePadukData.setVisible(false);  
              putuskanKoneksiKePadukData.setVisible(false);  
              tombolUbahPadukData.setVisible(false);  
              tombolBatal.setVisible(false);  
              lanjut.setVisible(false);  
              jcboURL.setVisible(false);  
              jcboDriver.setVisible(false);  
              statusKoneksi.setVisible(false);  
              padukData.setVisible(false);  
              myocardialInfarction.setVisible(true);  
              stroke.setVisible(true);  
              for (int hklma = 0; hklma < kriteria.length; hklma++) 
                  {    
                      for (int nyola = 0; nyola < kriteria[hklma].length; nyola++) 
                          {    
                              kriteria[hklma][nyola].setVisible(false);    
                          }    
                  }  
              for (int hklmaf = 0; hklmaf < jawabAlternatif1.length; hklmaf++) 
                  {    
                       for (int nyolaf = 0; nyolaf < jawabAlternatif1[hklmaf].length; nyolaf++) 
                           {    
                                jawabAlternatif1[hklmaf][nyolaf].setVisible(false);    
                           }    
                  }  
              for (int hklma = 0; hklma < alternatif.length; hklma++) 
                  {    
                       for (int nyola = 0; nyola < alternatif[hklma].length; nyola++) 
                           {    
                                alternatif[hklma][nyola].setVisible(false);    
                           }    
                  }  
              statusMasuk.setVisible(false);  
              labelPerhitunganKriteria.setVisible(true);  
              tampilKriteria.setVisible(true);  
              tampilKriteria1.setVisible(true);  
              ubah.setVisible(true);  
              kembali.setVisible(true);  
              lanjutlah.setVisible(true);  
              lanjutlah1.setVisible(true);  
              perhitunganKriteria.setVisible(true);  
              perhitunganKriteria1.setVisible(true);  
              kmbl.setVisible(true);  
              kmbl1.setVisible(true);  
              update.setVisible(true);  
              update1.setVisible(true);  
              myocardInfarc.setVisible(true);  
              stroke1.setVisible(true);  
              for (int hklma = 0; hklma < jawabKriteria1.length; hklma++) 
                  {    
                       jawabKriteria1[hklma][0].setVisible(true);
                       jawabKriteria1[hklma][1].setVisible(true);
                  }    
              for (int hklma = 0; hklma < labelLuarKriteria.length; hklma++) 
                  {    
                       for (int nyola = 0; nyola < labelLuarKriteria[hklma].length; nyola++) 
                           {    
                                labelLuarKriteria[hklma][nyola].setVisible(true);    
                           }    
                  }  
              for (int hklma = 0; hklma < labelLuarAlternatif.length; hklma++) 
                  {    
                       for (int nyola = 0; nyola < labelLuarAlternatif[hklma].length; nyola++) 
                           {    
                                labelLuarAlternatif[hklma][nyola].setVisible(true);    
                           }    
                  }  
              for (int hklma = 0; hklma < labelLuarAlternatif1.length; hklma++) 
                  {    
                       for (int nyola = 0; nyola < labelLuarAlternatif1[hklma].length; nyola++) 
                           {    
                                labelLuarAlternatif1[hklma][nyola].setVisible(true);    
                           }    
                  }  
              for (int hklm = 0; hklm < labelLuarKriteria1.length; hklm++) 
                  {    
                       for (int nyol = 0; nyol < labelLuarKriteria1[hklm].length; nyol++) 
                           {    
                                labelLuarKriteria1[hklm][nyol].setVisible(true);    
                           }    
                  }  
              for (int hklmg = 0; hklmg < jawabKriteria.length; hklmg++) 
                  {    
                       for (int nyolg = 0; nyolg < jawabKriteria[hklmg].length; nyolg++) 
                           {    
                                jawabKriteria[hklmg][nyolg].setVisible(false);    
                           }    
                  }  
              for (int hklmga = 0; hklmga < jawabAlternatif.length; hklmga++) 
                  {    
                       for (int nyolga = 0; nyolga < jawabAlternatif[hklmga].length; nyolga++) 
                           {    
                                jawabAlternatif[hklmga][nyolga].setVisible(false);    
                           }    
                  }  
              kriteriaLanjut.setVisible(true);  
              kriteriaLanjut1.setVisible(true);  
              //FrameBaru baru = new FrameBaru(passCriteriaVariables, passAlternativeVariables); // I want to make a class that is named FrameBaru to be visible   
          }  
       });  
       tombolUbahPadukData.addActionListener(new java.awt.event.ActionListener() 
       {  
          @Override  
          public void actionPerformed(java.awt.event.ActionEvent evt) 
          {  
              ubah();  
          }  
      
          private void ubah() 
          {  
             if (connection == null)
                {
                   JOptionPane.showMessageDialog(null, "Hubungkan Dahulu ke Paduk Data", "Tidak Ada Koneksi", JOptionPane.INFORMATION_MESSAGE);
                }
             else 
                {
                   for (int lmo = 0; lmo < 4; lmo++)  
                       {  
                            jawabKriteria[lmo][0].setEditable(true);
                            jawabKriteria[lmo][0].setVisible(true);
                            jawabKriteria[lmo][1].setEditable(true);  
                            jawabKriteria[lmo][1].setVisible(true);
                            kriteria[lmo][0].setVisible(true);
                            kriteria[lmo][1].setVisible(true);
                       }  
                   for (int mlo = 0; mlo < 5; mlo++)  
                       {  
                            jawabAlternatif[mlo][0].setEditable(true);  
                            jawabAlternatif[mlo][0].setVisible(true);
                            jawabAlternatif[mlo][1].setEditable(true);  
                            jawabAlternatif[mlo][1].setVisible(true);
                            alternatif[mlo][0].setVisible(true);
                            alternatif[mlo][1].setVisible(true);
                       }  
                   lanjut.setEnabled(true); 
                   lanjut.setVisible(true);
                   myocardialInfarction.setVisible(true);
                   stroke.setVisible(true);
                 }  
          }
       });  
       putuskanKoneksiKePadukData.addActionListener(new java.awt.event.ActionListener() {  
                @Override  
                public void actionPerformed(java.awt.event.ActionEvent evt) 
                {  
                    putuskan();    
                }  
      
                private void putuskan() 
                {  
                  try 
                  {
                    if (connection == null)  
                       {  
                           statusKoneksi.setText("Tidak ada Koneksi ke Paduk Data");  
                           myocardialInfarction.setVisible(false);
                           stroke.setVisible(false);
                           for (int ltu = 0; ltu < 4; ltu++)  
                               {  
                                   kriteria[ltu][0].setVisible(false);
                                   kriteria[ltu][1].setVisible(false);
                                   jawabKriteria[ltu][0].setEditable(false);  
                                   jawabKriteria[ltu][1].setEditable(false); 
                                   jawabKriteria[ltu][0].setVisible(false);  
                                   jawabKriteria[ltu][1].setVisible(false);  
                               }  
                           for (int tlu = 0; tlu < 5; tlu++)  
                               {  
                                   jawabAlternatif[tlu][0].setEditable(false);  
                                   jawabAlternatif[tlu][1].setEditable(false);  
                                   jawabAlternatif[tlu][0].setVisible(false);  
                                   jawabAlternatif[tlu][1].setVisible(false);
                                   alternatif[tlu][1].setVisible(false);
                                   alternatif[tlu][0].setVisible(false);
                               }  
                       }  
                    else   
                       {  
                          statusKoneksi.setText("Koneksi ke Paduk Data sudah Terputus");  
                          for (int lko = 0; lko < 4; lko++)  
                              {  
                                  kriteria[lko][0].setVisible(false);
                                  kriteria[lko][1].setVisible(false);
                                  jawabKriteria[lko][0].setEditable(false);  
                                  jawabKriteria[lko][1].setEditable(false); 
                                  jawabKriteria[lko][0].setVisible(false);  
                                  jawabKriteria[lko][1].setVisible(false);  
                              }  
                          for (int lok = 0; lok < 5; lok++)  
                              {  
                                 alternatif[lok][0].setVisible(false);
                                 alternatif[lok][1].setVisible(false);
                                 jawabAlternatif[lok][0].setEditable(false);  
                                 jawabAlternatif[lok][1].setEditable(false); 
                                 jawabAlternatif[lok][0].setVisible(false);  
                                 jawabAlternatif[lok][1].setVisible(false);
                              }                  
                       }  
                    connection.close();
                    statement.close();
                    myocardialInfarction.setVisible(false);
                    stroke.setVisible(false);
                  }
                  catch (SQLException ex) 
                   {
                    ex.printStackTrace();
                   }
       }});
    I cannot open and close the database because after I open it, I cannot close it again. What is wrong?
    Last edited by Tawijakarta; June 20th, 2013 at 11:40 AM.
  4. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    I have a new problem
    Why can't I connect or disconnect with this code?
    Is this the problem you are having now? If not, please explain in detail.
    Please explain what happens when the program is executed.
    What does the user do when the program is started?
    what does the program do with the user input?
    What happens next?

    Copy the full contents of the console from when the program is executed to show all the output from the println statements used for debugging so that I can see exactly what the code sees when it executes.


    Please edit and properly format the code for the program.
    I will not try to work with unformatted code. Logically nested statements should be indented 3-4 spaces. The posted code has too many statements that start in the first column. they need to be indented.
  5. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Originally Posted by NormR
    Is this the problem you are having now? If not, please explain in detail.
    Please explain what happens when the program is executed.
    What does the user do when the program is started?
    what does the program do with the user input?
    What happens next?

    Copy the full contents of the console from when the program is executed to show all the output from the println statements used for debugging so that I can see exactly what the code sees when it executes.


    Please edit and properly format the code for the program.
    I will not try to work with unformatted code. Logically nested statements should be indented 3-4 spaces. The posted code has too many statements that start in the first column. they need to be indented.
    Here are the other part of the code:

    Code:
    masuk.addActionListener(new java.awt.event.ActionListener() 
       {  
                String loginName;  
                String loginPassword;    
                String passwrd;
                @Override  
                
                public void actionPerformed(java.awt.event.ActionEvent evt) {  
                    usrname = txtNama.getText().trim();  
                    psswrd = new String(sandiKata.getPassword());
                    if (("".equals(usrname)) && ("".equals(psswrd)))   
                                 {  
                                   tombolHubungkankePadukData.setEnabled(false);  
                                   putuskanKoneksiKePadukData.setEnabled(false);  
                                   tombolUbahPadukData.setEnabled(false);  
                                   tombolBatal.setEnabled(false);  
                                   masuk.setEnabled(true);
                                   statusKoneksi.setText("Tidak Ada Koneksi ke Paduk Data");
                                   keluar.setEnabled(true);  
                                   putuskanKoneksiKePadukData.setEnabled(false); 
                                   JOptionPane.showMessageDialog(null, cx, ex, JOptionPane.INFORMATION_MESSAGE);  
                                 }  
                    else if ((!"".equals(usrname)) && ("".equals(psswrd)))
                                 {  
                                   JOptionPane.showMessageDialog(null, ax, ex, JOptionPane.INFORMATION_MESSAGE);  
                                   tombolHubungkankePadukData.setEnabled(false);  
                                   putuskanKoneksiKePadukData.setEnabled(false);  
                                   tombolUbahPadukData.setEnabled(false);  
                                   tombolBatal.setEnabled(false); 
                                   masuk.setEnabled(true);
                                   statusKoneksi.setText("Tidak Ada Koneksi ke Paduk Data");
                                   keluar.setEnabled(true);  
                                   putuskanKoneksiKePadukData.setEnabled(false);  
                                 }  
                    else if ((("".equals(usrname)) && (!"".equals(psswrd))))  
                                 {      
                                   tombolHubungkankePadukData.setEnabled(false);  
                                   putuskanKoneksiKePadukData.setEnabled(false);  
                                   tombolUbahPadukData.setEnabled(false);  
                                   tombolBatal.setEnabled(false);  
                                   keluar.setEnabled(true);  
                                   masuk.setEnabled(true);
                                   statusKoneksi.setText("Tidak Ada Koneksi ke Paduk Data");
                                   putuskanKoneksiKePadukData.setEnabled(false);  
                                   JOptionPane.showMessageDialog(null, bx, ex, JOptionPane.INFORMATION_MESSAGE);                          
                                 }       
                    else if ((!"".equals(usrname)) && (!"".equals(psswrd)))  
                                 {
                                    connectToDB();
                                 }
                    try {  
                        masuklah();  
                    }   
                    catch (SQLException ex) {
                        ex.printStackTrace();
                        Logger.getLogger(ProgramTesisBaru.class.getName()).log(Level.SEVERE, null, ex);  
                    }  
                }  
      
                private void masuklah() throws SQLException {  
                      if (connection == null)  
                      {  
                          masuk.setEnabled(true);  
                          entryPrg();  
                      }  
                      else {
                          masuk.setEnabled(false);
                          entryPrg();  
                      }  
                }   
                private void entryPrg() {  
                          connectToDB();
                          try {
                          //System.out.println("con="+connection.isClosed());
                              statement = connection.createStatement();
                              pernyataan = connection.createStatement();
                              loginName = "select Nama_Dokter from tblDokterAhli where Nama_Dokter = '"+usrname+"'";  
                          //System.out.println(loginName);
                              loginPassword = "select Kata_Kunci from tblDokterAhli where Kata_Kunci = '"+psswrd+"' and Nama_Dokter = '"+usrname+"'";
                              ResultSet logName = statement.executeQuery(loginName);  
                          //System.out.println(logName);
                              ResultSet logPassword = pernyataan.executeQuery(loginPassword);
                              while (logName.next()) 
                                  {  
                                     namaPengguna1 = logName.getString("Nama_Dokter");  
                                  }  
                              while (logPassword.next()) 
                                  {  
                                     passwordPengguna1 = logPassword.getString("Kata_Kunci");  
                                  }  
                              if ((!"".equals(namaPengguna1)) && (!"".equals(passwordPengguna1)))   
                                {  
                                   tombolHubungkankePadukData.setEnabled(true);  
                                   putuskanKoneksiKePadukData.setEnabled(true);  
                                   tombolUbahPadukData.setEnabled(true);  
                                   tombolBatal.setEnabled(true);  
                                   masuk.setEnabled(false);
                                   statusKoneksi.setText("Terhubung ke Paduk Data");
                                   keluar.setEnabled(true);  
                                   putuskanKoneksiKePadukData.setEnabled(true);  
                                   statement.close();
                                   connection.close();
                                   pernyataan.close();
                                }  
                              else if (("".equals(namaPengguna1)) && (!"".equals(passwordPengguna1)))  
                                {  
                                   tombolHubungkankePadukData.setEnabled(false);  
                                   putuskanKoneksiKePadukData.setEnabled(false);  
                                   tombolUbahPadukData.setEnabled(false);  
                                   tombolBatal.setEnabled(false);  
                                   keluar.setEnabled(true);
                                   masuk.setEnabled(true);
                                   statusKoneksi.setText("Tidak Ada Koneksi ke Paduk Data");
                                   putuskanKoneksiKePadukData.setEnabled(false);  
                                   JOptionPane.showMessageDialog(null, dx, ex, JOptionPane.INFORMATION_MESSAGE);  
                                   connection.close();
                                   statement.close();
                                   pernyataan.close();
                               }  
                             else if ((!"".equals(namaPengguna1)) && ("".equals(passwordPengguna1)))  
                               {  
                                   tombolHubungkankePadukData.setEnabled(false);  
                                   putuskanKoneksiKePadukData.setEnabled(false);  
                                   tombolUbahPadukData.setEnabled(false);  
                                   tombolBatal.setEnabled(false);
                                   masuk.setEnabled(true);
                                   statusKoneksi.setText("Tidak Ada Koneksi ke Paduk Data");
                                   keluar.setEnabled(true);  
                                   putuskanKoneksiKePadukData.setEnabled(false);  
                                   JOptionPane.showMessageDialog(null, dx, ex, JOptionPane.INFORMATION_MESSAGE);  
                                   connection.close();
                                   pernyataan.close();
                               }
                             else if (("".equals(namaPengguna1)) && ("".equals(passwordPengguna1)))  
                               {  
                                   tombolHubungkankePadukData.setEnabled(false);  
                                   putuskanKoneksiKePadukData.setEnabled(false);  
                                   tombolUbahPadukData.setEnabled(false);  
                                   tombolBatal.setEnabled(false);
                                   masuk.setEnabled(true);
                                   statusKoneksi.setText("Tidak Ada Koneksi ke Paduk Data");
                                   keluar.setEnabled(true);  
                                   putuskanKoneksiKePadukData.setEnabled(false);  
                                   JOptionPane.showMessageDialog(null, dx, ex, JOptionPane.INFORMATION_MESSAGE);  
                                   connection.close();
                                   pernyataan.close();
                               }  
                          }  
                          catch (java.lang.Exception ex){ 
                              ex.printStackTrace();
                              statusMasuk.setText("Gagal Masuk");  
                          }
                }});
    
       keluar.addActionListener(new java.awt.event.ActionListener() {  
                @Override  
                public void actionPerformed(java.awt.event.ActionEvent evt) {  
                    keluar();  
                }  
      
                private void keluar() {  
                    System.exit(0);  
                }  
            });  
       tombolBatal.addActionListener(new java.awt.event.ActionListener() {  
                @Override  
                public void actionPerformed(java.awt.event.ActionEvent evt) {  
                    batal();  
                }  
      
                private void batal() {  
                    myocardialInfarction.setVisible(false);
                    stroke.setVisible(false);
                    for (int k = 0; k < 4; k++)  
                       {  
                          jawabKriteria[k][0].setText("");  
                          jawabKriteria[k][1].setText("");  
                          kriteria[k][0].setVisible(false);
                          kriteria[k][1].setVisible(false);
                       }  
                    for (int lkm = 0; lkm < 5; lkm++)  
                       {  
                          jawabAlternatif[lkm][0].setText("");  
                          jawabAlternatif[lkm][1].setText("");  
                          alternatif[lkm][0].setVisible(false);
                          alternatif[lkm][1].setVisible(false);
                       }  
                    for (int lqj = 0; lqj < 4; lqj++)  
                       {  
                          jawabKriteria[lqj][0].setEditable(false);  
                          jawabKriteria[lqj][1].setEditable(false); 
                          jawabKriteria[lqj][0].setVisible(false);  
                          jawabKriteria[lqj][1].setVisible(false);  
                       }  
                    for (int ljq = 0; ljq < 5; ljq++)  
                       {  
                          jawabAlternatif[ljq][0].setEditable(false);  
                          jawabAlternatif[ljq][1].setEditable(false);  
                          jawabAlternatif[ljq][0].setVisible(false);  
                          jawabAlternatif[ljq][1].setVisible(false);  
                       }  
                    lanjut.setEnabled(false);  
                }  
            });  
       tombolHubungkankePadukData.addActionListener(new java.awt.event.ActionListener() {  
                @Override  
                public void actionPerformed(java.awt.event.ActionEvent evt) {  
                    if (connection == null)  
                     {  
                       connectToDB();  
                       statusKoneksi.setText("Terhubung ke Paduk Data");  
                     }  
                    else  
                     {  
                        statusKoneksi.setText("Sudah Terhubung ke Paduk Data");  
                     }  
                }  
        });  
    for (int m = 0; m <5; m++)  
       {  
          jawabAlternatif[m][0].setEditable(false);  
          jawabAlternatif[m][1].setEditable(false);  
       }  
    for (int hki = 0; hki < 4; hki++)  
       {  
          jawabKriteria[hki][0].setEditable(false);  
          jawabKriteria[hki][1].setEditable(false);  
       }  
    // Tanda Alternatif Harga Myocardial Infarction  
    kriteria[0][0].setBounds(1,200,100,25);  
    kriteria[1][0].setBounds(1,230,100,25);  
    kriteria[2][0].setBounds(1,260,100,25);  
    kriteria[3][0].setBounds(1,290,100,25);  
    for (int lop = 0; lop < 4; lop++)  
       {  
          konten.add(kriteria[lop][0]);  
       }  
    // Alternatif Sakit Harga Myocardial Infarction  
    jawabKriteria[0][0].setBounds(101,200,70,25);  
    jawabKriteria[1][0].setBounds(101,230,70,25);  
    jawabKriteria[2][0].setBounds(101,260,70,25);  
    jawabKriteria[3][0].setBounds(101,290,70,25);  
    for (int jki = 0; jki < 4; jki++)  
       {  
          konten.add(jawabKriteria[jki][0]);  
       }  
    // Kriteria Sakit Myocardial Infarction  
    alternatif[0][0].setBounds(200,200,100,25);  
    alternatif[1][0].setBounds(200,230,100,25);  
    alternatif[2][0].setBounds(200,260,100,25);  
    alternatif[3][0].setBounds(200,290,100,25);  
    alternatif[4][0].setBounds(200,320,100,25);  
      
    for (int loyo = 0; loyo < 5; loyo++)  
       {  
          konten.add(alternatif[loyo][0]);  
       }  
    jawabAlternatif[0][0].setBounds(360,200,70,25);  
    jawabAlternatif[1][0].setBounds(360,230,70,25);  
    jawabAlternatif[2][0].setBounds(360,260,70,25);  
    jawabAlternatif[3][0].setBounds(360,290,70,25);  
    jawabAlternatif[4][0].setBounds(360,320,70,25);  
    for (int gfk = 0; gfk < 5; gfk++)  
       {  
           konten.add(jawabAlternatif[gfk][0]);  
       }  
    // Awal Stroke  
    stroke.setBounds(0,380,200,25);  
    konten.add(stroke);  
    // Tanda Kriteria Stroke  
    kriteria[0][1].setBounds(1,420,200,25);  
    kriteria[1][1].setBounds(1,450,200,25);  
    kriteria[2][1].setBounds(1,480,200,25);  
    kriteria[3][1].setBounds(1,510,200,25);  
    for (int gdu = 0; gdu < 4; gdu++)  
       {  
          konten.add(kriteria[gdu][1]);  
       }  
    // Kriteria Sakit Stroke  
    jawabKriteria[0][1].setBounds(101,420,60,25);  
    jawabKriteria[1][1].setBounds(101,450,60,25);  
    jawabKriteria[2][1].setBounds(101,480,60,25);  
    jawabKriteria[3][1].setBounds(101,510,60,25);  
    for (int jku = 0; jku < 4; jku++)  
       {  
          konten.add(jawabKriteria[jku][1]);  
       }  
    alternatif[0][1].setBounds(200,420,100,25);  
    alternatif[1][1].setBounds(200,450,100,25);  
    alternatif[2][1].setBounds(200,480,100,25);  
    alternatif[3][1].setBounds(200,510,100,25);  
    alternatif[4][1].setBounds(200,540,100,25);  
    for (int loyom = 0; loyom < 5; loyom++)  
       {  
          konten.add(alternatif[loyom][1]);  
       }  
    jawabAlternatif[0][1].setBounds(360,420,70,25);  
    jawabAlternatif[1][1].setBounds(360,450,70,25);  
    jawabAlternatif[2][1].setBounds(360,480,70,25);  
    jawabAlternatif[3][1].setBounds(360,510,70,25);  
    jawabAlternatif[4][1].setBounds(360,540,70,25);  
    for (int gfki = 0; gfki < 5; gfki++)  
       {  
          konten.add(jawabAlternatif[gfki][1]);  
       }  
    lanjut.setBounds(880,560,100,25);  
    konten.add(lanjut);  
    lanjut.setEnabled(false);  
      
    } //Akhir Konstruktor  
    
    public static void main(String[] args)  
    {  
            ProgramTesisBaru tesis = new ProgramTesisBaru();   
            tesis.setTitle("Program Pemilihan Obat dengan Cara Analytic Hierarchycal Process");  
            tesis.setSize(1024,768);  
            tesis.setVisible(true);  
            tesis.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
            tesis.setLocationRelativeTo(null);  
    }};
    I did format the code properly. If this forum cannot show them, what will I need to do?

    Basically, it is the same with NewMain but I put event handler for every button that is created in NewMain. After the user can enter successfully, he can choose whether to connect, disconnect, make change or to cancel the change to the database. We don't have to see the change or cancel part first. We look at the connect or disconnect first, what is happening? Why can't I connect correctly? After I disconnect the code from database and try to reconnect it, the message will be sudah terhubung ke paduk data. That is not the message that I want. The message that I want the code to show is terhubung ke paduk data. How to make this happen? What make it show an incorrect message? One more, why do the masuk button and keluar button disappear very often after I run the code? Where do you want me to put the println?
    Last edited by Tawijakarta; June 20th, 2013 at 11:57 AM.
  6. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    What make it show an incorrect message?
    I can not see what the code does unless you copy and paste here the full contents of the console from when you execute the code. To debug the code there needs to be lots of println statements in it that shows where the code is executing and what the values of the variables are when it is executing.

    The code in post #170 is not a full program that can be compiled and executed for testing.

    Is this the code with the messages that you are talking about:
    Code:
                    if (connection == null)  
                     {  
                       connectToDB();  
                       statusKoneksi.setText("Terhubung ke Paduk Data");  
                     }  
                    else  
                     {  
                        statusKoneksi.setText("Sudah Terhubung ke Paduk Data");  
                     }
    The value of the connecion variable controls which message you get.
    If null, the first message.
    If not null, the second message
    Last edited by NormR; June 20th, 2013 at 12:04 PM.
  7. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Originally Posted by NormR
    I can not see what the code does unless you copy and paste here the full contents of the console from when you execute the code. To debug the code there needs to be lots of println statements in it that shows where the code is executing and what the values of the variables are when it is executing.

    The code in post #170 is not a full program that can be compiled and executed for testing.

    Is this the code with the messages that you are talking about:
    Code:
                    if (connection == null)  
                     {  
                       connectToDB();  
                       statusKoneksi.setText("Terhubung ke Paduk Data");  
                     }  
                    else  
                     {  
                        statusKoneksi.setText("Sudah Terhubung ke Paduk Data");  
                     }
    The value of the connecion variable controls which message you get.
    If null, the first message.
    If not null, the second message
    What should I do to make is show the first message? The first part was posted in #168. What console do you mean? FrameBaru was posted prior these two code, you can search the other posts.
  8. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    What should I do to make is show the first message?
    Change the value of the connection variable to null.

    What console do you mean?
    The console(or command prompt window) is where the output from a println() method displays.
  9. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Originally Posted by NormR
    Change the value of the connection variable to null.
    How? How to disconnect the database from the code?
  10. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    How to disconnect the database
    I don't know what you mean by "disconnect".
    Do you mean "close"? Call the close() method.
  11. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Originally Posted by NormR
    I don't know what you mean by "disconnect".
    Do you mean "close"? Call the close() method.
    I did but it didn't close the database. Am I missing any close() methods that I need to put? Where do I miss these close() methods?
  12. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    it didn't close the database
    How do you know that the database is not closed? What happens when the program is executed that tells you the DB is not closed?

    Where is the code executing the close() methods? Add some println stateements next to where each close() method is called so you can see what statements are being executed.
    Just having a statement in the code does NOT mean that it will be executed. Looking at code will not tell you IF a statement will be executed when the program runs.
    When a println() statment prints out a message THEN you know that the statement is being executed. You may hope that a statement will be executed, but it may not be executed. Having a println() call next to a statement will show if the statement is executed.
  13. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Originally Posted by NormR
    How do you know that the database is not closed? What happens when the program is executed that tells you the DB is not closed?

    Where is the code executing the close() methods? Add some println stateements next to where each close() method is called so you can see what statements are being executed.
    Just having a statement in the code does NOT mean that it will be executed. Looking at code will not tell you IF a statement will be executed when the program runs.
    When a println() statment prints out a message THEN you know that the statement is being executed. You may hope that a statement will be executed, but it may not be executed. Having a println() call next to a statement will show if the statement is executed.
    In fact it shows a wrong message. In every if that test the username and password I put the close() method. Where do you think that I need to put any other close() methods?
  14. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    In fact it shows a wrong message
    Please explain how showing a message means that the DB is not closed? Does the code use the isClosed() method? What value does that method return?
  15. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Originally Posted by NormR
    Please explain how showing a message means that the DB is not closed? Does the code use the isClosed() method? What value does that method return?
    Well, I told you that if the database is closed, it will show a correct message. How to fix that?

IMN logo majestic logo threadwatch logo seochat tools logo