Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Problems with document based app in java

Problems with document based app in java
Thread Tools
Mac Elite
Join Date: Oct 2000
Location: Edinburgh, Scotland
Status: Offline
Reply With Quote
Jan 20, 2003, 06:01 PM
 
Hi guys + gals, hope you can help with this cos it's driving me mad!

I've got a "Document based application" which I'm using java to develop. The project is called Battler.

I used InterfaceBuilder to lay out the main document window (MyDocument.nib) with various buttons linked to a class called "battleGrid" which I then instantiated. In my project I now have three source code files:
MyDocument.java
battleGrid.java
main.m

When my program starts up, the window (from MyDocument.nib) is displayed and somewhere an instance of battleGrid is created. A new window is displayed and a new instance of battleGrid created every time I select "New" from the File menu.

At certain points in the game I want the window corresponding to a particular instance of battleGrid to display a sheet. However, I don't know how to tell that instance what window to display the sheet on (it has to be the one associated with that instance of battleGrid).

Can anyone help please?

I know a nasty hack I can use to get round it, but it's not very pretty. It involves using a global variable....Sooooo, onto question 2!

How can I create a global variable?

Thanks for all your help.
ClamXav - the free virus scanner for Mac OS X | Geobunny learns to fly
     
Forum Regular
Join Date: Jul 2002
Location: Australia
Status: Offline
Reply With Quote
Jan 20, 2003, 10:29 PM
 
Create an NSWindow outlet in battleGrid (there's an instance of it in MyDocument.nib right?) and connect it to the window you want a reference to. You can then use this reference within the class to refer to the window you want the sheet to attach to (I'm pretty sure this is correct, but it may not be. It may also be bad design, I'm only just learning Cocoa, and haven't done much with document based stuff).
     
Mac Elite
Join Date: Oct 2000
Location: Edinburgh, Scotland
Status: Offline
Reply With Quote
Jan 21, 2003, 02:31 AM
 
Thanks, I was playing around with InterfaceBuilder last night and spotted this one - felt really stupid for not noticing it earlier actually!

I'm not even convinced that a document based app was the right way to go, but I'd started the project before I even knew what I was developing!! Any help on the global variable?

Thanks
ClamXav - the free virus scanner for Mac OS X | Geobunny learns to fly
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jan 21, 2003, 03:09 AM
 
Originally posted by Geobunny:
Any help on the global variable?
Just make it a class variable. Those are globally accessable.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:04 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2