problem using JMF code

hello.

this is james mcfadden. i am having trouble trying to use 2 JMF programs (MediaPanel.java and MediaTest.java) with the Demo.java program. the Demo.java program compiles and runs ok, but when i press 1 (for listening to songs) in the media menu i get a JOptionPane (An Error Message) displayed on screen. how can i fix this problem?

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

publicclass Demoextends JFrame{

publicstaticvoid main(String[] args){

int choice=-1;//a variable of type int that is set to -1

choice=getChoice();//invokes the method getChoice()

if(choice!=0){

getSelected(choice);//invokes the method getSelected(choice)

}//end if

}//end main

publicstaticint getChoice(){

String choice;//a variable of type string

int ch;//a variable of type int

choice=JOptionPane.showInputDialog(null,

"1. Product Menu\n" +

"2. Member Menu\n" +

"3. Rental Menu\n" +

"4. Media Menu\n" +

"5. Log Off\n\n" +

"Enter your choice");//asks the user for some input

ch=Integer.parseInt(choice);//a class that wraps a value of the primitive type int in an object

return ch;//a method that returns an integer value

}//end getChoice

publicstaticvoid getSelected(int choice){

if(choice == 1){

product();

}//end if

if(choice==2){

member();

}//end if

if(choice==3){

rental();

}//end if

if(choice==4){

media();

}//end if

if(choice==5){

LogOff logoff=new LogOff();

}//end if

else{

JOptionPane.showMessageDialog(null,"Error\n\nInvalid options\nPlease choose 1, 2, 3, 4 or 5 on the main menu\nPlease choose 1, 2, 3, 4 or 5 on the product menu\nPlease choose 1, 2, 3, 4 or 5 on the member menu\nPlease choose 1, 2, 3, 4 or 5 on the rental menu\nPlease choose 1, 2, 3 or 4 on the media menu");

System.exit(0);

}

}//end getSelected

publicstaticvoid product(){

int productChoice=-1;//a variable of type int that is set to -1

productChoice=getProductChoice();//invokes the method getChoice()

if(productChoice!=0){

getProductSelected(productChoice);//invokes the method getSelected(choice)

}//end if

getChoice();

}

publicstaticvoid member(){

int memberChoice=-1;//a variable of type int that is set to -1

memberChoice=getMemberChoice();//invokes the method getChoice()

if(memberChoice!=0){

getMemberSelected(memberChoice);//invokes the method getSelected(choice)

}//end if

getChoice();

}

publicstaticvoid rental(){

int rentalChoice=-1;//a variable of type int that is set to -1

rentalChoice=getRentalChoice();//invokes the method getChoice()

if(rentalChoice!=0){

getRentalSelected(rentalChoice);//invokes the method getSelected(choice)

}//end if

getChoice();

}

publicstaticvoid media(){

int mediaChoice=-1;//a variable of type int that is set to -1

mediaChoice=getMediaChoice();//invokes the method getChoice()

if(mediaChoice!=0){

getMediaSelected(mediaChoice);//invokes the method getSelected(choice)

}//end if

getChoice();

}

publicstaticint getProductChoice(){

String productChoice;//a variable of type string

int pch;//a variable of type int

productChoice=JOptionPane.showInputDialog(null,

"1. Add product details\n" +

"2. View product details\n" +

"3. Edit product details\n" +

"4. Delete product details\n" +

"5. Return to main menu\n\n" +

"Enter your choice");//asks the user for some input

pch=Integer.parseInt(productChoice);//a class that wraps a value of the primitive type int in an object

return pch;//a method that returns an integer value

}//end getProductChoice

publicstaticint getMemberChoice(){

String memberChoice;//a variable of type string

int mch;//a variable of type int

memberChoice=JOptionPane.showInputDialog(null,

"1. Add member details\n" +

"2. View member details\n" +

"3. Edit member details\n" +

"4. Delete member details\n" +

"5. Return to main menu\n\n" +

"Enter your choice");//asks the user for some input

mch=Integer.parseInt(memberChoice);//a class that wraps a value of the primitive type int in an object

return mch;//a method that returns an integer value

}//end getMemberChoice

publicstaticint getRentalChoice(){

String rentalChoice;//a variable of type string

int rch;//a variable of type int

rentalChoice=JOptionPane.showInputDialog(null,

"1. Add rental details\n" +

"2. View rental details\n" +

"3. Edit rental details\n" +

"4. Delete rental details\n" +

"5. Return to main menu\n\n" +

"Enter your choice");//asks the user for some input

rch=Integer.parseInt(rentalChoice);//a class that wraps a value of the primitive type int in an object

return rch;//a method that returns an integer value

}//end getRentalChoice

publicstaticint getMediaChoice(){

String mediaChoice;//a variable of type string

int mtch;//a variable of type int

mediaChoice=JOptionPane.showInputDialog(null,

"1. Listen to songs\n" +

"2. View movie previews\n" +

"3. View game previews\n" +

"4. Return to main menu\n\n" +

"Enter your choice");//asks the user for some input

mtch=Integer.parseInt(mediaChoice);//a class that wraps a value of the primitive type int in an object

return mtch;//a method that returns an integer value

}//end getMediaChoice

publicstaticvoid getProductSelected(int productChoice){

if(productChoice==1){

addProducts();

}//end if

if(productChoice==2){

viewProducts();

}//end if

if(productChoice==3){

editProducts();

}//end if

if(productChoice==4){

deleteProducts();

}//end if

else{

JOptionPane.showMessageDialog(null,"Error\n\nInvalid options\nPlease choose 1, 2, 3, 4 or 5 on the main menu\nPlease choose 1, 2, 3, 4 or 5 on the product menu\nPlease choose 1, 2, 3, 4 or 5 on the member menu\nPlease choose 1, 2, 3, 4 or 5 on the rental menu\nPlease choose 1, 2, 3 or 4 on the media menu");

System.exit(0);

}

}//end getProductSelected

publicstaticvoid getMemberSelected(int memberChoice){

if(memberChoice==1){

addMembers();

}//end if

if(memberChoice==2){

viewMembers();

}//end if

if(memberChoice==3){

editMembers();

}//end if

if(memberChoice==4){

deleteMembers();

}//end if

else{

JOptionPane.showMessageDialog(null,"Error\n\nInvalid options\nPlease choose 1, 2, 3, 4 or 5 on the main menu\nPlease choose 1, 2, 3, 4 or 5 on the product menu\nPlease choose 1, 2, 3, 4 or 5 on the member menu\nPlease choose 1, 2, 3, 4 or 5 on the rental menu\nPlease choose 1, 2, 3 or 4 on the media menu");

System.exit(0);

}

}//end getMemberSelected

publicstaticvoid getRentalSelected(int rentalChoice){

if(rentalChoice==1){

addRentals();

}//end if

if(rentalChoice==2){

viewRentals();

}//end if

if(rentalChoice==3){

editRentals();

}//end if

if(rentalChoice==4){

deleteRentals();

}//end if

else{

JOptionPane.showMessageDialog(null,"Error\n\nInvalid options\nPlease choose 1, 2, 3, 4 or 5 on the main menu\nPlease choose 1, 2, 3, 4 or 5 on the product menu\nPlease choose 1, 2, 3, 4 or 5 on the member menu\nPlease choose 1, 2, 3, 4 or 5 on the rental menu\nPlease choose 1, 2, 3 or 4 on the media menu");

System.exit(0);

}

}//end getRentalSelected

publicstaticvoid getMediaSelected(int mediaChoice){

if(mediaChoice==1){

hearSongs();

}//end if

if(mediaChoice==2){

viewMovies();

}//end if

if(mediaChoice==3){

viewGames();

}//end if

else{

JOptionPane.showMessageDialog(null,"Error\n\nInvalid options\nPlease choose 1, 2, 3, 4 or 5 on the main menu\nPlease choose 1, 2, 3, 4 or 5 on the product menu\nPlease choose 1, 2, 3, 4 or 5 on the member menu\nPlease choose 1, 2, 3, 4 or 5 on the rental menu\nPlease choose 1, 2, 3 or 4 on the media menu");

System.exit(0);

}

}//end getMediaSelected

publicstaticvoid addProducts(){

ProductForm product=new ProductForm();

product.getInput();

product.setVisible(true);

}

publicstaticvoid viewProducts(){

DatabaseTest tt=new DatabaseTest();

tt.setVisible(true);

}

publicstaticvoid editProducts(){

ProductForm product=new ProductForm();

product.getInput();

product.setVisible(true);

}

publicstaticvoid deleteProducts(){

ProductForm product=new ProductForm();

product.setVisible(true);

}

publicstaticvoid addMembers(){

MemberForm member=new MemberForm();

member.getInput();

member.setVisible(true);

}

publicstaticvoid viewMembers(){

DatabaseTest tt=new DatabaseTest();

tt.setVisible(true);

}

publicstaticvoid editMembers(){

MemberForm member=new MemberForm();

member.getInput();

member.setVisible(true);

}

publicstaticvoid deleteMembers(){

MemberForm member=new MemberForm();

member.setVisible(true);

}

publicstaticvoid addRentals(){

RentalForm rental=new RentalForm();

rental.getInput();

rental.setVisible(true);

}

publicstaticvoid viewRentals(){

DatabaseTest tt=new DatabaseTest();

tt.setVisible(true);

}

publicstaticvoid editRentals(){

RentalForm rental=new RentalForm();

rental.getInput();

rental.setVisible(true);

}

publicstaticvoid deleteRentals(){

RentalForm rental=new RentalForm();

rental.setVisible(true);

}

publicstaticvoid hearSongs(){

MediaTest media=new MediaTest();

}

publicstaticvoid viewMovies(){

MediaTest media=new MediaTest();

}

publicstaticvoid viewGames(){

MediaTest media=new MediaTest();

}

}//end class Demo

import java.awt.BorderLayout;

import java.awt.Component;

import java.io.IOException;

import java.net.URL;

import javax.media.CannotRealizeException;

import javax.media.Manager;

import javax.media.NoPlayerException;

import javax.media.Player;

import javax.swing.JPanel;

publicclass MediaPanelextends JPanel{

public MediaPanel(URL mediaURL){

setLayout(new BorderLayout());//use a BorderLayout

//Use lightweight components for Swing compatibility

Manager.setHint(Manager.LIGHTWEIGHT_RENDERER,true);

try{

//create a player to play the media specified in the URL

Player mediaPlayer=Manager.createRealizedPlayer(mediaURL);

//get the components for the video and the playback controls

Component video=mediaPlayer.getVisualComponent();

Component controls=mediaPlayer.getControlPanelComponent();

if(video!=null)

add(video,BorderLayout.CENTER);//add video component

if(controls!=null)

add(controls,BorderLayout.SOUTH);//add controls

mediaPlayer.start();//start playing the media clip

}//end try

catch(NoPlayerException noPlayerException){

System.err.println("No media player found");

}//end catch

catch(CannotRealizeException cannotRealizeException){

System.err.println("Could not realize media player");

}//end catch

catch(IOException iOException){

System.err.println("Error reading from the source");

}//end catch

}//end MediaPanel constructor

}//end class MediaPanel

import java.io.File;

import java.net.MalformedURLException;

import java.net.URL;

import javax.swing.JFileChooser;

import javax.swing.JFrame;

publicclass MediaTest{

//launch the application

publicstaticvoid main(String args[]){

//create a file chooser

JFileChooser fileChooser=new JFileChooser();

//show open file dialog

int result=fileChooser.showOpenDialog(null);

if(result==JFileChooser.APPROVE_OPTION){//user chose a file

URL mediaURL=null;

try{

//get the file as URL

mediaURL=fileChooser.getSelectedFile().toURL();

}//end try

catch(MalformedURLException malformedURLException){

System.err.println("Could not create URL for the file");

}//end catch

if(mediaURL!=null){//only display if there is a valid URL

JFrame mediaTest=new JFrame("Media Tester");

mediaTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

MediaPanel mediaPanel=new MediaPanel(mediaURL);

mediaTest.add(mediaPanel);

mediaTest.setSize(300,300);

mediaTest.setVisible(true);

}//end inner if

}//end outer if

}//end main

}//end class MediaTest

[28475 byte] By [james-mcfaddena] at [2007-11-27 2:07:31]
# 1
once more, the legendary james mcfadden and his as-much-legendary invisible dukes appears from the dark :D
calvino_inda at 2007-7-12 1:55:49 > top of Java-index,Java Essentials,Java Programming...