#16
  1. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    Look at the API doc for the Container class for methods that set the layout manager
  2. #17
  3. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    I use this code

    Code:
    setLayout(null);
    It is not working so? What should I do?
  4. #18
  5. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    What container did you call that method for?

    Post the current code that compiles, executes and shows the problem.
  6. #19
  7. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package programtesisbaru;
    
    import java.sql.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.*;
    
    /**
     *
     * @author Tawi
     */
    public class NewMain extends JFrame {
        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"); 
        String namaPengguna1;  
        String passwordPengguna1; 
        Connection connection;  
        Statement statement; 
        JLabel statusMasuk = new JLabel("Belum Masuk");  
        JComboBox jcboURL = new JComboBox (new String[] {"jdbc:odbc:DatabaseKlinik"});  
        JComboBox jcboDriver = new JComboBox (new String[] {"sun.jdbc.odbc.JdbcOdbcDriver"});  
        JLabel statusKoneksi = new JLabel("Tidak ada Koneksi ke Paduk Data");  
        String ax = "Nama Dokter Belum Dimasukkan";   
        String bx = "Dokter atau Kata Sandi tidak Ada";  
        String cx = "Kata Sandi Belum Dimasukkan";  
        String dx = "Nama Dokter Belum Dimasukkan";  
        String ex = "Dokter tidak Dikenal";  
        String fx = "Kata Kunci tidak Benar";  
        String gx = "Nama Pengguna dan Kata Kunci tidak Benar";  
        String hx = "Nama Dokter dan Kata Sandi tidak Ada";  
        
      public NewMain() {  
      
    // Atur letak beberapa komponen  
    setLayout(null);
    statusKoneksi.setVisible(true);  
    lblNama.setVisible(true);  
    txtNama.setVisible(true);  
    kataSandi.setVisible(true);  
    sandiKata.setVisible(true);  
    masuk.setVisible(true);  
    keluar.setVisible(true);  
    lblNama.setBounds(0,10,100,25);  
    add(lblNama);  
    txtNama.setBounds(130,10,200,25);  
    add(txtNama);  
    kataSandi.setBounds(330,10,100,25);  
    add(kataSandi);  
    sandiKata.setBounds(410,10,200,25);  
    add(sandiKata);  
    masuk.setBounds(600,10,100,25);  
    add(masuk);  
    keluar.setBounds(700,10,100,25);  
    add(keluar);  
    masuk.addActionListener(new java.awt.event.ActionListener() {  
                String loginName;  
                String loginPassword;    
                String usrname;
                String passwrd;
                String psswrd;
                @Override  
                public void actionPerformed(java.awt.event.ActionEvent evt) {  
                    try {  
                        masuklah();  
                    }   
                    catch (SQLException ex) {  
                        Logger.getLogger(ProgramTesisBaru.class.getName()).log(Level.SEVERE, null, ex);  
                    }  
                }  
      
                private void masuklah() throws SQLException {  
                      if (connection == null)  
                      {  
                          masuk.setEnabled(false);  
                          connectToDB();  
                          entryPrg();  
                      }  
                      else {
                          entryPrg();  
                      }  
                }  
      
                public void connectToDB() {  
                    String uniRL = (String)jcboURL.getSelectedItem();  
                    String driver = (String) jcboDriver.getSelectedItem();  
                    //URL uniRL = (URL)jcboURL.getSelectedItem();  
                    usrname = txtNama.getText().trim();  
                    passwrd = new String(sandiKata.getPassword());  
                    try {  
                        Class.forName(driver);  
                        connection = DriverManager.getConnection(uniRL, usrname, passwrd);  
                        //rowSet.setURL(uniRL);  
                        statusKoneksi.setText("Terhubung ke Paduk Data");  
                    }  
                    catch (java.lang.Exception ex) {  
                        statusKoneksi.setText("Gagal Terhubung ke Paduk Data");  
                    }  
                }  
      
                private void entryPrg() throws SQLException {  
                          usrname = txtNama.getText().trim();  
                          psswrd = new String(sandiKata.getPassword());  
                          loginName = "select Nama_Dokter from tblDokterNaraSumber where Nama_Dokter = '"+usrname+"'";  
                          loginPassword = "select Password from tblDokterNaraSumber where Nama_Dokter = '"+usrname+"'";  
                          try {  
                          ResultSet logName = statement.executeQuery(loginName);  
                          ResultSet logPassword = statement.executeQuery(loginPassword);  
                          while (logName.next()) 
                               {  
                               namaPengguna1 = logName.getString("Nama_Dokter");  
                               }  
                          while (logPassword.next()) 
                               {  
                               passwordPengguna1 = logPassword.getString("Password");  
                               }  
                          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");
                                   connection.close();
                                   keluar.setEnabled(true);  
                                   //putuskanKoneksiKePadukData.setEnabled(false);  
                                   JOptionPane.showMessageDialog(null, gx, hx, JOptionPane.INFORMATION_MESSAGE);  
                                 }  
                        else if ((!"".equals(usrname)) && (!"".equals(psswrd)))  
                          {  
                             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);  
                                   connection.close();  
                                }  
                             else if ((!"".equals(namaPengguna1)))  
                                {  
                                   //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, fx, bx, JOptionPane.INFORMATION_MESSAGE);  
                                   connection.close();  
                               }  
                            else if ((!"".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, ex, bx, JOptionPane.INFORMATION_MESSAGE);  
                                   connection.close();  
                               }  
        }  
        else if (!"".equals(usrname))  
        {  
            if (("".equals(namaPengguna1)) && ("".equals(passwordPengguna1)))   
            {  
            JOptionPane.showMessageDialog(null, cx, bx, 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);  
              connection.close();                          
            }  
            else if (("".equals(namaPengguna1)))  
            {  
              //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, bx, JOptionPane.INFORMATION_MESSAGE);                
              connection.close();                          
            }  
          else if (("".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, cx, bx, JOptionPane.INFORMATION_MESSAGE);                          
            connection.close();                          
          }  
        }  
        else if (!"".equals(psswrd))  
        {  
            if (("".equals(namaPengguna1)) && ("".equals(passwordPengguna1)))   
          {  
            JOptionPane.showMessageDialog(null, dx, bx, JOptionPane.INFORMATION_MESSAGE);  
            //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);                          
            connection.close();                          
          }  
          else if (("".equals(namaPengguna1)))  
          {  
            //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, bx, JOptionPane.INFORMATION_MESSAGE);                          
            connection.close();                          
          }  
          else if (("".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, bx, JOptionPane.INFORMATION_MESSAGE);                          
            connection.close();                          
          }  
        }     
                          }  
                          catch (java.lang.Exception ex){  
                              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);  
                }  
            });  
      }
        public static void main(String[] args) {
            NewMain mainkan = new NewMain();// TODO code application logic here
            mainkan.setVisible(true);
            mainkan.setTitle("Program Pemilihan Obat dengan Cara Analytic Hierarchycal Process");
            mainkan.setSize(1024,768); 
            mainkan.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
            mainkan.setLocationRelativeTo(null);
        }
    }
  8. #20
  9. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    It is not working so?
    The code shows 6 components across the top of the frame when it is executed.
    Can you explain what the problem is with: setLayout(null)?
    It seems to work for me.
  10. #21
  11. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Well, it will show me nothing if I do not put my mouse pointer above the component, can you explain the reason?
  12. #22
  13. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    The code in post#19 works for me. I don't know what could be the problem for you.

    One thing I see that is unusual is all the calls to setVisible() for the components. That should not be needed.

    Another possible problem is the call to setVisible() BEFORE the frame is ready to be shown. Try calling it AFTER all the GUI has been made ready to see.
    Last edited by NormR; May 1st, 2013 at 12:38 PM.
  14. #23
  15. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Can you post the code that you think must be made by me to make the code better?
  16. #24
  17. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    The code that worked for me is in post#19
  18. #25
  19. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    I cannot connect to the database in my code, why? How to solve it? The JOptionPane is not showing either, can you help me to solve these problems?
  20. #26
  21. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    Sorry, I don't know anything about databases.

    What is the problem with the JOptionPane method?

    Can you make a small, complete program that compiles, executes and shows the JOptionPane problem?
  22. #27
  23. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,020
    Rep Power
    1285
    Originally Posted by Tawijakarta
    I cannot connect to the database in my code, why? How to solve it? The JOptionPane is not showing either, can you help me to solve these problems?
    Do you have the appropriate jar file in your CLASSPATH?
  24. #28
  25. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    The posted one in #19 shows the problem. The JOptionPane is not showing if any of the JTextFields are empty. I want the JOptionPane to show up if there are some of the JTextFields are empty. How to do this?
  26. #29
  27. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Originally Posted by bullet
    Do you have the appropriate jar file in your CLASSPATH?
    From the code in #19, what jar file should I have? Where should I get it?
  28. #30
  29. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    I cannot connect to the database in my code
    What is the full text of the error message you get? Does it say there is a missing definition for a class?
    If that is the error, you need to find the jar file that contains that class and add it to the classpath when the code is executed.

IMN logo majestic logo threadwatch logo seochat tools logo