Static ResultListener ruleListener = new ResultAdapter() { public void resultCreated(ResultEventevent) { //the result is not finalized yet Result result_recognizer = (Result) event.getSource( ); } public void grammarFinalized(ResultEvent event) { //the grammar is already known but the result is not finalized //yet Result result_recognizer = (Result) event.getSource( ); } public void resultUpdated(ResultEvent event) { //the result is yet being created Result result_recognizer = (Result) event.getSource( ); } public void resultAccepted(ResultEvent event) { //if it is an accepted result, surely //it is a finalized result, so we can use the casting //for any of the three result types: Result, FinalResult and //FinalRule/DictationResult //we use Result if we do not know the type of the grammar //or will not need specialized methods, but basic ones //like addResultListener Result result_recognizer = (Result) event.getSource( ); //we use FinalResult if we do not know the type of the grammar //and we need to use methods like releaseAudio and //releaseTrainingInfo Result result_recognizer = (FinalResult) evento.getSource(); //in the case when both the grammars are associated with a //determined resultListener we must test the type of the //grammar in order to avoid exceptions Result result = event.getSource(); if (result.getGrammar() instanceof RuleGrammar){ result_recognizer = (FinalRuleResult) result; } else { result_recognizer = (FinalDictationResult) result; } } public void resultRejected(ResultEvent event) { //equal to resulAccepted } public void audioReleased(ResultEvent event) { //equal to resulAccepted } public void trainingInfoReleased(ResultEvent event) { //equal to resulAccepted } };