Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Java JList and actionPerformed problem

  • 03-11-2011 06: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