#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0

    Connecting GUI to the back end


    Hi, I am trying to connect my GUI to a back end but some pieces are not working and some other have errors.

    1: This is for saving a new customer by pressing the save Button. cb.closeBroker(); is for release resources allocated to the broker and save all modified data.

    Code:
    if(e.getSource() == saveButton)
    			{
    				try
    				{
    					cb.persist(new Customer(idTextField.getText()+";"+firstNameTextField.getText()+ ";" + lastNameTextField.getText()+";"+ addressTextField.getText()+';'+
    							postalCodeTextField.getText()+";"+phoneTextField.getText()+";"+searchTextField.getText()));
    				} catch (InvalidPhoneNumberException e1)
    				{
    					// TODO Auto-generated catch block
    					//e1.printStackTrace();
    					JOptionPane.showMessageDialog(null, "Invalid phone number");
    				} catch (InvalidPostalCodeException e1)
    				{
    					// TODO Auto-generated catch block
    					JOptionPane.showConfirmDialog(null, "Invalid Postal Code");
    				}
    				cb.closeBroker();
    			}
    2: I tried to do the same for another window that adds movies however is not working is said "The constructor Movie(String) is undefined"

    And I need to add another exception;

    Code:
    if(e.getSource() == saveButton)
    				{
    					
    						mb.persist(new Movie(movieIdTextField.getText()+";"+movieTitleTextField.getText()+ ";" + movieDirectorTextField.getText()+";"+
    								movieLeadingTextField.getText()+';'+movieCategoryTextField.getText()+";"+movieRunningTextField.getText()+";"+
    								 movieRunningTextField.getText()+ ";"+ movieRatingTextField.getText()+";"+movieReleaseTextField.getText()));
    					
    					mb.closeBroker();
    					
    				}
    NOTE: I just need to connect it to a back end.
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    other have errors.
    Please copy the full text of the error messages and paste it here.

    The constructor Movie(String) is undefined
    That says the compiler can not find a definition for the Movie class that takes a String as arg.

    Can you explain what you are trying to do and what the problems are?

    By "connect it to a back end" do you mean you want to start a thread that will do some task leaving the GUI free to respond to a user?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0
    Originally Posted by NormR
    Please copy the full text of the error messages and paste it here.


    That says the compiler can not find a definition for the Movie class that takes a String as arg.

    Can you explain what you are trying to do and what the problems are?

    By "connect it to a back end" do you mean you want to start a thread that will do some task leaving the GUI free to respond to a user?
    Hi Thank you for you reply

    By connecting to the back end I mean that I have all the functionality already done and I am just trying to connect all the buttons to the functionality.

    What I am trying to do is when I click in the save or remove button, it adds all the information that is in the text fields.

    This is my remove code.

    PHP Code:
    else if (e.getSource() == deleteButton)
                    {
                        
                        
                        
    Long id Long.parseLong(movieIdTextField.getText());
                        
    String title movieTitleTextField.getText();
                        
    String director movieDirectorTextField.getText();
                        
    String leading movieLeadingTextField.getText();
                        
    String category =  movieCategoryTextField.getText();
                        
    String sActors movieSupportingTextField.getText();
                        
    int runTime =Integer.parseIntmovieRunningTextField.getText());
                        
    String rating movieRatingTextField.getText();
                        
    String releaseDate movieReleaseTextField.getText();
                        
                         try
                        {
                            
    mb.remove(new Movie(idtitledirectorleadingcategorysActors,  runTimeratingreleaseDate));
                        } catch (
    InvalidDateException e1)
                        {
                            
    // TODO Auto-generated catch block
                            
    JOptionPane.showMessageDialog(null"Invalid movie date");
                        } catch (
    InvalidRatingException e1)
                        {
                            
    // TODO Auto-generated catch block
                            
    JOptionPane.showMessageDialog(null"Invalid movie rating");
                        }
                
                    
    mb.closeBroker(); 
                    
                    } 
    The error that it shows like the save one is:

    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
    at java.util.ArrayList.elementData(Unknown Source)
    at java.util.ArrayList.remove(Unknown Source)
    at videoStore.persistence.products.MovieBroker.remove(MovieBroker.java:134)
    at mainGUIWindowFrames.MovieWindow$MyActionListener.actionPerformed(MovieWindow.java:474)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
    at java.util.ArrayList.elementData(Unknown Source)
    at java.util.ArrayList.remove(Unknown Source)
    at videoStore.persistence.products.MovieBroker.remove(MovieBroker.java:134)
    Look at line 134 and see why the index used there is -1
    -1 is not a valid value for the remove() method. The code should test that the value is in range for the contents of the ArrayList before calling any of the ArrayList methods.

    Code:
    mb.remove(new Movie...
    That's strange code. Calling the remove method with a new object that would not be in the list yet (its newly created by the new)
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0
    Originally Posted by NormR
    Look at line 134 and see why the index used there is -1
    -1 is not a valid value for the remove() method. The code should test that the value is in range for the contents of the ArrayList before calling any of the ArrayList methods.

    Code:
    mb.remove(new Movie...
    That's strange code. Calling the remove method with a new object that would not be in the list yet (its newly created by the new)
    My line 134 is just a panel:
    Code:
    JPanel rightInformationPanel = new JPanel(new BorderLayout());
    Ans my line 474 is:
    Code:
    mb.remove(new Movie(id, title, director, leading, category, sActors,  runTime, rating, releaseDate));
  10. #6
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    The error message says there is a call to the ArrayList's remove() method at line 134 in MovieBroker.java.
    Are you looking at the right class?

IMN logo majestic logo threadwatch logo seochat tools logo