PDA

View Full Version : Java-Cocoa Resources


Steven
2002.09.19, 05:43 PM
Where can I find resources on how to program with Java in PBX? I have done a search, with very few results :( Any good books or web-based resources? Specifically, I want to do drawing- I can't even figure out how to draw a rectangle :(.
???
Thanks,
Steven

Griggs
2002.09.19, 05:48 PM
How about:
http://developer.apple.com/techpubs/macosx/Cocoa/CocoaTopics.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

Steven
2002.09.19, 06:03 PM
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 :(. I would much rather use Java as I already know it.
:confused:
Thanks,
Steven

OneSadCookie
2002.09.19, 06:43 PM
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.

Steven
2002.09.19, 07:07 PM
Thanks, but it still doesn't work:
/* 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:

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.

OneSadCookie
2002.09.19, 07:34 PM
Looks like you need a constructor with a specific form. Try something like this:

public MyView(NSRect rect) {
super(rect);
}

Steven
2002.09.19, 10:16 PM
Wow! Hey thanks!!
Steven