Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java JList and actionPerformed problem

Options
  • 03-11-2011 6:42pm
    #1
    Closed Accounts Posts: 1


    I have been given this project to create a java GUI for a cinema, where a user can add a movie, this movie is then inserted into a list.
    By click on the items in the list the program retrieves the relevant data about that movie inserting them into the same form used to add a movie
    I can add a movie and retrieve a movies details. But once i retrieve the details i cannot add a new movie.

    Below is my add movie code
    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
        resetForm();
        //checking if there is 8 movies in the vector
        if(count<=8){
            
            addButtonEnable();
            addFilm();
            addToList();
            
            resetForm();
            
            count++;
            
        }
        else {
            addButton.setEnabled(false);
            resetForm();
            JOptionPane.showMessageDialog(this, "You have entered 8 movies, you can't enter anymore without deleteing some movie/s");
        }
        
    }             
    

    below are some of my method
    public void addFilm() {
            //getting text from form
            String strTitle = titleTF.getText();
            Object objStudio = studioDropDown.getSelectedItem();
            ButtonModel age = JToggleButtonGroup.getSelection();
            String strReleaseDate = releaseDateTF.getText();
            String strStaring = starringTF.getText();
            String strDuration = durationTF.getText();
            String strDirector = directorTF.getText();
            String strDescription = description.getText();
            ButtonModel screen = buttonGroup1.getSelection();
            
            //creating an instance of movie
            movie newMovie = new movie();
            
            //setting the values in this instance
            newMovie.setTitle(strTitle);
            newMovie.setStudio(objStudio);
            newMovie.setClassification(age);
            newMovie.setReleaseDate(strReleaseDate);
            newMovie.setStaring(strStaring);
            newMovie.setDuration(strDuration);
            newMovie.setDirector(strDirector);
            newMovie.setSynopsis(strDescription);
            newMovie.setScreen(screen);
            
            //adding movie instance newMovie to vector movie
            movie.add(newMovie);
            
            
        }
        
        public void addToList() {
            //adding to list
            listModel.clear();
            for(int i=0;i<movie.size();i++){
                movie newMov = (movie) movie.get(i);
                listModel.add(i, newMov.getTitle().toString().toUpperCase());
            }
            movieList.setModel(listModel);
        }
        
        public void retrieve() {
            addButtonEnable();
            movie newMov = (movie) movie.get(movieList.getSelectedIndex());
            
            //inserting the data in the textfield
            titleTF.setText(newMov.getTitle());
            studioDropDown.setSelectedItem(newMov.getStudio());
            JToggleButtonGroup.setSelected((ButtonModel) newMov.getClassification(), true);
            releaseDateTF.setText(newMov.getReleaseDate());
            starringTF.setText(newMov.getStaring());
            durationTF.setText(newMov.getDuration());
            directorTF.setText(newMov.getDirector());
            description.setText(newMov.getSynopsis());
            buttonGroup1.setSelected((ButtonModel) newMov.getScreen(), true);
            
            
            
        }
        
        public void removeMovie(int index) {
            movieList.remove(index);
            movie.remove(index);
            
        }
    

    Below is the code for remove, i have just started this so it is not very good
    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
            removeMovie(movieList.getSelectedIndex());
            addFilm();
     }
    

    As I have said i need help with adding a new movie after i have retrieved another movie, also i need ideas for removing a movie from the list.


Advertisement