aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Understanding API's -- full text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Understanding API Watch "Understanding API New topic
Author

Understanding API's -- full text

John Held
Greenhorn

Joined: Jun 13, 2002
Posts: 13
Ambitious I know, but I the problem I'm having
illustrates the difference between book-learning and writing real Java programs
According to the Sequence API, I can create a
new MIDI (music) sequence, add a track to it, and
then add midi events to it.
1--in spite of the right import statement, I seem
to have to add "javax.sound.midi.MidiEvent" for
the t.add statement to find the "setTick" midi function.
2--Even though Midi2 is not static, I get the message "non-static method set.Tick(l) cannot
be referenced from a static context"
Help -- code below!

public class Midi2 {
Midi2() {
Sequence seq = null;
try {seq = new Sequence(0.0f, 500);} catch (InvalidMidiDataException e)
{System.exit(0);}
Track t = null;
t = seq.createTrack();
long l = 500;

t.add(javax.sound.midi.MidiEvent.setTick(l));


John Held
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

This isn't Certification related, moving to Other Java API's. Please continue the discussion there.
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
Originally posted by John Held:

1--in spite of the right import statement, I seem
to have to add "javax.sound.midi.MidiEvent" for
the t.add statement to find the "setTick" midi function.
2--Even though Midi2 is not static, I get the message "non-static method set.Tick(l) cannot
be referenced from a static context"
...
t.add(javax.sound.midi.MidiEvent.setTick(l));

1) Not seeing the import statement, it's hard to say if it's "right" or not. What exactly are you using as the import statement that you say is not working?
2) I don't have this MIDI API installed so I can't check it, but just going by what the compiler is telling you, I don't think that setTick() in class MidiEvent is a static method, and you are referring to it as if it were. You might want to double-check this.


Rob
SCJP 1.4
John Held
Greenhorn

Joined: Jun 13, 2002
Posts: 13
Thanks Rob,
The import statement is as follows:
importjavax.sound.midi.MidiEvent;
Any ideas on the correct way to add the
event?
--John
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
John, do you understand the difference between a static method and an instance method? If not, you should ask about them in the Java In General (Beginner) forum here:
http://www.coderanch.com/forums/f-33/java
To answer your question, you probably need to have an instance of a MidiEvent object. Instances are created via the instance-creation statement "new MidiEvent()", passing whatever parameters may be required, as described in the JavaDocs for your MIDI API.
[ June 28, 2002: Message edited by: Rob Ross ]
John Held
Greenhorn

Joined: Jun 13, 2002
Posts: 13
Thanks. I was able to create a sequence with midi events. If anyone knows of better descriptions of the values which need to go in various midi events (the API seems pretty dry for this information and the midi site reference is pretty feeble) let me know.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Understanding API's -- full text