Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MIDI

 
Trey German
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yesw i had the same proble. If anyone has the same problem, please post!!!
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Trey German
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please some one help please!! i beg u
 
Kay Tracid
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I load the FileChooser Dialog faster?
my way:
 
Kay Tracid
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello� Sombody knows how i can load the filechooser faster?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic