Multiple file Project
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I have never worked on one before so Im trying to sort stuff out here.
A guy is the project leader and has created the GUI already. He has one file that sets up the GUI. Then another file as the actionlistener on the menu. He has four "status areas" at the bottom of the screen of the GUI. When someone clicks File New the infoArea0 is supposed to say NEW. With this being on a separate file I do not have access to the infoArea0 so how do I get access to it. I have copied and pasted that file into the file that creates the GUI and it worked. I just need that other file to have access(rights) to it. Any way to do this? I kinda think it should all be one file(anything dealing with the GUI) and have it call Classes to process things.
A guy is the project leader and has created the GUI already. He has one file that sets up the GUI. Then another file as the actionlistener on the menu. He has four "status areas" at the bottom of the screen of the GUI. When someone clicks File New the infoArea0 is supposed to say NEW. With this being on a separate file I do not have access to the infoArea0 so how do I get access to it. I have copied and pasted that file into the file that creates the GUI and it worked. I just need that other file to have access(rights) to it. Any way to do this? I kinda think it should all be one file(anything dealing with the GUI) and have it call Classes to process things.
Visit my blog! http://jameshambrick.com
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I dont know what you want really.
But yes you're right, you need to couple things that belong together(cohesion).
All the user interface should be separate from the actual funcioning code.
so yes, have outside classes that you call in the GUI to do the work for you.
ok, nevermind, I understand now.
all you need to do is have a listener on the menu, and when new is selected, just print the text "NEW" into that JTextArea.
I believe that is what you are asking.
and if you want to create a class that will create a file with the same text, look into BufferedWriter();
I think the initialization of a BufferedWriter to a file is like so:
so you could have a class called NewFile
and have it to where when you called an instance of it, it created a file
for for reading a writing.
then have different methods of that class that write to it and things of that sort. I dont know all the different IO classes by heart, but these are some you should look at.
-PrintWriter
-FileOutputStream and FileInputStream
-BufferedReader
-BufferedWriter
-File
these are different class that can pertain to modifying and creating files,
I'm sure there are more.
Hope this helps you out,
Justin Fox
Justin Fox
[ November 17, 2007: Message edited by: Justin Fox ]
But yes you're right, you need to couple things that belong together(cohesion).
All the user interface should be separate from the actual funcioning code.
so yes, have outside classes that you call in the GUI to do the work for you.
ok, nevermind, I understand now.
all you need to do is have a listener on the menu, and when new is selected, just print the text "NEW" into that JTextArea.
I believe that is what you are asking.
and if you want to create a class that will create a file with the same text, look into BufferedWriter();
I think the initialization of a BufferedWriter to a file is like so:
so you could have a class called NewFile
and have it to where when you called an instance of it, it created a file
for for reading a writing.
then have different methods of that class that write to it and things of that sort. I dont know all the different IO classes by heart, but these are some you should look at.
-PrintWriter
-FileOutputStream and FileInputStream
-BufferedReader
-BufferedWriter
-File
these are different class that can pertain to modifying and creating files,
I'm sure there are more.
Hope this helps you out,
Justin Fox
Justin Fox
[ November 17, 2007: Message edited by: Justin Fox ]
You down with OOP? Yeah you know me!
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The listener is already there, If I copy the code from the separate file into the file that creates the GUI then it works(set's the text in infoArea). Whats the best way to display line numbers and column numbers?
Visit my blog! http://jameshambrick.com
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
What happens when you don't copy the code? I suspect there will be a simple solution to using it in its own file.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
infoArea0 is not recognized so I cannot use infoArea0.setText("Bold"); in taht file, but I can inside the GUI file because that is where all the infoArea's are defined.
Visit my blog! http://jameshambrick.com
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
And how do I make these two files communicate? The Gui file has the infoArea's defined, but the logic that sets the infoArea is in another file(userGuiCommand).The project leader wants it separated(after I told him that I joined the two files and had it working).
Like I said before one file(Gui) sets up the GUI and displays the program, then the listener is on another file(useGuiCommand). So I need the userGuiCommand to pass the information to the Gui file and have it do the infoArea0.setText("Bold"); Seems easier to have it all in one file, but he wants it separate.
Like I said before one file(Gui) sets up the GUI and displays the program, then the listener is on another file(useGuiCommand). So I need the userGuiCommand to pass the information to the Gui file and have it do the infoArea0.setText("Bold"); Seems easier to have it all in one file, but he wants it separate.
Visit my blog! http://jameshambrick.com
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I know that this works, but I am trying to figure out how to access part of the GUI.
Visit my blog! http://jameshambrick.com
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
He decided to let me stick it in the class that defined the GUI so now it works no problem.
Visit my blog! http://jameshambrick.com
Stan James
(instanceof Sidekick)
Posts: 8791
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I was after the details of what goes bad. How does "infoArea0 is not recognized" manifest itself? A compiler error message? What message, on what line? Your examples don't have an "infoArea0" so they don't illuminate the problem much. Without detail like that I'm guessing ...
And I'm guessing you copy the listener class file into the GUI class file so the variables of the top level class are visible to the code in the inner class. That's a fine technique as long as you don't want to make reusable listeners.
If you put the listener in a separate source file, you might give it references to the GUI widgets it needs to work with. For example you might pass inforArea0 in a constructor. Or you might give the listener a reference to the window or some container in the hierarchy and add a method there to update the text area.
And I'm guessing you copy the listener class file into the GUI class file so the variables of the top level class are visible to the code in the inner class. That's a fine technique as long as you don't want to make reusable listeners.
If you put the listener in a separate source file, you might give it references to the GUI widgets it needs to work with. For example you might pass inforArea0 in a constructor. Or you might give the listener a reference to the window or some container in the hierarchy and add a method there to update the text area.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Justin Fox
Ranch Hand
Posts: 802
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Just have a componentModify class, in which you pass whatever JComponent you want to, in the constructor and modify it further there.
example:
in the above class your passing either a JTextField to that class or
a JTextArea, so in the setter method you try to determine which of the
two that instance is, so you can modify the correct one with out error.
This is just an extra step, in your case you would just have a JTextArea passed, and modify it, i.e "JTextArea.append("BOLD");".
someone in an above comment gave you the exact same advice.
it doesn't matter where that textarea is initialized, if you pass it (after it is initialized ofcourse) to another class, when that class calls its ".setText()" or ".append()" or ".getText()" those methods in that separate class will modify the GUI Component passed, that is in the GUI class.
gets kind of hard to word after awhile,
but I hope this helps out a little atleast.
Justin Fox
example:
in the above class your passing either a JTextField to that class or
a JTextArea, so in the setter method you try to determine which of the
two that instance is, so you can modify the correct one with out error.
This is just an extra step, in your case you would just have a JTextArea passed, and modify it, i.e "JTextArea.append("BOLD");".
someone in an above comment gave you the exact same advice.
it doesn't matter where that textarea is initialized, if you pass it (after it is initialized ofcourse) to another class, when that class calls its ".setText()" or ".append()" or ".getText()" those methods in that separate class will modify the GUI Component passed, that is in the GUI class.
gets kind of hard to word after awhile,
but I hope this helps out a little atleast.
Justin Fox
You down with OOP? Yeah you know me!
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
oh you can pass GUI components! I will try this when I get home and some time, with Christmas coming I dont have alot of time at the computer.
Visit my blog! http://jameshambrick.com
| You firghten me terribly. I would like to go home now. Here, take this tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |







