A graphical project implemented in pure Java language - Lemon (beautiful social chat personalization applet)

Xiaochat: In this article, I will introduce to you the first Java project written in the early years, a graphical project written in pure Java, using the built-in JFrame. . . Ah, I really miss it, it’s nothing, I just want to record how I felt when I was just learning Java. Ahem, don't talk nonsense, because it was written when I just finished learning the basics of Java, and there is no technical content, so I simply recall it, laughing. The project has been put on github, and those who are interested can pick it up by themselves, with a programming report attached. Also, my annotations are super detailed, and I had this awareness at that time.
github address: "Lemon"


1. Project introduction

  • Item name

Lemon

  • project details

It is a multi-person chat program that simulates the web version of QQ graphical interface. There will be a preview of what it looks like below.

  • project function

Account password login, personal information display and modification, multi-person online chat.

  • Main technical content of the project (Java foundation)

Multi-threading, IO stream file operation, network transmission based on TCP protocol, Swing GUI (Java comes with it)

  • Project development environment

eclipse, windows10.
Oh, I used eclipse at the beginning, everyone knows it. Because the structure of the eclipe project is different from that of the idea, in fact, the project structure between the versions of eclipse will also be different, and the previous default encoding is GDK (idea is UTF-8), and now the default encoding of the 2022 version of eclipe seems to be UTF -8. If you have running problems if you want to download, I suggest you create a new project and copy the content into your own project. Anyway, there is not much content. As for the problem of project file encoding, my original code must be GDK, and now the uploaded version encoding has been changed to UTF-8, so it doesn’t matter if you are using the latest version of eclipse. If you use the old version, you can set and modify the Encoding. , It’s okay if it’s an idea.


2. Project demo

It was originally an eclipse project, but in order to verify the portability, I used idea to create a new project and then copied the content into this empty project, and it started and ran normally.

2.1. Project start entry

Lemon_Action.java file under src/com/lemon/login

insert image description here

It's just a main program, hehe, and then start the thread from the beginning, without using the thread pool, I didn't understand it at that time~ I don't plan to move it, just keep the original appearance.


2.2. The initial login interface

After the project starts successfully, the login window will pop up

insert image description here


2.3. Register and log in

At that time, it was too troublesome to set the account password to death, because I thought it was still in the development and testing stage, so I just got a few test accounts first. Click Register Account and this window will pop up. The specific account information can also be found in the Users information folder of the project.
insert image description here


2.4. Personal information interface

Enter the password and click to log in. After success, the personal information interface will pop up.
insert image description hereinsert image description here


2.5. Modification of personal information

Click "Edit Information", the following window will pop up, let's modify it, and then look at the modified personal interface information
insert image description here

Click OK, the modification is successful
insert image description here

I'll change it back


2.6. Chat interface

Click the ENTER blue button to enter the chat interface
insert image description here


2.7. Test input

try typing
insert image description here


2.8. Multi-person online login chat

Then how to implement multi-person online chat, next I will demonstrate the steps. In fact, there is a difference between IDEs here. If you use eclipse, Run as can directly run the main program of Lemon_Action.java again and open another running window without closing the previous running window, but Idea can’t , if it runs directly, it will restart the project by default, which is not very good. In fact, there are ways to open multiple running windows. Next, I will use Idea and eclipse to open multiple running windows to realize multi-threaded multi-person online chat Function.

  • Idea Demo

1) First of all, we need to set up multi-window, click Edit Configuration... to set
insert image description here

2) According to the existing configuration of this running window, we will add two new ones to demonstrate three people chatting online at the same time
insert image description here
insert image description here
insert image description here
insert image description here

In this way, we have added two new running windows.

2) Select the window to start running
insert image description here

Note: This project requires each account to log in successfully before opening a new thread to log in to the next user. It is absolutely not allowed to open multiple login interface windows at the same time! ! ! ! The principle of starting the server is not explained here. If you accidentally open multiple running windows and run them at once, an error will be reported in the background. You need to close all threads and modify the configuration before it can run again. If you modify the configuration, I will talk about it later.

3) Open the second running window to log in to the account
insert image description here
insert image description here
insert image description here

ok, now we have two accounts

3) Open the third running window to log in to the third account
insert image description here
insert image description here

4) Open three chat windows for chatting
insert image description here

  • eclipse demo

By default, eclipse will open a new window, so there is no need to configure it

1) Open the first running window
insert image description here

2) Open the second running window

Run the same Run as ——> Java application
insert image description here

2) Open the third running window
insert image description here

The following demonstration is the same, so I won't demonstrate it again.


3. Description of project directory

insert image description here

src: code directory

Files:

​ IdAndPassword: The startup status of the account, the initialization is false, if you encounter startup problems, just initialize all values ​​to false.

​ID: account number and password

Users information: the information folder of each account


4. Notes on project use

  • When opening multi-person chat, be sure to run mian one by one. After successful login on the login interface, start the next one. This involves the startup judgment of the TCP service, and the function display of the previous account status. If you accidentally open multiple login interfaces at one time, please close all running windows, modify the configuration of the IdAndPassword file, and reset all values ​​to false.
  • In the process of using the program of this project, it is necessary to maintain the normal operation of closing the program. That is to say, if you want to log out, you need to click the close button in the upper right corner. You cannot directly terminate the running of the program, otherwise the startup status of the server will be wrong, and everyone understands it , It is impossible for you as a customer to directly shut down the server. If you still do this, please reset the IdAndPassword configuration file.

Feeling a little bit emotional, I actually admired me at that time. I didn’t know that I could do it, but I still worked hard to do it. Therefore, it is not easy to do something that is not absolutely sure. If you work hard and do it with a little confidence, you may still fail, but no matter what, you will want to make your life more valuable.


5. Essay

insert image description here

Guess you like

Origin blog.csdn.net/m0_48489737/article/details/127820435