Thursday, 20 October 2011

Java: TEXT EDITOR COMPLETE (sorta)

Woop, well we have everything in place, so the only things left to do are "New" and "Close", put them in a menu bar (along with everything else), and give them shortcuts! After today, we'll start work on Threads, which will allow us, hopefully, to work on some of the simpler games.

An issue I don't feel like working on is when you hit new/close/load, an option to save doesn't come up. Also there's no Save vs. Save As. But that's okay, since I wasn't planning on this replacing Notepad anyway, and its more of a matter of building it than learning anything new.

Here's the new and close methods:




Very, very simple methods, here. So now we move into the design tab, and add a menu bar, which comes with File and Edit automatically. To add items to each menu, drag them in from the Swing menu on the right...


The "Menu" item in between is for another menu, like file/edit. Perhaps "Help", if it weren't such a simple program. Anyway, we can see each menu item has 3 sections, a box on the left, the text and a shortcut button. The latter 2 are self explanatory, the first box, however, is for an image! Y'know, the partially open folder, or the minimize icon, whatever. I won't use these, but they're there if you need 'em.

Keep in mind that double clicking the menu item won't take you to the ActionPerformed() method for that item, it'll just open one of the 3 subsections of the item, so you have to right click and go to events yourself.
TL;DR: Look at the pretty pictures! Put in whatever menu items you want, and check out what the 3 sections do.


After filling in the menu items with names, shortcuts and functionality, I get the following:


It's done! Now, to get something you can either distribute, or just use outside of Netbeans, you'll want to hit either F11 or Shift+F11 (the latter cleans before building). The file is now inside your project directory, under "/dist/". You might get some unsafe warnings, depending on how paranoid your computer protection is, but you built this yourself, so you can tell it to go fuck itself this time.

Here's the entire works, source code and executable (again, under /dist/):

http://www.megaupload.com/?d=RZVY4DW1

And there you have it, a ghetto text editor. So yeah, unless something comes up, tomorrow: THREADS


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. 


7 comments:

  1. this is a great tutorial man, well explained and makes it look easy

    ReplyDelete
  2. Thanks for the source code, makes it so much easier than starting over.

    ReplyDelete
  3. This is getting more interesting everyday!

    ReplyDelete
  4. Interesting tutorial.

    ReplyDelete
  5. Ok, I think I'm going to have to backtrack now and reread some earlier code to understand this better.

    ReplyDelete
  6. Thanks for this! I keep increasing my knowledge!

    ReplyDelete