John Calson

Greenhorn
+ Follow
since Jul 23, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by John Calson

Head First Java Book 2nd Edition 2005
I have searched the errata for the book but did not find this

Page 620 (Chapter 18)

MyRemote service = (MyRemote) Naming...

Arrow pointing to MyRemote says:

"The client always uses the remote implementation as the type of service..."

In my opinion this should read:

"The client always uses the remote interface as the type of service..."

Change 'implementation' to 'interface'.

Do you agree. Is this an error in the book?
If not, please explain.
Thanks for your help.
16 years ago
Thanks much!
This works great.
16 years ago
Hello:

In short: How do you get focus on a scrolling JTextArea when a separate thread is appending text to the text area? Appending text is thread safe, no problem there, scrolling works fine but focus is NOT maintained on the current appended text line. Have tried requestFocus. Tried SwingUtilities.invokeLater. Does not solve problem. Any ideas?

Situation:
Created a class with a JFrame with a vertical scrolling JTextArea and a JButton. This class also creates a new thread. When the button is clicked, the new thread is started. The thread is a simulation that prints out data to the JTextArea using text.append(), which is thread safe. This works fine and vertical scroll bar appears when text exceeds vertical height, BUT focus is lost. Focus does not stay with the current output text line? I have tried requestFocus but did not help. Then tried to invokeLater the requestFocus, but that did not do it either.

Any help appreciated!
16 years ago
This solution assumes:
- Windows XP SP3
- JDK 1.6+
- JRE 1.6+

The problem is the file sound.jar
Find it in 3 places and delete it.

C:\Program Files\JMF2.1.1e\lib\sound.jar
C:\Program Files\Java\jdk1.6.0_07\jre\lib\ext\sound.jar
C:\Program Files\Java\jre1.6.0_07\lib\ext\sound.jar

Also, remove sound.jar reference from PATH and CLASSPATH

This is an old sound.jar that messes up the new sound API in the new versions of Java.
16 years ago
Hello,
I am getting a MidiUnavailableException : MIDI OUT transmitter not available
The code is the MiniMusicApp from the Head First Java book
The program was working great until I installed JMF 2.1.1e. Since then I get the above error. I am running JDK 1.6.06 and JRE 1.6.06 on Windows XP. I can play MIDI files through Windows Media Player - no problem.
javax.sound.sampled is working fine

Code:

import javax.sound.midi.*;


public class MiniMusicApp { // this is the first one

public static void main(String[] args) {
MiniMusicApp mini = new MiniMusicApp();
mini.play();
}

public void play() {

try {

// make (and open) a sequencer, make a sequence and track

Sequencer sequencer = MidiSystem.getSequencer(); //***** Blows up here ********
sequencer.open();

Sequence seq = new Sequence(Sequence.PPQ, 4);
Track track = seq.createTrack();

// now make two midi events (containing a midi message)
MidiEvent event = null;

// first make the message
// then stick the message into a midi event
// and add the event to the track

ShortMessage first = new ShortMessage();
first.setMessage(192, 1, 102, 0);
MidiEvent setIns = new MidiEvent(first, 0);
track.add(setIns);

ShortMessage a = new ShortMessage();
a.setMessage(144, 1, 82, 120);
MidiEvent noteOn = new MidiEvent(a, 1); // <-- means at tick one, the above event happens
track.add(noteOn);

ShortMessage b = new ShortMessage();
b.setMessage(128, 1, 82, 120);
MidiEvent noteOff = new MidiEvent(b, 64); // <-- means at tick one, the above event happens
track.add(noteOff);

// add the events to the track

// add the sequence to the sequencer, set timing, and start
sequencer.setSequence(seq);

sequencer.start();
// new
Thread.sleep(1000);
sequencer.close();
System.exit(0);
} catch (Exception ex) {ex.printStackTrace();}
} // close play

} // close class

I noticed a similar issue was filed in 2005 but that was never answered, hence my request again for info. If Sun continues to make JMF available for download then it should be supported?
Further, if this a known problem with no solution, then the book or their website should warn you not to install JMF
16 years ago