private void saveAndCloseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAndCloseButtonActionPerformed
        // TODO add your handling code here:
        
        matchReader read = new matchReader();
        ArrayList<MatchObject> matches = null;
        
        try {
            matches = read.readMatchObject();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(teamsListFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
        MatchObject match = new MatchObject();
        
        
        MatchTeamSubFrame redIso = (MatchTeamSubFrame)redIsolation;       
        match.red.isolation.setMatchTeamObject(redIso.getMatchTeam());
        
        MatchTeamSubFrame redInter = (MatchTeamSubFrame)redInteraction;       
        match.red.interaction.setMatchTeamObject(redInter.getMatchTeam());
        
        MatchTeamSubFrame blueIso = (MatchTeamSubFrame)blueIsolation;       
        match.blue.isolation.setMatchTeamObject(blueIso.getMatchTeam());
        
        MatchTeamSubFrame blueInter = (MatchTeamSubFrame)blueInteraction;       
        match.blue.interaction.setMatchTeamObject(blueInter.getMatchTeam());
        
        match.red.setScore(Integer.parseInt(redTeamScore.getText()));
        match.blue.setScore(Integer.parseInt(blueTeamScore.getText()));
        
        
        if((match.blue.interaction.getIdNumber() == match.blue.isolation.getIdNumber())||
                (match.red.interaction.getIdNumber() == match.red.isolation.getIdNumber())||
                (match.red.interaction.getIdNumber() == match.blue.isolation.getIdNumber())||
                (match.blue.interaction.getIdNumber() == match.red.isolation.getIdNumber())||
                (match.red.interaction.getIdNumber() == match.blue.interaction.getIdNumber())||
                (match.red.isolation.getIdNumber() == match.blue.isolation.getIdNumber())){
            JOptionPane.showMessageDialog(this, "There must be four diffrent teams in a match", "ERROR", JOptionPane.ERROR_MESSAGE);
        }
        else{
        match.setMatchNumber(matchNumber);
        matches.set(matchNumber, match);
        
        matchWriter write = new matchWriter();
        try {
            write.replaceMatchObject(matches);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(MatchTeamFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        matchListFrame frame = new matchListFrame();
        frame.setSize(this.getWidth(), getHeight());
        frame.setLocation(this.getX(), this.getY());
        frame.setVisible(true);
        
        this.dispose();
        }
        
        
    }//GEN-LAST:event_saveAndCloseButtonActionPerformed