Ep.8: Text History - Network Chat Programming

The Cherno · Intermediate ·12y ago

Key Takeaways

The video demonstrates how to use JTextArea to send data to a GUI console window and append strings, as well as network chat programming concepts using Java and Yarn.

Full Transcript

hey what's up guys My Name Is AO and welcome to episode 8 of network chat programming so last time which was a while ago we left off with having this pretty cool window here where the user could enter their name you know an IP address so like Local Host for example and a port like 8192 for example like we have here then they could hit the login button and uh presumably you know the client logs in and they're traded with this window um and today we're going to talk about a few things we're probably going to um talk about actually passing this data into actual login thing so you can see that we pass it in here but um we'll more or less talk about that a bit further and also um first thing I want to fix up here is uh this request Focus thing like um you know what happens is when we kind of launch this application and we log in you know whatever Yan Local Host 8192 then we hit log in like the user can't type straight away right there's no focus on this um and it's pretty easy to actually request Focus after we hit the set visible true okay straight after that we we actually have to type the component we want so text message is the name of our um text field and uh request uh focus in window okay that's the proper way to do it request focus is a bit on it it it works but it's more or less platform dependent might not work for all circumstances and this also will not request Focus to the window just the component in the window so if you minimize or something it's not going to um appear at you and harass you so Cho Local Host 8192 if we hit log in what we should see is as you can see the window is straight away uh the message Windows is available for us to type straight away so cool um now let's talk about how we can get the send button right now or when the user hits enter how we can actually get that to post something into this text history because this is a text history in fact what we want to have here is a way to write to this as like a console okay so we might want to display a message being like blah blah blah logged in at this time or connection successful or connection failed or connection retrying you know what I mean like a console kind of window so the user knows what's going on um so let's talk about doing that now so what we have is this awesome text history which is a j text area and we need a function here in our client uh. Java class now remember client. Java is more or less a um it's it's our window okay it's not actually probably going to contain any of the um the code to actually send messages and receive messages and stuff it's probably just going to be there um for the purpose of playing our window as a graphical interface um and because of that all of our methods that actually write to the console should be here um so we'll just make a public method here um a public void we'll call it um uh let's say client dot we could call it console okay um and this would be like a right line kind of um print line to the console thing um and then we'll print whatever we want so string message or string text um and then what we want to do here is simply type text uh area I think it's called text history dot um that's not it okay it is it it's just not Global so make sure we take the text area here and we actually um let's copy that and then let's get rid of the text area here and then we'll paste what we just copied into the top here so private and then jxt area text history that will make it Global first class uh which is good here and make sure it's private because we don't need to be accessing it from anywhere else so text history Dot come on give me some oh there we go oh it's text R history why is it text R history anyway um guess cuz it's a text area I don't know why we called it that but anyway um text area. append uh and then our message okay um now what this will do is append whatever we want into the um into the actual console so let's test that out real quick when we do create this um and this is in the create window thing here um what we want to do is let's just type in uh text r history dot um no hang on we just made a method for that uh let's type in console and then we can um type in something like successfully connected you know even though we don't know if it's successfully connected or not let's just type that in anyway so again we'll go Yan Local Host 8192 hit log in and you can see that it says successfully connected now and that's really cool now what happens if we try to do that again okay what if we do two lines so console and then let's do another line and we'll call it uh successfully disconnected I don't know just for fun um let's hit up uh that hit log in okay you can see it's on the same line not cool right we want we want everything to be on the on a different line um so how can we do that well if we go down over here um after append we can actually add in fact I'm not sure if a pend will actually have anything to do with that no it doesn't have anything in the Java doc but um if if we actually append to this message literally here if we just type in plus and then back slash uh n back SL r that will actually give us I was just thinking n is n is new line right n is new line in consoles R is um more or less kind of the same thing but if we try that out and we type in Yan Local Host 8192 what we should get is as you can see them on separate lines and that is pretty cool you probably don't need both of them there SL n/r not quite sure that sln would work I know SLR will but you know have both of them there for safety um so now we've got a way to write stuff to the console okay um and that's pretty that's pretty cool okay so um that's probably going to wrap up this episode what we're doing as well which is actually um kind of important here is we're actually setting whatever our name is into these variables so what I could do is in fact let's do this quickly um so uh we could we could do something like um attempting a attempting a connection uh with um and then we could add the name here at uh um hang on no so attempting connection with like yarn or something that doesn't really sound right does it um attempting a connection for whatever um no hang on I am scroll up the English part of this aren't I um what sounds good so attempting attempting a connection I guess two and then our server which is address at H we could probably do uh just a column there Plus Port um plus you know user and then plus our name here okay and I guess that would look more or less correct here make sure we have a plus here as well Okay cool so if we run this and we go Yan Local Host uh 8192 then what we should get is as you can see over here so attempting a connection to Local Host a192 um use a yarn okay that's it um and that basically just demonstrates that we actually have the ability to uh do this stuff now one thing one other thing I want to cover because this episode's kind of short and and I know you guys want to see content every time we uh ex we basically hit the send button we want to grab the everything we got in fact I might actually sa that for the later episode because it is a bit more involved because we want stuff like um the an key to work but um what we'll cover next episode probably is this um this text this text message history kind of thing I think it's just called text message but um this this field right let me just make sure you guys can see that this text field okay um because we essentially want people to be able to type in like hi and then hit enter we don't want them to be we don't want them to hit send like they can obviously if they want to but um we want them to be able to hit enter so we'll cover keyboard uh listening into this field next time so so I hope you guys enjoyed this episode of network chat programming if you did please hit the like button again same as with game programming series if this hits 200 likes I'll release one video per day not of this series just one video per day in general of either the game programming or the network chat programming series uh if it hits two likes then I'll release uh two videos per day most likely one of each okay so make sure you hit that like button if you guys did enjoy this video later guys [Music]

Original Description

200 likes = 1 video per day, 300 likes = 2 videos per day! ------------------------------------------------------------------------------------------------- In this video: - How to use JTextArea - How to send data to a GUI console window - How to append strings ------------------------------------------------------------------------------------------------- Website: http://www.thecherno.com Twitter: http://www.twitter.com/thecherno Facebook: http://www.facebook.com/thecherno Subreddit: http://www.reddit.com/r/thecherno/ Steam Group: http://www.steamcommunity.com/groups/thecherno ------------------------------------------------------------------------------------------------- Outro music is by Approaching Nirvana: http://www.youtube.com/approachingnirvana
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from The Cherno · The Cherno · 0 of 60

← Previous Next →
1 3D Game Programming - Episode 1 - Window
3D Game Programming - Episode 1 - Window
The Cherno
2 3D Game Programming - Episode 2 - Game Loop
3D Game Programming - Episode 2 - Game Loop
The Cherno
3 3D Game Programming - Episode 3 - Arrays
3D Game Programming - Episode 3 - Arrays
The Cherno
4 3D Game Programming - Episode 4 - Drawing Pixels!
3D Game Programming - Episode 4 - Drawing Pixels!
The Cherno
5 3D Game Programming - Episode 4.5 - How Rendering Works
3D Game Programming - Episode 4.5 - How Rendering Works
The Cherno
6 3D Game Programming - Episode 5 - Playing with Pixels!
3D Game Programming - Episode 5 - Playing with Pixels!
The Cherno
7 3D Game Programming - Episode 6 - Performance Boosting
3D Game Programming - Episode 6 - Performance Boosting
The Cherno
8 3D Game Programming - Episode 7 - FPS Counter
3D Game Programming - Episode 7 - FPS Counter
The Cherno
9 3D Game Programming - Episode 8 - Alpha Support and More
3D Game Programming - Episode 8 - Alpha Support and More
The Cherno
10 3D Game Programming - Episode 9 - Beginning 3D
3D Game Programming - Episode 9 - Beginning 3D
The Cherno
11 3D Game Programming - Episode 10 - Floors and Animation
3D Game Programming - Episode 10 - Floors and Animation
The Cherno
12 3D Game Programming - Episode 11 - Rotation
3D Game Programming - Episode 11 - Rotation
The Cherno
13 3D Game Programming - Episode 12 - User Input
3D Game Programming - Episode 12 - User Input
The Cherno
14 3D Game Programming - Episode 13 - Render Distance Limiter!
3D Game Programming - Episode 13 - Render Distance Limiter!
The Cherno
15 3D Game Programming - Episode 14 - Basic Mouse Movement
3D Game Programming - Episode 14 - Basic Mouse Movement
The Cherno
16 3D Game Programming - Episode 15 - Textures + More!
3D Game Programming - Episode 15 - Textures + More!
The Cherno
17 3D Game Programming - Episode 16 - Walking, Crouching, Sprinting + More
3D Game Programming - Episode 16 - Walking, Crouching, Sprinting + More
The Cherno
18 3D Game Programming - Episode 16.5 - Exporting Runnable Jars
3D Game Programming - Episode 16.5 - Exporting Runnable Jars
The Cherno
19 3D Game Programming - Episode 17 - Small Adjustments + Birthday!
3D Game Programming - Episode 17 - Small Adjustments + Birthday!
The Cherno
20 3D Game Programming - Episode 17.5 - Creating an Applet
3D Game Programming - Episode 17.5 - Creating an Applet
The Cherno
21 3D Game Programming - Episode 18 - The Beginning of Walls
3D Game Programming - Episode 18 - The Beginning of Walls
The Cherno
22 3D Game Programming - Episode 18.1 - A Few More Things
3D Game Programming - Episode 18.1 - A Few More Things
The Cherno
23 Episode 18.5 - Creating an EXE File in Java
Episode 18.5 - Creating an EXE File in Java
The Cherno
24 3D Game Programming - Episode 19 - Rendering Walls
3D Game Programming - Episode 19 - Rendering Walls
The Cherno
25 3D Game Programming - Episode 20 - Continuing Walls, Fixing Bugs, and Managing Crashes
3D Game Programming - Episode 20 - Continuing Walls, Fixing Bugs, and Managing Crashes
The Cherno
26 3D Game Programming - Episode 21 - Texturing Walls, Fixing Clipping, and Fixing the Mouse
3D Game Programming - Episode 21 - Texturing Walls, Fixing Clipping, and Fixing the Mouse
The Cherno
27 3D Game Programming - Episode 22 - Random Level Generator + Properly Fixing Clipping
3D Game Programming - Episode 22 - Random Level Generator + Properly Fixing Clipping
The Cherno
28 3D Game Programming - Episode 23 - Graphical User Interface (GUI) Launcher
3D Game Programming - Episode 23 - Graphical User Interface (GUI) Launcher
The Cherno
29 3D Game Programming - Episode 24 - Making Our Launcher Work
3D Game Programming - Episode 24 - Making Our Launcher Work
The Cherno
30 3D Game Programming - Episode 25 - Writing and Reading Files
3D Game Programming - Episode 25 - Writing and Reading Files
The Cherno
31 3D Game Programming - Episode 26 - Custom Resolutions
3D Game Programming - Episode 26 - Custom Resolutions
The Cherno
32 3D Game Programming - Episode 27 - Decorating the Launcher
3D Game Programming - Episode 27 - Decorating the Launcher
The Cherno
33 3D Game Programming - Episode 28 - Continuing our Custom Launcher!
3D Game Programming - Episode 28 - Continuing our Custom Launcher!
The Cherno
34 3D Game Programming - Episode 29 - Launching The Game
3D Game Programming - Episode 29 - Launching The Game
The Cherno
35 3D Game Programming - Episode 30 - Colour Processing In-Depth
3D Game Programming - Episode 30 - Colour Processing In-Depth
The Cherno
36 3D Game Programming - Episode 31 - Sprites!
3D Game Programming - Episode 31 - Sprites!
The Cherno
37 3D Game Programming - Episode 32 - Sprite Mapping
3D Game Programming - Episode 32 - Sprite Mapping
The Cherno
38 3D Game Programming - Episode 33 - High Resolution Rendering
3D Game Programming - Episode 33 - High Resolution Rendering
The Cherno
39 3D Game Programming - Episode 34 - Entities
3D Game Programming - Episode 34 - Entities
The Cherno
40 Genesis - My Game for Ludum Dare 24
Genesis - My Game for Ludum Dare 24
The Cherno
41 Vlog + Ludum Dare Results
Vlog + Ludum Dare Results
The Cherno
42 Game Programming - Episode 1 - Resolution
Game Programming - Episode 1 - Resolution
The Cherno
43 Game Programming - Episode 2 - Threads
Game Programming - Episode 2 - Threads
The Cherno
44 Game Programming - Episode 3 - Game Loop
Game Programming - Episode 3 - Game Loop
The Cherno
45 Game Programming - Episode 4 - Window
Game Programming - Episode 4 - Window
The Cherno
46 Episode 5 - Buffer Strategy
Episode 5 - Buffer Strategy
The Cherno
47 Game Programming - Episode 6 - Graphics Initialized
Game Programming - Episode 6 - Graphics Initialized
The Cherno
48 Game Programming - Episode 7 - Buffered Image and Rasters
Game Programming - Episode 7 - Buffered Image and Rasters
The Cherno
49 Game Programming - Episode 8 - The Screen Class
Game Programming - Episode 8 - The Screen Class
The Cherno
50 Game Programming - Episode 9 - Rendering Pixels
Game Programming - Episode 9 - Rendering Pixels
The Cherno
51 Game Programming - Episode 10 - Clearing the Screen
Game Programming - Episode 10 - Clearing the Screen
The Cherno
52 Game Programming - Episode 11 - "Out of Bounds, Baby!"
Game Programming - Episode 11 - "Out of Bounds, Baby!"
The Cherno
53 Game Programming - Episode 12 - Negative Bounds
Game Programming - Episode 12 - Negative Bounds
The Cherno
54 Game Programming - Episode 13 - Timer
Game Programming - Episode 13 - Timer
The Cherno
55 Game Programming - Episode 14 - FPS Counter
Game Programming - Episode 14 - FPS Counter
The Cherno
56 Episode 15 - Tiles
Episode 15 - Tiles
The Cherno
57 Game Programming - Episode 16 - The Map
Game Programming - Episode 16 - The Map
The Cherno
58 The Walls 2 - Minecraft PvP Survival Map
The Walls 2 - Minecraft PvP Survival Map
The Cherno
59 Game Programming - Episode 17 - Key Input
Game Programming - Episode 17 - Key Input
The Cherno
60 Game Programming - Episode 18 - Controlling The Map
Game Programming - Episode 18 - Controlling The Map
The Cherno

This video teaches how to use JTextArea to send data to a GUI console window and append strings, as well as network chat programming concepts using Java and Yarn. It covers topics such as text history, console output, and ui design. By watching this video, viewers can learn how to design a GUI console window, implement text history using JTextArea, and use Java and Yarn for network chat programming.

Key Takeaways
  1. Request focus on the text field component
  2. Append message to the text history using JTextArea append method
  3. Append messages to the console
  4. Add a new line using
  5. Set variables for name and server address
  6. Demonstrate a connection to Local Host 8192 using Yarn
💡 Using JTextArea to append messages to the console and implementing keyboard listening to allow users to hit enter instead of send can enhance the user experience of a network chat program.
Up next
George Hotz | Programming | tinygrad, starting on CLOUD=1 | Part 2
george hotz archive
Watch →