A Java-based chatbot application featuring a graphical user interface with client-server architecture, utilizing an embedded H2 database for keyword-based responses.
- Client-Server Architecture: Separate client and server components communicating via sockets
- Graphical User Interface: Swing-based chat interface for user interaction
- Database-Driven Responses: Keyword-based chatbot responses stored in H2 database
- Embedded Database: H2 database for easy deployment without external dependencies
- Real-time Communication: Socket-based communication between client and server
- Multi-threaded Server: Handles multiple client connections simultaneously
- Java: Core programming language
- Swing: GUI framework for the client interface
- Socket Programming: Network communication between client and server
- H2 Database: Embedded relational database for storing chatbot data
- JDBC: Database connectivity
- Ant: Build automation (NetBeans project structure)
- Java Development Kit (JDK): Version 8 or higher
- Java Runtime Environment (JRE): For running the compiled application
- Operating System: Windows, macOS, or Linux
# If using Git
git clone <repository-url>
cd Chatbot-Java-masterChatbot-Java-master/
βββ src/
β βββ backend/
β β βββ Answer.java # Chatbot response logic
β β βββ DBHelper.java # Database connection and operations
β βββ frontend/
β βββ Client.java # GUI client application
β βββ Server.java # Server application
βββ db_file/
β βββ chatbot_1.sql # Database schema and sample data
βββ lib/
β βββ h2-2.1.214.jar # H2 database driver
βββ build.xml # Ant build configuration
βββ manifest.mf # JAR manifest
βββ README.md # This file
The application uses an embedded H2 database that is automatically created on first run. The database schema includes:
- answer table: Stores chatbot responses with categories
- ask table: Stores user input keywords mapped to categories
Sample data includes basic Indonesian greetings and responses.
# Create build directory if it doesn't exist
mkdir -p build/classes
# Compile all Java files
javac -cp "lib/h2-2.1.214.jar" -d build/classes src/**/*.javajava -cp "build/classes;lib/h2-2.1.214.jar" frontend.Serverjava -cp "build/classes;lib/h2-2.1.214.jar" frontend.Client# Clean and build the project
ant clean
ant compile
# Run the server
ant -Dmain.class=frontend.Server run
# Run the client (in a new terminal)
ant -Dmain.class=frontend.Client run- Start the Server: Run the server first to initialize the database and start listening for connections
- Launch the Client: Open the client GUI application
- Chat Interface:
- Type your message in the text field at the bottom
- Click "Send" button or press Enter to send
- Chat history appears in the main text area
- Type "/quit" to exit the application
- User: "hai" β Bot: "hai juga"
- User: "apa kabar?" β Bot: "gimana kabarnya"
- User: "bye" β Bot: "bye!"
To view or modify the database directly:
java -jar lib/h2-2.1.214.jar- JDBC URL:
jdbc:h2:./db_file/chatbot_1 - Username:
sa - Password: (leave empty)
To expand the chatbot's knowledge base, add entries to the answer and ask tables:
-- Add new response
INSERT INTO answer (answer, category) VALUES ('Your response here', 'category_name');
-- Add keyword mapping
INSERT INTO ask (ask, category) VALUES ('user_input', 'category_name');Located in src/backend/DBHelper.java:
- Database URL:
jdbc:h2:./db_file/chatbot_1 - Username:
sa - Password: (empty)
Located in src/frontend/Server.java:
- Port: 1239 (default)
- Host: localhost (127.0.0.1)
- Server: Manages database connections, processes user input, generates responses
- Client: Provides GUI interface, sends user messages, displays responses
- Database: Stores conversation patterns and responses
- DBHelper.java: Database connection and query execution
- Answer.java: Business logic for response generation
- Server.java: Socket server handling multiple clients
- Client.java: Swing GUI for user interaction
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Add more conversation data to the database
- Implement conversation history persistence
- Add user authentication
- Enhance the GUI design
- Implement natural language processing
This project is licensed under the MIT License - see the LICENSE file for details.
- Built as a learning project for Java socket programming
- Uses H2 database for embedded database functionality
- Inspired by basic chatbot implementations
Note: This is a basic implementation intended for educational purposes. The chatbot has limited responses and would benefit from additional training data for more comprehensive conversations.