Java, Cocoa, Examples & Help

  • <Attachment missing>

    Here I am, after RTFLA'ing, RTFMing, and also the examples source code.

    I am hacking together a simple GUI front end to fortune for MacOS X in
    Java (sorry, ObjC is not viable for me in my limited time). Rather than
    use Java's native windowing, I though a quick play with IB and PB would be
    in order.

    Its mostly working ( v.small, and simple too).

    Its heavily based on Celcius to Fahrenheit example from Apple. I need only
    one more thing to declare it complete, and set it to start at each login.

    The window has a text field, and two buttons. Clicking one displays a
    fortune in the textfield, the other, quits.

    The problem is, how to set the TextFields contents when its 1st displayed?
      i.e. from the constructor of my object? This is a simple java object, as
    in the CtoF example. I'm unsure how to tie this into the framework, as
    implementing the constructor Fortune() compiles, but fails at run time.

    Has anyone any ideas, pointers, or outright solutions?
    How do you start an application at each login in Macos X anyway?

    I've attached the Java source file of the Fortune class - its only a few
    lines long.

    Thanks in advance

    George Russell
  • > The problem is, how to set the TextFields contents when its 1st displayed?
    > i.e. from the constructor of my object? This is a simple java object, as
    > in the CtoF example. I'm unsure how to tie this into the framework, as
    > implementing the constructor Fortune() compiles, but fails at run time.
    >
    > Has anyone any ideas, pointers, or outright solutions?

    I hope there might be an easier way, but this method works. If you subclass
    NSWindowController, you can do your window initialization before the window
    gets displayed by overriding the inherited method windowDidLoad(). However,
    the only way I can figure out how to do this is by creating an NSDocument
    object that creates the NSWindowController object. So here are the steps
    that I use:

    1. Start with a Cocoa-Java Document-based application.
    2. In Interface Builder, create a subclass of NSWindowController
    ("MyWindowController" is the default) to respond to your outlets.
    3. In MyDocument.nib, change "File's Owner"  to be of type
    "MyWindowController". Do this by selecting "File's Owner" in the Instances
    tab, then going to the Info tool window, select the Attributes popup, then
    pick "MyWindowController" from the list.
    4. Connect "File's Owner" to your outlet.
    5. In MyDocument.java, add the makeWindowControllers() and remove
    windowNibName() and windowControllerDidLoadNib()
    6. Add the nib file name to the constructor in MyWindowController, add the
    windowDidLoad() method, and handle the rest of your window controls there.

    I've attached the two example files in the hopes of making this explanation
    clearer. Also, since you are using an NSTextField, this will leave whatever
    text you set selected when the app launches, so you might want to make it
    non-editable (or find another way to disable First Responder, which I think
    requires a delegate method).

    > How do you start an application at each login in Macos X anyway?

    You can assign startup apps in the Login panel in System Preferences.
previous month april 2001 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
Go to today
MindNode
MindNode offered a free license !