• 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
Cocoa Java NSString drawing?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cocoa Java NSString drawing?


  • Subject: Cocoa Java NSString drawing?
  • From: email@hidden
  • Date: Tue, 26 Jun 2001 23:29:25 -0400

I am wondering what the easiest way to "draw" a string to a subclass of NSView is in the Java version of Cocoa. My problem really stems from trying to get the O'Reilly Learning Cocoa Appendix A code (Drawing in Cocoa) converted over to Java (just for the sake of learning really). I think I have most of it converted, but when I look in the Java Cocoa Documentation there isn't an NSString class, so instead I use a String - which works until I hit the LAST line in the example, which has the NSString call a method for drawAtPoint. Now obviously the java String does not recognize the drawAtPoint method. SO - what is the best way to do this? It would be easier to track down if java had the NSString class I suppose. There should at least be a pointer to WHY we don't have that class and what to use instead.

Essentially I want to convert this line:

[string drawAtPoint: NSMakePoint((myBounds size.width/4.0), 5) withAttributes: attrs];

to the Java counterpart. Here is my entire conversion if you want to see that:

/* MyView */

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

public class MyView extends NSView
{
private String string;
private NSFont font;

public boolean isFlipped()
{
return true;
}

public MyView(NSRect frame)
{
super(frame);
this.setString("Hello World");
this.setFont(NSFont.systemFontOfSize(12));
}

public void setString(String value)
{
string = value;
this.setNeedsDisplay(true);
}

public void setFont(NSFont value)
{
font = value;
this.setNeedsDisplay(true);
}

public void drawRect(NSRect rect)
{
NSRect myBounds = this.bounds();
NSMutableDictionary attrs = new NSMutableDictionary();

attrs.setObjectForKey(font,font.fontName());
string.drawAtPoint(new NSPoint((myBounds.width())/4,(float)5.0),attrs);
}
}



there may be other problems in there, but this drawAtPoint one is the most obvious since it won't get past that during compile. I tried to see if I could figure out what the Sketch example was doing to accomplish this - but it is a bit complex for me right now.

Any help would be appreciated...
Tyler


  • Prev by Date: Re: Problems with NSOutlineView in Java?
  • Next by Date: autoreleasing NSBezierPath object
  • Previous by thread: Re: Oddities in Cocoa/Java object initialization?
  • Next by thread: autoreleasing NSBezierPath object
  • Index(es):
    • Date
    • Thread