Package client
Class ChatView
java.lang.Object
client.ChatView
- All Implemented Interfaces:
ChatModelListener
ChatView - The View component of the MVC pattern.
Responsible for displaying the UI. Contains no business logic.
Implements ChatModelListener(Observer) to receive updates from the Model.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidRegisters a listener for the "Add Chat" button.voidaddChatSelectionListener(ActionListener listener) Registers a listener for selecting chat rooms.voidRegisters a listener for the "Disconnect" button.voidRegisters a listener for the message input field (e.g., for Enter key).voidRegisters a listener for the "Login" button.voidRegisters a listener for the "Send" message button.voidRegisters a listener for the "Send Image" button.voidClears the text in the "Add Chat" input field.voidClears the message input field.voidcreateAndShowUi(String inituser) Initializes the GUI components, sets up layouts, and displays the main frame.getFrame()voidonChatSelected(Chat chat) Updates the display when a user selects a different chat room.voidonChatsLoaded(ArrayList<String> chats, String ActiveChat) Populates the sidebar with the list of available chat rooms.voidonMessageAdded(Chat chat) Updates the UI when a message is added to a specific chat.voidonMessageReceived(Message message) Updates the current chat view with a single incoming message.voidRemoves content of chatPanelvoidupdateUserList(String chatName, String[] activeUsers, ArrayList<String> inChatUsers) Updates the user list in the sidebar when a chat update is received.
-
Constructor Details
-
ChatView
public ChatView()
-
-
Method Details
-
createAndShowUi
Initializes the GUI components, sets up layouts, and displays the main frame.- Parameters:
inituser- The initial username to display in the login field.
-
onMessageAdded
Updates the UI when a message is added to a specific chat. Re-initializes the entire chat message panel.- Specified by:
onMessageAddedin interfaceChatModelListener- Parameters:
chat- The Chat object containing the updated message history.
-
onMessageReceived
Updates the current chat view with a single incoming message.- Specified by:
onMessageReceivedin interfaceChatModelListener- Parameters:
message- The Message object to append to the view.
-
updateUserList
Updates the user list in the sidebar when a chat update is received.- Specified by:
updateUserListin interfaceChatModelListener- Parameters:
chatName- The name of the chat room being updated.activeUsers- An array of usernames currently active in the chat.inChatUsers- An ArrayList of usernames currently in the chat.
-
onChatsLoaded
Populates the sidebar with the list of available chat rooms. Ensures listeners are reapplied to new buttons.- Specified by:
onChatsLoadedin interfaceChatModelListener- Parameters:
chats- An ArrayList of strings representing chat room names.ActiveChat- The name of the currently selected chat room.
-
onChatSelected
Updates the display when a user selects a different chat room.- Specified by:
onChatSelectedin interfaceChatModelListener- Parameters:
chat- The Chat room data to display.
-
clearAddChatField
public void clearAddChatField()Clears the text in the "Add Chat" input field. -
getAddChatText
- Returns:
- The text currently in the "Add Chat" input field.
-
addChatSelectionListener
Registers a listener for selecting chat rooms. The listener is stored to be reapplied when the chat list refreshes.- Parameters:
listener- The ActionListener for chat room selection buttons.
-
addChatButtonListener
Registers a listener for the "Add Chat" button. -
addSendButtonListener
Registers a listener for the "Send" message button. -
addSendImageButtonListener
Registers a listener for the "Send Image" button. -
addLoginButtonListener
Registers a listener for the "Login" button. -
addDisconnectButtonListener
Registers a listener for the "Disconnect" button. -
addInputFieldListener
Registers a listener for the message input field (e.g., for Enter key). -
removeChatPanel
public void removeChatPanel()Removes content of chatPanel -
getLoginText
- Returns:
- The text currently in the Login input field.
-
getInputText
- Returns:
- The text currently in the message input field.
-
clearInputField
public void clearInputField()Clears the message input field. -
getFrame
- Returns:
- The main JFrame of the application.
-