Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mixing Cocoa Java and Java AWT Q&A



Another way to get the effects of the performSelectorOnMainThread method is to use an NSTimer. Here is a code sample (where mainThread is a reference to the event thread and mainRunLoop is a reference to the event thread's currentRunLoop()):

// A selector used to play sounds only on the main thread
static private NSSelector playCocoaSelector = new NSSelector("play", new Class[] {});

public void play()
{
if (Thread.currentThread() == mainThread)
{
cocoaSound.play();
}
else
{
// recall this method on the main thread
mainRunLoop.addTimerForMode(new NSTimer(0, this, playCocoaSelector, cocoaSound, false), NSRunLoop.DefaultRunLoopMode);
}
}

--
Dustin Sacks
http://randomdude.com


On 29-Feb-04, at 5:40 PM, Dmitry Markman wrote:

well, if creators of Apple's Java implementation and CocoaJava
never heard about mixing of those 2 technologies
then maybe there is something in it :-)
maybe it should not be done
maybe we have not to try to create "hermaphrodite" :-)))

IMHO: if Apple didn't implement performSelectorOnMainThread
for Java's NSObject, again maybe they had a reason
maybe they tried and it didn't work or worked unreliable
I 100% sure they thought about that and decided not to do that.

you always can use Cocoa performSelectorOnMainThread from JNI
as I did for my WebKit/Java implementation



On Feb 29, 2004, at 4:43 PM, Greg Bolsinga wrote:

On Feb 28, 2004, at 2:53 PM, Andrew Thompson wrote:

You know though, it occurs to me that using java.util.Executor from JDK 1.5, one could easily write an Executor that called -performSelectorOnMainThread: Hrm, might see if I have time to do that once 1.5 goes final.

I believe that it would still be not recommended, supported, or suggested.

I must re-iterate. I have never ever heard of anyone mixing Cocoa Java and Java AWT until the postings on this list. I asked many of my co-workers, and they agreed that they had never heard of it either.

Please read in-between the lines of that statement, and please mind the Technical Q&As!
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Do not post admin requests to the list. They will be ignored.


Dmitry Markman
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Mixing Cocoa Java and Java AWT Q&A (From: Greg Bolsinga <email@hidden>)
 >Re: Mixing Cocoa Java and Java AWT Q&A (From: Andrew Thompson <email@hidden>)
 >Re: Mixing Cocoa Java and Java AWT Q&A (From: Greg Bolsinga <email@hidden>)
 >Re: Mixing Cocoa Java and Java AWT Q&A (From: Dmitry Markman <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.