 |
 |
talking to GUI in Java
|
 |
|
 |
|
Forum Regular
Join Date: Sep 2000
Status:
Offline
|
|
I'm having a bit of a problem here - I've got a nice little command-line java app that I've written, and now I'm trying to build the GUI on top of it.
I have happily created the beginning GUI (one window, kind of like a console) and I can get NSText fields to send text to the app... however, I cannot find a way in my other classes to get ahold of the reference to the NSScrollView that I have set up in my main nib. Since PB ignored my main() function, I have a startup function in the nib's controller file. So FROM the interface I can send things, but I cannot get any info back to it, because I don't know what to talk to.
I can send text to the scrollview from within the controller class, so it does know that it's there.
Any help is appreciated!
-uD
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Read the into to Java programming with Cocos in /Developer/Documentation/Cocoa/JavaTutorial - it should answer most of what you're asking. Have you subclassed java.lang.Object in IB with your controller files, instantiated them, and linked your actions (methods) and oulets (variables) from the interface to your instantiated controller objects? I'm guessing this is what you forget to do.
HTH,
F-bacher
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Sep 2000
Status:
Offline
|
|
Originally posted by Ghoser777:
<STRONG>Read the into to Java programming with Cocos in /Developer/Documentation/Cocoa/JavaTutorial - it should answer most of what you're asking. Have you subclassed java.lang.Object in IB with your controller files, instantiated them, and linked your actions (methods) and oulets (variables) from the interface to your instantiated controller objects? I'm guessing this is what you forget to do.
HTH,
F-bacher</STRONG>
I most definately have. Like I said, I can access all peices of the interface from within the controller class. (doing an insertText on the NSScrollView in response to a button click works perfectly.) I'm calling the main function (in some other random class) from the controller class (since it runs at startup), the obvious object that is instantiated (the controller class) is accessable from within itself.
Since main() is in another class, how do I then send messages back to my controller class? Do I need to set up a stream between them? I simply cannot figure out the reference to the controller class. (as in, what is it named? is it a subclass of NSApplication?)
-uD
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Okay, for the sake of helpful visualization, what does main() do? I mean, does it find n primes, decode an mp3, download porn, etc? Why not make an instance of your class that contains main()? If it has some useful algorithms, you can use that class over and over again instead of tweaking main() to make it do what you want.
Ultimately, I think you either want main() to return something, or you're going to have to make an instance of main() so you can send it messages and get the data you're interested in.
Hope that makes some sense,
F-bacher
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Sep 2000
Status:
Offline
|
|
Originally posted by Ghoser777:
<STRONG>Okay, for the sake of helpful visualization, what does main() do? I mean, does it find n primes, decode an mp3, download porn, etc? Why not make an instance of your class that contains main()? If it has some useful algorithms, you can use that class over and over again instead of tweaking main() to make it do what you want.
Ultimately, I think you either want main() to return something, or you're going to have to make an instance of main() so you can send it messages and get the data you're interested in.
Hope that makes some sense,
F-bacher</STRONG>
Basically, main() starts the whole application. Like I said, this is a full java command-line app, so I need it to be able to run from any machine. I'm just building the UI natively in cocoa. I have a class hierarchy set up so that if there is no UI, it just uses System.in and System.out to recieve and output commands. Now I've added a UI, and before I go throwing around controller classes, I need to be able to access the elements of the UI from the rest of the app. The problem is, my controller class is loaded automatically, and it ignores my app's main() function, so I call it from the controller class constructor.
But once main has started up, I have an instance of the controller class running (which is evidenced by a window being open). I couldn't make the elements static to be able to call controllerClass.NSScrollviewEx.insertText(String s) from other classes. If the main class returned anything, it would be when the application was completely done, and I'd get one thing. Since I can send output to System.out at any time during the execution of the application, do I need to set up a similar stream in my controller class? Or is there some default reference that is established when the application starts up?
Since I never do a new controllerClass(), because it starts up automatically, I have no reference to it. That's what I'm looking for.
I just realized... could I pass something like "mainClass.startMeUp(this)" which would then give the mainClass a reference, which could then call main()? hmm...
I'm ultimately trying to NOT change the rest of the application just to suit the UI.
Thanks
-uD
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Well, if you want, I guess you could try to create a STDOUT and STDIN buffer reader to catch all you're S.O.P calls... but that just sounds messy.
Okay, let's see if I can explain why controllerClass.NSScrollviewEx.insertText(String s) doesn't work: When you load your app, it makes an instance of NSScrollViewEx, so trying to calling it statically just doesn't make any sense. Because you are actually editing your mainClass (I think that's where you are calling this from), you can do one of two really easy things:
1. Pass all your outlets by reference to main and have main work on them as so:
contollerClass
..............
mainClass.printLotsOfPrimes(n, output); //int n and NSTextView ouput
..............
mainClass
.........
public static void printLotsOfPrimes(int n, NSTextView output)
//remember to import com.apple.....
{
output.insertText(findPrimes(n)); //where findPrimes returns a String
}
2. You could make an instance of your mainClass in IB and link the outlets to it that way. One way or another, you probably want your outlets to be passed to your main() function, if you don't want it to return anything.
Gooluck,
F-bacher
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
I'd use NSTask.
From what I can make out you don't want to change your command-line program (much, if at all) to work with a GUI. So, handing variables to your main() (or wherever) doesn't make any sense -- that would require a change.
You can include your command-line app inside (YourApp.app/Contents/..../TheExecutable) your GUI application, start the command-line app with NSTask and get input and ouput streams to it.
Aside from NSTask you can do much the same with plain ole Java. For an example check out Nicer (GUI wrapper for renice). I haven't touched Nicer since the Public Beta so it's not very pretty or up to date but it may help.
HTH
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|