• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Odd stuff with Cocoa-Java
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Odd stuff with Cocoa-Java


  • Subject: Re: Odd stuff with Cocoa-Java
  • From: David McCabe <email@hidden>
  • Date: Sun, 30 Sep 2001 21:14:00 -0700

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Okay, everyone. Thanks for the info, but you've completely missed the problem.

(This is it so pay attention): the timer does not start. Let me repeat that. The timer doesn't start.

I'm using NSTimer to do the thing. Take a look at this Java class:


/* EggTimer */

import com.apple.cocoa.foundation.*;
import com.apple.cocoa.application.*;

/**
EggTimer
This class controls the EggTime application. It starts the timer, and
acts when the timer has fired. The framework calls its methods when
events happen, ie, StartTimer() when Userboy clicks 'OK' button.
Copyright 2001 David McCabe.
*/
public class EggTimer {

NSTextField messageField;

NSTextField minuteField;

NSWindow theWindow;

/**
This method is called when Userboy clicks the Cancel button in
the setup dlg. Kills the app nicely.
*/
public void CancelApp(Object sender)
{
// WHY DOESN'T THIS WORK?!
//NSApplication theApp = NSApp.sharedApplication();

// theApp.terminate();
}


/**
public void StartTimer(Object sender)
This method is called by the framework when Userboy clicks
the 'OK' button in the settings dialog box. It starts the timer.
*/
public void StartTimer(Object sender)
{
int minutes = minuteField.intValue();
try
{
NSSelector fireMethod = new NSSelector("Fire", null);
NSTimer myTimer = new NSTimer( minutes * 60, this, fireMethod, null, false );
} catch( NullPointerException foo )
{
NSAlertPanel myAlert = new NSAlertPanel();
myAlert.runAlert( "NullPointerException", foo.getMessage(), null, null, null, null );
}


theWindow.close();

}


/**
public void Fire(void)
This method is called by the timer created by StartTimer().
It displays a dialog box. The timer, by the way, is implemented by
the NSTimer class which is part of the Cocoa framework.
*/
public void Fire()
{
// Display a dialog.
String myMessage = messageField.stringValue();
NSAlertPanel myAlert = new NSAlertPanel();
myAlert.runAlert( "EggTime", myMessage, null, null, null, null );

// Now kill the app.
CancelApp(null);
}
}

/* End of file. */


That is the main controller. For some reason, the Fire() method is not called. Also, the window is not closed. Full source is at <http://homepage.mac.com/davidmccabe/eggtime.tar.gz>.

On Sunday, September 30, 2001, at 06:31 PM, email@hidden wrote:

I haven't tried - but you should be okay with subclassing the NSWindowController and the NSView classes. I think that is normal. However - subclassing the NSTextField or whatever it is you were doing is not necessary. You should use an NSFormatter instead. You should be able to just drag one onto your Nib file through IB that will probably give you just numbers. You should maybe look at the vermont recipes stuff on Stepwise. The NSFormatter example (I think in recipe 4) is very useful in figuring it all out. It's in ObjC - but it's really easy to figure out and you could convert it to Java no problem...

Good Luck,
Tyler

On Sunday, September 30, 2001, at 06:32 PM, Brian Hook wrote:

At 11:59 PM 9/30/01 +0200, Andreas Monitzer wrote:
You don't have to, take a look at formatters. Subclassing is very seldom in Cocoa.

Subclassing in general, or subclassing text views? Because if you're saying the former, then I'm doing something REALLY wrong because I'm subclassing the hell out of NSWindowController and NSView right now.

Brian
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev


- --
David McCabe
http://homepage.mac.com/davidmccabe/
'finger email@hidden' for PGP key.
Wrfhf ybirf lbh!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (Darwin)
Comment: For info see http://www.gnupg.org

iD8DBQE7t+2KCwKQ8Z46eHoRAl9NAKDNxZP45Hvb5RchqEoLXPuzeZDUEgCg7BhM
CQUw7MMI55cRfkozhTgjDIA=
=IIdF
-----END PGP SIGNATURE-----


References: 
 >Re: Odd stuff with Cocoa-Java (From: email@hidden)

  • Prev by Date: Re: NSScrollView and general IB annoyance
  • Next by Date: Re: Does cocoa just leak?
  • Previous by thread: Re: Odd stuff with Cocoa-Java
  • Next by thread: Re: Odd stuff with Cocoa-Java
  • Index(es):
    • Date
    • Thread