5.3 KiB
LocalChatApp
The second small project of the "Brick and Tile" team: A local LAN chat application based on Java Swing and Socket.
Introduction
This project is a C/S architecture instant messaging software that supports user registration, login, group chat, group management, and other functions. The project is developed in Java, using Swing as the GUI framework, and the underlying layer communicates in full duplex via TCP Socket.
Software Architecture
The project is mainly divided into three core packages: client, server, and global/util (common components).
Directory Structure
-
Client
- Entry file:
src/client/Client.java - Business Logic:
src/client/service/ChatReceiver.java: Responsible for receiving server messages and driving UI updatesChatSender.java: Responsible for sending messages to the serverLocalData.java: Client local data cache
- Interface Display:
src/client/view/LoginPage.java: Login/Registration main containerMainPage.java: Chat main interface containerlogin/: Specific view components for login and registrationmain/: Specific view components such as chat windows and group lists
- Entry file:
-
Server
- Entry file:
src/server/Server.java - Business Service:
src/server/serveice/ClientChatThread.java: Connection thread handling a single clientWrapper.java: Communication protocol data packet definition
- Data Model:
src/server/data/
- Entry file:
-
Common Components
- Global Constants:
src/global/global.java - Utilities:
src/util/MsgUtil.java: Message processing utilitySocketUtil.java: Socket related utilityFileUtil.java: File operation utility
- Global Constants:
Core Features
- User System
- Login and Registration
- Personal Information Maintenance
- Instant Messaging
- Real-time Group Chat
- Message Receiving and Sending
- Group Management
- Group List Display
- Group Information Update and Maintenance
UI Component Introduction
This project adopts a design pattern of dynamically replacing UI components. For example, on the login interface, when the user clicks the "Register" button, the login panel (SignIn) will be replaced by the registration panel (SignUp).
-
Login Page (
LoginPage)- Contains
SignInView: Login form component - Contains
SignUpView: Registration form component - Replacement Logic: Implement panel switching through
CardLayoutor removing/adding components.
- Contains
-
Main Interface (
MainPage)- Left Navigation (
SideOptionView): Function menu and group list - Middle Content (
ContentView): Chat window and message display - Secondary Options (
SecondaryOptionView): Auxiliary function entry. (Update: Added clear top and bottom dividers to the top title bar to enhance the visual hierarchy with the chat list and window title)
- Left Navigation (
-
UI Toolkit (
util)- Contains custom UI elements (such as
BlueOutlineWhiteBtn,CircleCharIcon2) DesignToken: Uniformly defines design specifications such as colors and fonts to ensure UI style consistency.
- Contains custom UI elements (such as
Project Packaging
This project supports generating independent client installation packages.
-
Compile and Package: Use Maven to compile.
pom.xmlis configured withmaven-resources-pluginto automatically copy dependencies totarget/lib.mvn clean package -
Generate Client Image: Use
jpackageto generate an independent client containing JRE.jpackage --type app-image --input target --main-jar LocalChatRoom-1.0-SNAPSHOT.jar --main-class client.Client --dest dist --name LocalChatClient --java-options "-Dfile.encoding=UTF-8" -
Generate Installer: Use Inno Setup to compile the
dist/setup.issscript, finally generatingdist/Output/LocalChatApp_Setup.exe.
Extended Features
This project reserves relevant interfaces and logic for the friend system. Although the current version mainly focuses on group chat, the following functions can be expanded in the future:
- Friend Management: Add and delete friends
- Private Chat Function: Establish point-to-point private chat sessions
- Status Synchronization: Friend online/offline status display
Note: At this stage, these functions are optional items and are not forcibly required to be implemented.
Development Environment
- JDK: Java 11 (Recommended) / Java 8
- Build Tool: Maven
- UI Framework: Java Swing / JavaFX
- Dependencies: The project has built-in required dependency libraries (located in the
lib/directory), and can be built without additional Maven repository configuration.
How to Run
-
Start Server Run the
mainmethod insrc/server/Server.java. -
Start Client Run the
mainmethod insrc/client/Client.java. Note: Please ensure the server is started, otherwise the client cannot connect.
Contribution Guide
- Fork this repository
- Create
feature/xxxbranch - Commit your code
- Create Pull Request