Woestijnvis
asked on
Where to put the JFrame actionlisteners when programming client-server with sockets.
I am programming a client server program over sockets.
I have a main class where I Open a JFrame class and inside the JFrame I have another class with a panel. This panel has 2 buttons. When I click this buttons I need to send a command to the server.
As my Buttons are in the panel class, my actionlisteners for this buttons are too. My socket is initiated in the main class and is in a while(true) loop.
How can I get to the socket from my actionlisteners, as my socket instance is unknown in Jpanel class. How can I fix this? I can't pass my socket object to the frame, I tried and that doesnt work.
I have a main class where I Open a JFrame class and inside the JFrame I have another class with a panel. This panel has 2 buttons. When I click this buttons I need to send a command to the server.
As my Buttons are in the panel class, my actionlisteners for this buttons are too. My socket is initiated in the main class and is in a while(true) loop.
How can I get to the socket from my actionlisteners, as my socket instance is unknown in Jpanel class. How can I fix this? I can't pass my socket object to the frame, I tried and that doesnt work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Genius,
I understand your solution, but my button is in a panel, my panel is in a frame and my frame is being called by a main class. My socket is in the main class. The easiest step would be to bring my socket in the frame class. But thats not good programming because I want MVC.
How can I get the actionListener of the button up to the main class?
Eli
I understand your solution, but my button is in a panel, my panel is in a frame and my frame is being called by a main class. My socket is in the main class. The easiest step would be to bring my socket in the frame class. But thats not good programming because I want MVC.
How can I get the actionListener of the button up to the main class?
Eli
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
or add a method to the class that contains the class to add the listener
public void addActionListener(ActionLi
button.addActionListener(l
}
you can then call that from your main class to add a listtener which owuld have access to socket