• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multiple file Project

 
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens when you don't copy the code? I suspect there will be a simple solution to using it in its own file.
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know that this works, but I am trying to figure out how to access part of the GUI.

 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
He decided to let me stick it in the class that defined the GUI so now it works no problem.
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Put a gun against his head, pulled my trigger, now he's dead, that tiny ad sure bled
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic