Search code examples
javaswingnetbeansjdbcjcombobox

JComboBox gives an array after running for 3 times [jdbc]


i was making an library management system, here when u are adding book, u select a category from jcombobox, now jcombobox is getting categories(items) from another table, issue is this that it runs perfectly for two or three times after it , it gives an error and ADD BOOK frame doesnt load, coding and error message and screen shots are below :)

Category Table

enter image description here

Book Table

enter image description here

book category is FK to category table

now here is the code which is fetching data from category table to jcombobox

JComboBox category = new JComboBox();
    try {
        MyConnection mc = new MyConnection();
        Class.forName(mc.driver);
        Connection connect = DriverManager.getConnection(mc.login);
        Statement state = connect.createStatement();
        ResultSet rs = state.executeQuery("select book_category from library_category");            
        while (rs.next()) {
            String item = rs.getString("book_category");
            category.addItem(item);
        }

    } catch (SQLException ex) {
        System.out.println("Error");
        ex.printStackTrace();
    } catch (ClassNotFoundException ex) {
        System.out.println("Class not found");
        ex.printStackTrace();
    }
    category.setBounds(300, 240, 150, 30);
    category.setVisible(true);
    panel.add(category);

and this is the other half code (code was too long so im just posting everything regarded to this issue)

    JButton btn_add = new JButton("ADD");
    btn_add.setBounds(300, 350, 80, 30);
    panel.add(btn_add);
    btn_add.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {

            String[] pattern = new String[4];

            pattern[0] = "^[A-Za-z0-9]{3,10}$";
            pattern[1] = "^[A-Za-z0-9 ]{3,40}$";
            pattern[2] = "^[\\p{L} .'-]{4,30}$";
            pattern[3] = "^[1-9]\\d*$";

            //--------------------------------------
            String[] field = new String[5];

            field[0] = bkid.getText();
            field[1] = txtid.getText();
            field[2] = re.getText();
            field[3] = (String) category.getSelectedItem();
            field[4] = txtqun.getText();

            if (field[0].isEmpty()) {
                obj.info("Please enter book code!", "Error");
                return;
            }

            if (field[1].isEmpty()) {
                obj.info("Please enter book name!", "Error");
                return;
            }

            if (field[2].isEmpty()) {
                obj.info("Please enter author's name!", "Error");
                return;
            }

            if (field[4].isEmpty()) {
                obj.info("Please enter book's quantity!", "Error");
                return;
            }

            Pattern pat1 = Pattern.compile(pattern[0]),
                    pat2 = Pattern.compile(pattern[1]),
                    pat3 = Pattern.compile(pattern[2]),
                    pat4 = Pattern.compile(pattern[3]);

            Matcher mat1 = pat1.matcher(field[0]),
                    mat2 = pat2.matcher(field[1]),
                    mat3 = pat3.matcher(field[2]),
                    mat4 = pat4.matcher(field[4]);

            if (mat1.matches()) {
                if (mat2.matches()) {
                    if (mat3.matches()) {
                        if (mat4.matches()) {

                            try {
                                MyConnection mc = new MyConnection();
                                Class.forName(mc.driver);
                                Connection connect = DriverManager.getConnection(mc.login);
                                PreparedStatement pst = connect.prepareStatement("insert into library_book values (?,?,?,?,?);");
                                pst.setString(1, field[0]);
                                pst.setString(2, field[1]);
                                pst.setString(3, field[2]);
                                pst.setString(4, field[3]);
                                pst.setString(5, field[4]);
                                pst.execute();
                                frame.dispose();
                                obj.info("You've successfully added " + field[1] + " book to Library System Management", "Congratulations!");
                                connect.close();
                                bkid.setText("");
                                txtid.setText("");
                                re.setText("");
                                txtqun.setText("");

                            } catch (SQLException ex) {
                                System.out.println("Error");
                                ex.printStackTrace();

                            } catch (ClassNotFoundException ex) {
                                System.out.println("Class not found");
                                ex.printStackTrace();
                            }

                        } else {
                            obj.info("Please use only numbers in book quantity!", "Error");
                        }
                    } else {
                        obj.info("Please use only alphabets in Author Name!", "Error");
                    }
                } else {
                    obj.info("Please use only alphabets in Book Name!", "Error");
                }
            } else {
                obj.info("Please use only numbers and alphabets in Book Code!", "Error");
            }

        }
    });

    JButton exit = new JButton("exit");
    panel.add(exit);
    exit.setBounds(400, 350, 80, 30);
    exit.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            bkid.setText("");
            txtid.setText("");
            re.setText("");
            txtqun.setText("");
            frame.dispose();
        }

everything is running perfectly, working perfectly , but i get this issue after opening the add book frame for three times

this is twice i runned it

enter image description here

and finally when i opened this add book frame for the 3rd time ( note: i didnt close the parent frame ) i get this, it doesnt open, and error shows upenter image description here

now after reading this long error i found out it is regarding some pointer that points at row, when its fetching data from table, i tried to reset it or close the result set but nothing is happening, please help me, i've to submit this project tomorrow :)

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: illegal component position at java.awt.Container.addImpl(Container.java:1093) at javax.swing.JLayeredPane.addImpl(JLayeredPane.java:230) at javax.swing.JDesktopPane.addImpl(JDesktopPane.java:484) at java.awt.Container.add(Container.java:410) at libraraylms.LibrarayLMS$2.actionPerformed(LibrarayLMS.java:48) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.AbstractButton.doClick(AbstractButton.java:376) at com.birosoft.liquid.LiquidMenuItemUI.doClick(LiquidMenuItemUI.java:492) at com.birosoft.liquid.LiquidMenuItemUI$MouseInputHandler.mouseReleased(LiquidMenuItemUI.java:1161) at java.awt.Component.processMouseEvent(Component.java:6516) at javax.swing.JComponent.processMouseEvent(JComponent.java:3320) at java.awt.Component.processEvent(Component.java:6281) at java.awt.Container.processEvent(Container.java:2229) at java.awt.Component.dispatchEventImpl(Component.java:4872) at java.awt.Container.dispatchEventImpl(Container.java:2287) at java.awt.Component.dispatchEvent(Component.java:4698) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422) at java.awt.Container.dispatchEventImpl(Container.java:2273) at java.awt.Window.dispatchEventImpl(Window.java:2719) at java.awt.Component.dispatchEvent(Component.java:4698) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735) at java.awt.EventQueue.access$200(EventQueue.java:103) at java.awt.EventQueue$3.run(EventQueue.java:694) at java.awt.EventQueue$3.run(EventQueue.java:692) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87) at java.awt.EventQueue$4.run(EventQueue.java:708) at java.awt.EventQueue$4.run(EventQueue.java:706) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:705) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

BUILD SUCCESSFUL (total time: 10 seconds)

as @HovercraftFullOfEels sir asked about

Which line is LibrarayLMS.java:48, line 48 of LibrarayLMS.java class?

here is that block of code

    JMenu books = new JMenu("Book's");
    mb.add(books);
    JMenuItem adbook = new JMenuItem("Add Books");
    books.add(adbook);
    adbook.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Addbook objadd = new Addbook();
            objadd.addframe();
            objadd.frame.setVisible(true);
            desktop.add(objadd.frame);  // ******* - LINE #48 *********
            try {
                objadd.frame.setSelected(true);
            } catch (PropertyVetoException exn) {
                exn.printStackTrace();
            }

        }
    });

as @HovercraftFullOfEels sir asked about " You'll need to look into the Addbook class perhaps including its addFrame() method and its frame field. Post it here if possible. "

here is the full code of add book

package libraraylms;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.regex.*;
import static libraraylms.Login.obj;
import static libraraylms.registerstd.frame;

public class Addbook {

    public void info(String message, String title) {
        JOptionPane.showMessageDialog(null, message, "NOTE:" + title, JOptionPane.INFORMATION_MESSAGE);
    }
    static JInternalFrame frame = new JInternalFrame("Add Book");
    JComboBox category = new JComboBox();

    public void addframe() {

        try {
            UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");

        } catch (Exception e) {
            e.printStackTrace();
        }
        JPanel panel = new JPanel();
        frame.setSize(700, 568);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.add(panel);
        frame.setResizable(false);

        panel.setLayout(null);

        try {
            MyConnection mc = new MyConnection();
            Class.forName(mc.driver);
            Connection connect = DriverManager.getConnection(mc.login);
            Statement state = connect.createStatement();
            ResultSet rs = state.executeQuery("select book_category from library_category");            
            while (rs.next()) {
                String item = rs.getString("book_category");
                category.addItem(item);
            }

        } catch (SQLException ex) {
            System.out.println("Error");
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            System.out.println("Class not found");
            ex.printStackTrace();
        }
        category.setBounds(300, 240, 150, 30);
        category.setVisible(true);
        panel.add(category);

        JLabel heading = new JLabel("ADD BOOK");
        heading.setBounds(320, 1, 200, 100);
        heading.setFont(new Font("Serif", Font.BOLD, 30));
        panel.add(heading);

        JLabel b_id = new JLabel("Book code:");
        b_id.setBounds(200, 65, 670, 150);
        b_id.setForeground(Color.white);
        panel.add(b_id);

        final JTextField bkid = new JTextField(20);
        bkid.setBounds(300, 130, 200, 20);
        panel.add(bkid);

        JLabel id = new JLabel("Book name:");
        id.setBounds(200, 100, 670, 150);
        id.setForeground(Color.white);
        panel.add(id);

        final JTextField txtid = new JTextField(20);
        txtid.setBounds(300, 165, 200, 20);
        panel.add(txtid);

        JLabel author = new JLabel("author name:");
        author.setBounds(200, 135, 670, 150);
        author.setForeground(Color.white);
        panel.add(author);

        final JTextField re = new JTextField(20);
        re.setBounds(300, 200, 200, 20);
        panel.add(re);

        JLabel catog = new JLabel("Category:");
        catog.setBounds(200, 180, 670, 150);
        catog.setForeground(Color.white);
        panel.add(catog);

        JLabel qun = new JLabel("Book Quantity:");
        qun.setBounds(200, 240, 670, 150);
        qun.setForeground(Color.white);
        panel.add(qun);

        final JTextField txtqun = new JTextField(20);
        txtqun.setBounds(300, 300, 50, 20);
        panel.add(txtqun);

        JButton btn_add = new JButton("ADD");
        btn_add.setBounds(300, 350, 80, 30);
        panel.add(btn_add);
        btn_add.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ev) {

                String[] pattern = new String[4];

                pattern[0] = "^[A-Za-z0-9]{3,10}$";
                pattern[1] = "^[A-Za-z0-9 ]{3,40}$";
                pattern[2] = "^[\\p{L} .'-]{4,30}$";
                pattern[3] = "^[1-9]\\d*$";

                //--------------------------------------
                String[] field = new String[5];

                field[0] = bkid.getText();
                field[1] = txtid.getText();
                field[2] = re.getText();
                field[3] = (String) category.getSelectedItem();
                field[4] = txtqun.getText();

                if (field[0].isEmpty()) {
                    obj.info("Please enter book code!", "Error");
                    return;
                }

                if (field[1].isEmpty()) {
                    obj.info("Please enter book name!", "Error");
                    return;
                }

                if (field[2].isEmpty()) {
                    obj.info("Please enter author's name!", "Error");
                    return;
                }

                if (field[4].isEmpty()) {
                    obj.info("Please enter book's quantity!", "Error");
                    return;
                }

                Pattern pat1 = Pattern.compile(pattern[0]),
                        pat2 = Pattern.compile(pattern[1]),
                        pat3 = Pattern.compile(pattern[2]),
                        pat4 = Pattern.compile(pattern[3]);

                Matcher mat1 = pat1.matcher(field[0]),
                        mat2 = pat2.matcher(field[1]),
                        mat3 = pat3.matcher(field[2]),
                        mat4 = pat4.matcher(field[4]);

                if (mat1.matches()) {
                    if (mat2.matches()) {
                        if (mat3.matches()) {
                            if (mat4.matches()) {

                                try {
                                    MyConnection mc = new MyConnection();
                                    Class.forName(mc.driver);
                                    Connection connect = DriverManager.getConnection(mc.login);
                                    PreparedStatement pst = connect.prepareStatement("insert into library_book values (?,?,?,?,?);");
                                    pst.setString(1, field[0]);
                                    pst.setString(2, field[1]);
                                    pst.setString(3, field[2]);
                                    pst.setString(4, field[3]);
                                    pst.setString(5, field[4]);
                                    pst.execute();
                                    frame.dispose();
                                    obj.info("You've successfully added " + field[1] + " book to Library System Management", "Congratulations!");
                                    connect.close();
                                    bkid.setText("");
                                    txtid.setText("");
                                    re.setText("");
                                    txtqun.setText("");

                                } catch (SQLException ex) {
                                    System.out.println("Error");
                                    ex.printStackTrace();

                                } catch (ClassNotFoundException ex) {
                                    System.out.println("Class not found");
                                    ex.printStackTrace();
                                }

                            } else {
                                obj.info("Please use only numbers in book quantity!", "Error");
                            }
                        } else {
                            obj.info("Please use only alphabets in Author Name!", "Error");
                        }
                    } else {
                        obj.info("Please use only alphabets in Book Name!", "Error");
                    }
                } else {
                    obj.info("Please use only numbers and alphabets in Book Code!", "Error");
                }

            }
        });

        JButton exit = new JButton("exit");
        panel.add(exit);
        exit.setBounds(400, 350, 80, 30);
        exit.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                bkid.setText("");
                txtid.setText("");
                re.setText("");
                txtqun.setText("");
                frame.dispose();
            }

        });
        JLabel logo = new JLabel(new ImageIcon("C:\\Users\\ramb0\\Documents\\NetBeansProjects\\LibrarayLMS\\book.jpg"));
        panel.add(logo);
        logo.setSize(700, 568);
        frame.setVisible(true);
    }
}

and here is the code of parent class , the main frame, the KING,

package libraraylms;

import javax.swing.JDesktopPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import javax.swing.*;

public class LibrarayLMS {

    public void info(String message, String title) {
        JOptionPane.showMessageDialog(null, message, "NOTE:" + title, JOptionPane.INFORMATION_MESSAGE);
    }

    JDesktopPane desktop;
    JFrame f = new JFrame("A.M Library");

    public void framelaunch() {

        try {
            UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");

        } catch (Exception ec) {
            ec.printStackTrace();
        }
        JMenuBar mb = new JMenuBar();

        JMenu menu = new JMenu("File");
        mb.add(menu);

        JMenuItem exit = new JMenuItem("Quit");
        menu.add(exit);
        exit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });

        JMenu books = new JMenu("Book's");
        mb.add(books);
        JMenuItem adbook = new JMenuItem("Add Books");
        books.add(adbook);
        adbook.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Addbook objadd = new Addbook();
                objadd.addframe();
                objadd.frame.setVisible(true);
                desktop.add(objadd.frame);
                try {
                    objadd.frame.setSelected(true);
                } catch (PropertyVetoException exn) {
                    exn.printStackTrace();
                }

            }
        });

        JMenuItem issuebook = new JMenuItem("Issue Book");
        books.add(issuebook);

        issuebook.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {

                issue frame = new issue();
                frame.LaunchInternalFrame();
                frame.interFrame.setVisible(true);
                desktop.add(frame.interFrame);
                try {
                    frame.interFrame.setSelected(true);
                } catch (PropertyVetoException ex) {
                    ex.printStackTrace();
                }

            }
        }
        );

        JMenuItem rebook = new JMenuItem("Return Book");

        books.add(rebook);

        rebook.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                returns obj = new returns();
                obj.returnframe();
                obj.frame.setVisible(true);
                desktop.add(obj.frame);

                try {
                    obj.frame.setSelected(true);
                } catch (PropertyVetoException exx) {
                    exx.printStackTrace();
                }
            }

        });

        JMenuItem bookstatus = new JMenuItem("Book Status");

        books.add(bookstatus);

        bookstatus.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                bookstatus objst = new bookstatus();
                objst.status();
                objst.framest.setVisible(true);
                desktop.add(objst.framest);

                try {
                    objst.framest.setSelected(true);
                } catch (PropertyVetoException exxn) {
                    exxn.printStackTrace();
                }
            }

        });

        JMenuItem bookscat = new JMenuItem("Add Category");
        books.add(bookscat);

        bookscat.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                addCategory objcat = new addCategory();
                objcat.category();
                objcat.catframe.setVisible(true);
                desktop.add(objcat.catframe);

                try {
                    objcat.catframe.setSelected(true);
                } catch (PropertyVetoException n) {
                    n.printStackTrace();
                }
            }

        });

        JMenu reg = new JMenu("Register");
        mb.add(reg);
        JMenuItem adm = new JMenuItem("Admin");
        reg.add(adm);
        adm.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
              registeradmin amframe= new registeradmin();
              amframe.register();
              amframe.adminframe.setVisible(true);
              desktop.add(amframe.adminframe);
              try{
                    amframe.adminframe.setSelected(true);

              }catch (PropertyVetoException eee) {
                    eee.printStackTrace();

              }
            }
        });
        JMenuItem remem = new JMenuItem("Member");
        reg.add(remem);

        remem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent en) {

                registerstd f = new registerstd();
                f.register();
                f.frame.setVisible(true);
                desktop.add(f.frame);
                try {
                    f.frame.setSelected(true);
                } catch (PropertyVetoException e) {
                    e.printStackTrace();
                }
            }
        });

        JMenuItem report = new JMenuItem("Report");
        books.add(report);
        report.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {

                report frm = new report();
                frm.reports();
                frm.reportframe.setVisible(true);
                desktop.add(frm.reportframe);

                try {
                    frm.reportframe.setSelected(true);
                } catch (PropertyVetoException el) {
                    el.printStackTrace();
                }
            }

        });

        JMenu Help = new JMenu("Help");
        mb.add(Help);
        JMenuItem help = new JMenuItem("Help");
        Help.add(help);
        JMenuItem About = new JMenuItem("About");
        Help.add(About);
        About.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {

                about frme = new about();
                frme.aboutframe();
                frme.abframe.setVisible(true);
                desktop.add(frme.abframe);

                try {
                    frme.abframe.setSelected(true);
                } catch (PropertyVetoException el) {
                    el.printStackTrace();
                }
            }

        });

        desktop = new JDesktopPane(); //a specialized layered pane
        desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
        JLabel logo = new JLabel(new ImageIcon("C:\\Users\\ramb0\\Documents\\NetBeansProjects\\LibrarayLMS\\download.jpg"));
        desktop.add(logo);
        logo.setSize(1000, 625);
        f.getContentPane().add(desktop);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
        f.setJMenuBar(mb);
        f.setSize(1000, 625);
        f.setResizable(false);
        f.setContentPane(desktop);
    }

    public static void main(String[] args) {
        LibrarayLMS myframe = new LibrarayLMS();
        myframe.framelaunch();
    }

}

Solution

  • Yes, your problem is that you're using a static JInternalFrame and adding the same internal frame over and over again to the JDesktopPane. Don't do this. Instead, if you must use JInternalFrames, then create a new one as needed. Myself, I'd swap JPanels via a CardLayout.

    Here is my true-MCVE, a small compilable program that reproduces your problem. Note that I created this by successive commenting blocks of your code, then removing the commented blocks if they weren't needed to compile and reproduce the problem, until I was left with bare essential code that showed the problem.

    Please comment and un-comment the line indicated.

    import java.awt.event.*;
    import java.beans.PropertyVetoException;
    import javax.swing.*;
    
    public class Mcve1 {
       private static void createAndShowGui() {
          LibrarayLMS.main(null);
       }
    
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             public void run() {
                createAndShowGui();
             }
          });
       }
    }
    
    class Addbook {
       static JInternalFrame frame = new JInternalFrame("Add Book");
    
       public void addframe() {
          JPanel panel = new JPanel();
    
          // ****** comment and un-comment the line below
          // frame = new JInternalFrame("Add Book");
    
          frame.setSize(700, 568);
          frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          frame.add(panel);
          frame.setResizable(false);
          JButton btn_add = new JButton("ADD");
          panel.add(btn_add);
          btn_add.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent ev) {
                frame.dispose();
             }
          });
          JButton exit = new JButton("exit");
          panel.add(exit);
          exit.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                frame.dispose();
             }
          });
          frame.setVisible(true);
       }
    }
    
    class LibrarayLMS {
    
       JDesktopPane desktop;
       JFrame f = new JFrame("A.M Library");
    
       public void framelaunch() {
          JMenuBar mb = new JMenuBar();
          JMenu books = new JMenu("Book's");
          mb.add(books);
          JMenuItem adbook = new JMenuItem("Add Books");
          books.add(adbook);
          adbook.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                Addbook objadd = new Addbook();
                objadd.addframe();
                objadd.frame.setVisible(true);
                desktop.add(objadd.frame); // !! ***** here *****
                try {
                   objadd.frame.setSelected(true);
                } catch (PropertyVetoException exn) {
                   exn.printStackTrace();
                }
    
             }
          });
    
          desktop = new JDesktopPane();
          desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
          f.getContentPane().add(desktop);
          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          f.setVisible(true);
          f.setJMenuBar(mb);
          f.setSize(1000, 625);
          f.setResizable(false);
          f.setContentPane(desktop);
       }
    
       public static void main(String[] args) {
          LibrarayLMS myframe = new LibrarayLMS();
          myframe.framelaunch();
       }
    
    }
    

    Again, there's mis-use of static in your code, that I have not yet changed. Also as per my comment, you should avoid use of null layout and use of setBounds(...) for component placement as this makes for very inflexible GUI's that while they might look good on one platform look terrible on most other platforms or screen resolutions and that are very difficult to update and maintain. Also, your code does not respect Swing threading rules in that you've got a lot of long-running code running on the Swing event thread. Consider calling the long-running code on a background thread such as a SwingWorker-derived thread.

    Please remember this technique of isolating the error as it will come in handy in the future.