Results 1 to 5 of 5
  1. #1
    jMaster's Avatar
    jMaster is offline Member
    Join Date
    Oct 2011
    Posts
    16
    Rep Power
    0

    Default Urgent Help Please. My program freezes... Was working fine...

    So in the end I realised that the solution to a freezing JFrame in netbeans is to re-create it and it should work. The other possibility is a math error such as division by 0.

    BIG EDIT: I just realised something that I did with ManageUsers which could make this work even though ManageUsers never froze. I'm going to have to make WordID textfield editable again and add that to my sqls. But please do offer suggestions.
    No that still didn't work.

    Ok i'm doing my 2011 I.T Grade 12 (although im in gr11) Practical Assessment Task(fancy word for project) for the year.

    It is to make a translator.

    I'm almost done. Infact I thought I was done and I was just testing my PAT now. Before I added the ViewDictionary JFrame to the project this JFrame screen was working perfect. I'm totally lost as to what is wrong here...

    THE PROBLEM: What happens is that after I click the ManageDictionary Button and this frame pops up it just freezes - I can't select the textfields, press any buttons, or even close it. The rest of my computer stays fine so I close it with TaskManager.

    (Don't check the initComponents() method its generated by NetBeans and I can't change it)
    Java Code:
    import java.sql.*;
    import java.io.*;
    /**
     *
     * @author ITGrade11
     */
    public class ManageDictionary extends javax.swing.JFrame {
     DBw db = new DBw();
     int totalWords = 0;
     String numOfWords = "";
     String eng = "";
     String afr = "";
     String delEng = "";
     String delAfr = "";
     String delID = "";
     String selEng = "";
     String selAfr = "";
     String selID = "";
     int IDNum = 0;
        /** Creates new form ManageDictionary */
        public ManageDictionary() {
            initComponents();
            this.setLocationRelativeTo(null);
            onStart();
        }
    
          private void onStart(){
              try{
                 ResultSet rs = db.queryTbl("SELECT TOP 1 * FROM tblDictionary ORDER BY WordID DESC");
                 rs.next();
                 totalWords = Integer.parseInt(rs.getString("WordID"));
              } catch(SQLException s){
                  System.out.println("Failed to count dictionary length.");
                  System.out.println(s.getMessage());
              }
            totalWords++;
            numOfWords = totalWords + "";
            txtWordID.setText(numOfWords + "");
            txtWordID.requestFocusInWindow();
          }
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
    
            jPanel1 = new javax.swing.JPanel();
            jLabel1 = new javax.swing.JLabel();
            txtEng = new javax.swing.JTextField();
            jLabel2 = new javax.swing.JLabel();
            txtAfr = new javax.swing.JTextField();
            btnAdd = new javax.swing.JButton();
            btnDelete = new javax.swing.JButton();
            btnView = new javax.swing.JButton();
            btnBack = new javax.swing.JButton();
            jLabel3 = new javax.swing.JLabel();
            txtWordID = new javax.swing.JTextField();
            jLabel4 = new javax.swing.JLabel();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Dictionary");
            setEnabled(false);
    
            jLabel1.setText("English:");
    
            txtEng.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    txtEngActionPerformed(evt);
                }
            });
    
            jLabel2.setText("Afrikaans:");
    
            btnAdd.setText("Add");
            btnAdd.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btnAddActionPerformed(evt);
                }
            });
    
            btnDelete.setText("Delete");
            btnDelete.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btnDeleteActionPerformed(evt);
                }
            });
    
            btnView.setText("View");
            btnView.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btnViewActionPerformed(evt);
                }
            });
    
            btnBack.setText("Back");
            btnBack.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btnBackActionPerformed(evt);
                }
            });
    
            jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14));
            jLabel3.setText("Dictionary ");
    
            txtWordID.setEditable(false);
            txtWordID.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    txtWordIDActionPerformed(evt);
                }
            });
    
            jLabel4.setText("WordID:");
    
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addContainerGap()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(txtAfr, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtEng, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtWordID, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(30, 30, 30)
                                        .addComponent(jLabel1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGap(28, 28, 28)
                                    .addComponent(jLabel2)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(btnDelete, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .addComponent(btnAdd, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .addComponent(btnView, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(btnBack, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(70, 70, 70)
                            .addComponent(jLabel3))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(38, 38, 38)
                            .addComponent(jLabel4)))
                    .addContainerGap())
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(40, 40, 40)
                    .addComponent(jLabel3)
                    .addGap(20, 20, 20)
                    .addComponent(jLabel4)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnAdd)
                        .addComponent(txtWordID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(btnDelete)
                        .addComponent(jLabel1))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(btnView)
                        .addComponent(txtEng, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabel2)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(txtAfr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(btnBack))
                    .addContainerGap(21, Short.MAX_VALUE))
            );
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>
    
        private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {                                        
            // TODO add your handling code here:
            this.dispose();
            new AdminMenu().setVisible(true);
        }                                       
    
        private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {                                          
            // TODO add your handling code here:
    
            try{
                
              
                selAfr = txtAfr.getText() + "";
                selEng = txtEng.getText() + "";
    
                db.updateTbl("DELETE FROM tblDictionary WHERE English = '"+selEng+"' AND Afrikaans = '"+selAfr+"'");
            } catch(SQLException s){
                System.out.println(s.getMessage());
                System.out.println ("Error Deleting.");
            }
        }                                         
    
        private void btnViewActionPerformed(java.awt.event.ActionEvent evt) {                                        
            // TODO add your handling code here:
            this.dispose();
            new ViewDictionary().setVisible(true);
        }                                       
    
        private void txtWordIDActionPerformed(java.awt.event.ActionEvent evt) {                                          
            // TODO add your handling code here:
            txtEng.requestFocusInWindow();
        }                                         
    
        private void txtEngActionPerformed(java.awt.event.ActionEvent evt) {                                       
            // TODO add your handling code here:
            txtAfr.requestFocusInWindow();
        }                                      
    
        private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {                                       
            // TODO add your handling code here:
            eng = txtEng.getText() + "";
            afr = txtAfr.getText() + "";
            try{
                db.updateTbl("INSERT INTO tblDictionary(English, Afrikaans, WordID) VALUES('"+eng+"', '"+afr+"', '"+totalWords+"')");
            } catch(SQLException s){
                System.out.println(s.getMessage());
                System.out.println ("Exception when Inserting.");
            }
        }                                      
    
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new ManageDictionary().setVisible(true);
                }
            });
        }
    
        // Variables declaration - do not modify
        private javax.swing.JButton btnAdd;
        private javax.swing.JButton btnBack;
        private javax.swing.JButton btnDelete;
        private javax.swing.JButton btnView;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JTextField txtAfr;
        private javax.swing.JTextField txtEng;
        private javax.swing.JTextField txtWordID;
        // End of variables declaration
    
    }
    P.S I use NetBeans and Microsoft Access 2007 (Because the rubric says so)
    Last edited by jMaster; 11-03-2011 at 09:23 PM. Reason: Solved

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Urgent Help Please. My program freezes... Was working fine...

    Put some more println statements in your code and find out exactly where it gets stuck. My guess is it's the database code which shouldn't be called on the Swing thread to begin with but should be called in a background thread. Also your design of having JFrames pop in and out isn't usually a good one.

  3. #3
    jMaster's Avatar
    jMaster is offline Member
    Join Date
    Oct 2011
    Posts
    16
    Rep Power
    0

    Default Re: Urgent Help Please. My program freezes... Was working fine...

    Ok thanks i'll try that tomorrow in school, it's late here now have to sleep

  4. #4
    jMaster's Avatar
    jMaster is offline Member
    Join Date
    Oct 2011
    Posts
    16
    Rep Power
    0

    Default Re: Urgent Help Please. My program freezes... Was working fine...

    i've knocked it down and the problem is in one of the button methods :? because everything else works....

    Java Code:
     private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {                                       
            // TODO add your handling code here:
            eng = txtEng.getText() + "";
            afr = txtAfr.getText() + "";
            try{
                db.updateTbl("INSERT INTO tblDictionary(English, Afrikaans, WordID) VALUES('"+eng+"', '"+afr+"', '"+totalWords+"')");
            } catch(SQLException s){
                System.out.println(s.getMessage());
                System.out.println ("Exception when Inserting.");
            }
        }
    OR

    Java Code:
    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {                                          
            // TODO add your handling code here:
    
            try{
                
              
                selAfr = txtAfr.getText() + "";
                selEng = txtEng.getText() + "";
                 selID = txtWordID.getText() + "";
                db.updateTbl("DELETE FROM tblDictionary WHERE English = '"+selEng+"' AND Afrikaans = '"+selAfr+"' AND WordID = '"+selID+"'");
            } catch(SQLException s){
                System.out.println(s.getMessage());
                System.out.println ("Error Deleting.");
            }
        }
    But that is extreemly strange since the JFrame freezes without any input from the user...

  5. #5
    jMaster's Avatar
    jMaster is offline Member
    Join Date
    Oct 2011
    Posts
    16
    Rep Power
    0

    Default Re: Urgent Help Please. My program freezes... Was working fine...

    I re-made the JFrame. Copied and pasted the code. It worked like a charm. :)

Similar Threads

  1. How do I know java webstart is working fine?
    By Deenadayalan in forum New To Java
    Replies: 0
    Last Post: 07-07-2011, 05:52 AM
  2. Replies: 6
    Last Post: 02-08-2011, 02:29 AM
  3. Program working fine until I add methods....
    By LadyMonsterFace in forum New To Java
    Replies: 3
    Last Post: 12-04-2010, 03:22 AM
  4. HELP working with 2 classes!!! URGENT!
    By syntrax in forum New To Java
    Replies: 3
    Last Post: 12-09-2009, 02:58 AM
  5. Replies: 2
    Last Post: 03-16-2009, 07:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •