java—从另一个jframe(用于上载到dbase)完成一个方法后,自动将jinternalframe1打开到大型机的桌面

kyks70gy  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(215)

我有3个班:一个带桌面的主框架;主框架有一个按钮,可以打开一个jinternalframe(显示在桌面上),其中有一个按钮可以将.csv上传到dbase。jinternalframe还有一个方法来显示db表的内容。当点击按钮时,它将打开另一个jframe1,它将上传到db。jframe1在上传后不可见。我一直在努力实现的是通过jinternalframe中显示db表内容的方法来显示新上传的记录。我可以单击mainframe上的按钮来显示jinternalframe和上传的记录,但是我希望jinternalframe自动重新加载以显示上传的数据。
我知道这对高级程序员来说是一个简单的任务,我希望能有所启发。以下是一些代码:

//code from Main frame
        btnAddBooks = new JButton("Manage Books");
        btnAddBooks.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                desktopPane.removeAll();
                AddBook  addBook = new AddBook();
                desktopPane.add(addBook).setVisible(true);
            }
        });

//code from AddBook jinternalframe
JButton btnBatchUpload = new JButton("Batch Upload");
         btnBatchUpload.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                UploadCSV uploadCSV = new UploadCSV();
                uploadCSV.setVisible(true);
            }
         });
//code from UploadCSV
        JButton btnUpload = new JButton("Upload");
        btnUpload.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    BufferedReader reader=new BufferedReader(new FileReader(filename));
                    String data;
                    while ((data=reader.readLine()) != null) {
                        String[] values=data.split(",");
                        //check for duplicate
                        String bookcode=values[0];

                        try {
                            String sqlString = "SELECT `BookCode` FROM `addbook` where BookCode='"+bookcode+"' ";
                            pst = conn.prepareStatement(sqlString);
                            rSet = pst.executeQuery();

                            if (rSet.next()) {
                                JOptionPane.showMessageDialog(null, "Book Code: "+bookcode + " has duplicate in database");
                            } else {
                                try {
                                    PreparedStatement pst=conn.prepareStatement("INSERT INTO `addbook`(`BookCode`, `Title`, `NoOfCopies`, `dateAdded`, `category`, `remarks`) VALUES(?,?,?,?,?,?) ");
//i omitted the codes to set the string since the issue is not about this

                                    pst.executeUpdate();
                                    pst.close();            

                                } catch (Exception e2) {
                                    JOptionPane.showMessageDialog(null, e2, "File Upload Error", JOptionPane.ERROR_MESSAGE);
                                }
                            }

                        } catch (Exception ee) {
                            JOptionPane.showMessageDialog(rootPane, ee);
                        }                   
                    }
                    reader.close();
                    JOptionPane.showMessageDialog(null, "Batch Upload Done");
                    dispose();
                    //should show the uploaded data after dispose
                    /*this is what i tried
                    AddBook ab=new AddBook();
                    ab.setVisible(true);

* /

                } catch (Exception e2) {
                    JOptionPane.showMessageDialog(null, e2, "File Upload Error", JOptionPane.ERROR_MESSAGE);
                }
            }

        });

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题