This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

MIDI

 
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!!
 
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!!!
 
Wanderer
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
 
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?
 
"The Hood"
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
Boost this thread!