aspose file tools*
The moose likes Java in General and the fly likes MIDI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "MIDI" Watch "MIDI" New topic
Author

MIDI

Trey German
Greenhorn

Joined: Dec 05, 2002
Posts: 12
I am now trying to add sound to my program and i am using this code
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class midi {

public static void main(String[] args) throws Exception {
JFrame frame = new JFrame("NoisyButton");
java.io.File file = new java.io.File(args[0] );
final AudioClip sound = Applet.newAudioClip(file.toURL( ));
JButton button = new JButton("Woof!");
button.addActionListener(new ActionListener( ) {
public void actionPerformed(ActionEvent e) { sound.play( ); }
});
Container content = frame.getContentPane();
content.setBackground(Color.pink);
content.setLayout(new GridBagLayout());
content.add(button);
frame.setVisible(true);
frame.setSize(200, 200);
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setVisible(true);
}
}
but when i try to execute it gives me this error:
"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException at midi.main(midi.java:10)
whats wrong??? HELP!!
Paul Gruetzmacher
Greenhorn

Joined: Dec 11, 2002
Posts: 1
Yesw i had the same proble. If anyone has the same problem, please post!!!
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Look at line 10:

This line assumes that there is at least one command-line argument included when you invoke the JVM, e.g.
java MyClass filename.txt
If you don't wan't to invoke Java this way, you'll have to input the name of the file to be read some other way, like as a string literal in the program, or as a value read from a Properties or Preferences file somewhere.


"I'm not back." - Bill Harding, Twister
Trey German
Greenhorn

Joined: Dec 05, 2002
Posts: 12
What goes in the place of filename.txt. when i try to put the name of the MIDI file i want to play they it gives me errors or is there a spot in the program i put the file name of the MIDI. I got this code from a book but the book didn't describe it to well THANX
Trey German
Greenhorn

Joined: Dec 05, 2002
Posts: 12
Please some one help please!! i beg u
Kay Tracid
Ranch Hand

Joined: Mar 06, 2002
Posts: 148
How can I load the FileChooser Dialog faster?
my way:
Kay Tracid
Ranch Hand

Joined: Mar 06, 2002
Posts: 148
Hello� Sombody knows how i can load the filechooser faster?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Originally posted by Trey German:
What goes in the place of filename.txt. when i try to put the name of the MIDI file i want to play they it gives me errors or is there a spot in the program i put the file name of the MIDI. I got this code from a book but the book didn't describe it to well THANX

You would need to replace the args[0] with the full name of the file. If you are getting errors then you probably did not name the full path to the file.


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MIDI