Wednesday, 19 October 2011

Java: Completing the Text Editor Functionality II

As per the comments a couple days ago: Yes, we absolutely can get to simple games, but to do that, we need to learn about threads! So I'll do that right after this text editor is done! I suppose turn based games require it less, but still.

Okay, let's get to finishing this thing. Since load() was just a version of reading files, it follows that save will be a similar version of saving (durr) them. Keep in mind that our finished project will be very rudimentary, and you'll probably still be better off using notepad and stuff, but its still functional, right?
I changed a line in the code for load, when initializing the JFileChooser. It is identical to the initialized JFileChooser in the following:

Okay, first, note the bottom 3 methods. They were hilariously easy. Too bad I didn't know they existed and went around for an hour looking for a way to do it :D

Now look back up to save! The JFileChooser is the same as yesterday's, but with a parameter. This parameter just tells the program to look in the users current directory. Should make stuff easier, in a lot of cases! Then we have the standard if-else block to check for approval or cancellation.
TL;DR: Shit's the same standard style as before.

The save functionality itself is just the writing to file stuff we did before. Seriously, I went back in my posts and found the Writing to a File one, and more or less copied it into the try block. And uh...that's it! Hooray! Now all that's left to do is double click the buttons in the design tab, and add functionality to them:

....That was easy! Granted, to make a better text editor (This is simple, even compared to freaking Notepad) would take more and more time. The closer you get to perfection, the more work it takes to get a little bit better. Think of it like grades in school. It's easy to get a 50% (Mostly? I assume so for my target audience, at least), a few times as hard to get a 75%, which is only 1.5x the grade, and nigh impossible to get a 100%

But hey, the program is MORE OR LESS done. I won't provide source code today, but only because I'd like to spend one more day doing stuff to this. It'll involve menu bars, and a "New" method. But after that, we're moving onto threads, so we can design simple games!

Questions welcome! Comments, too!  Follow, subscribe, share etc, and see you tomorrow!

And as part of a shameless plug for a friend, if you're interested in classic movies/books/music, visit his site here (fixed), and feel free to throw loads of criticism at us. 


  1. im studing engieneer, java will be a subjcet next year so tihs is very helpfull..thanks bud :)

  2. Good stuff man, pretty well explained as always.

  3. Nice one! With all these tips I'm finally starting to learn all the ins and outs of Minecraft.

  4. So you basically made everything more efficient.


  5. wow thats a lot of code, im just learning c, so ill be coming here when i move on to java.