wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes How to make globally defined buttons, textfields, known inside separate class files? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to make globally defined buttons, textfields, known inside separate class files?" Watch "How to make globally defined buttons, textfields, known inside separate class files?" New topic
Author

How to make globally defined buttons, textfields, known inside separate class files?

Ana Suvari
Ranch Hand

Joined: Aug 18, 2009
Posts: 43
I am trying to hook the Java GUI to RoseRT and but the example tutorial that I was given had only two files. One for the Controller and one for the Window (view).

They have all their classes inside that Window class and the buttons and fields are defined in that one page.

But my code has the classes in separate files and I get compile errors saying that those buttons are undefined even though I defined them in Window class.

What can I do to make the classes in separate files know about those globally defined buttons?

The reason why they are globally defined is for easier hooking up the RoseRT model and easier to control when all the interactions of signals being passed are in one file.

I tried putting all my classes within the Window class but that causes me to have bugs because "static methods cannot be referenced within a class".

Please help.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
What "Java GUI" do you mean? Swing? AWT? SWT? Other (am I missing the boat here)?
Ana Suvari
Ranch Hand

Joined: Aug 18, 2009
Posts: 43
My GUI is my interface with all the buttons, textfields, textArea, etc.

The user logs in. He has to type in a textfield and enters his name. Then clicks on a button.

All the inputs are passed as signals to RoseRT to handle them. RoseRT will communicate by checking if the name is valid. If valid or invalid, it will send a message back to Java GUI.

Thus, i need all the buttons in one file for easier management.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Ana Suvari wrote:My GUI is my interface with all the buttons, textfields, textArea, etc.


Again, is this Swing? AWT? SWT? ...??
Ana Suvari
Ranch Hand

Joined: Aug 18, 2009
Posts: 43
I use both awt and swing. Is that wrong?
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Ana Suvari wrote:I use both awt and swing. Is that wrong?


Your visual components should be one or the other, and in most instances, Swing. Otherwise you'll have to take care not to have heavyweight components clobber your lightweight components.

OK, now that we know what GUI libraries you're using, I think we can better help you. First of all, you should not be trying to use global anything. Your buttons (JButtons) should be private. The controller code is what needs to be able to talk to your model (non-GUI logic) and to the GUI or view.
Ana Suvari
Ranch Hand

Joined: Aug 18, 2009
Posts: 43
Ok, that seemed to work when i put the buttons back in their classes like you said.

However, I still don't get the example tutorial. The Controller only has the window, hostname and portnumber as parameters and not any of my subclasses. Thus, i don't know how to access the button's action in a separate class.

In the Controller, How do i call the action class for getJoinButton() when its defined in the JoinServer class. It still needs to know the name of classes and procedures to control the button which are definied in separate classes and not the Window class that is passed in.

.

... Theres more but don't need to show all
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Ana Suvari wrote:
However, I still don't get the example tutorial. The Controller only has the window, hostname and portnumber as parameters and not any of my subclasses. Thus, i don't know how to access the button's action in a separate class.

In the Controller, How do i call the action class for getJoinButton() when its defined in the JoinServer class. It still needs to know the name of classes and procedures to control the button which are definied in separate classes and not the Window class that is passed in.

I'm no pro at this, but my take is that you may need more than one Controller class since your View is more complicated, and the Controller(s) will somehow need a reference to any view class that it needs to extract data from, either by additional constructor parameters of a setView method.
Ana Suvari
Ranch Hand

Joined: Aug 18, 2009
Posts: 43
I don't understand what to do...The window class is the top level. I can't just make the subclass called inside window as another parameter to the Controller. It doesn't make sense too.

public RoseRealTimeController(RoseRealTimeWindow window, JoinRoom jroom, String hostname, int portnumber)

Please help me someone. I'm really strugglinig I'm supposed to be working with my team but they abandoned me.

I'm in trouble if i can't figure it out.
Ana Suvari
Ranch Hand

Joined: Aug 18, 2009
Posts: 43
Ana Suvari wrote:I don't understand what to do...The window class is the super class that calls creates an instance of JoinRoom. I can't just make the subclass called inside window as another parameter to the Controller. It doesn't make sense too. I need to make Window class know about it so then Controller will know about it.

public RoseRealTimeController(RoseRealTimeWindow window, JoinRoom jroom, String hostname, int portnumber)

Please help me someone. I'm really strugglinig I'm supposed to be working with my team but they abandoned me.

I'm in trouble if i can't figure it out.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make globally defined buttons, textfields, known inside separate class files?