Java-Cocoa Resources

Member
Posts: 370
Joined: 2002.04
Post: #1
Where can I find resources on how to program with Java in PBX? I have done a search, with very few results Sad Any good books or web-based resources? Specifically, I want to do drawing- I can't even figure out how to draw a rectangle Sad.
???
Thanks,
Steven
Quote this message in a reply
Griggs
Unregistered
 
Post: #2
How about:
http://developer.apple.com/techpubs/maco...opics.html
They include a Java tutorial, and all reference material has info for Java too.

though you may want to consider learning Objective-C, because among other things, most Cocoa sample code is Obj-C
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #3
I have already looked there- but I can't figure out how to get started. I did the tutorial, but it says nothing about how to draw to the screen Sad. I would much rather use Java as I already know it.
:confused:
Thanks,
Steven
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
I've never used Cocoa Java, but hopefully this is still relevant:

Make a custom view in your window with Interface Builder. Subclass NSView, and set the class of your custom view to the new subclass. Choose Java for the language the class is implemented in. Generate the file for the class.

Override the drawRect method for the subclass. In the drawRect method, use NSBezierPath to draw whatever you want. Check out the docs for all the funky things you can do with an NSBezierPath.

Ask again if you have more problems.
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #5
Thanks, but it still doesn't work:
Code:
/* MyView */

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

public class MyView extends NSView {

    public void drawRect(NSRect rect){
        NSBezierPath aPath;
        aPath = NSBezierPath.bezierPathWithOvalInRect(rect);
        aPath.stroke();
    }

}


It gives this in the Run thingy:

Code:
2002-09-19 15:57:46.688 NSViewTest[686] AppKitJava: uncaught exception NSInvalidArgumentException (_BRIDGEUnmappedInitMethodImp: the java class MyView does not implement any constructor that maps to the Objective C method initWithFrame:.)
2002-09-19 15:57:46.690 NSViewTest[686] AppKitJava: exception = _BRIDGEUnmappedInitMethodImp: the java class MyView does not implement any constructor that maps to the Objective C method initWithFrame:.
2002-09-19 15:57:46.690 NSViewTest[686] AppKitJava: terminating.

NSViewTest has exited with status 1.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
Looks like you need a constructor with a specific form. Try something like this:

Code:
public MyView(NSRect rect) {
    super(rect);
}
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #7
Wow! Hey thanks!!
Steven
Quote this message in a reply
Post Reply