Kongzi Beta 7 Milestone 6

I’ve been working on Kongzi a lot recently. There are THREE major new features.

1. Mix and match now works again (although I suppose it always needs more testing).

2. Kongzi now supports split dictionary and user files. That means if you are running a class (versus studying on your own) each student can have their own profile but the dictionary data can be edited in one place. VERY convenient.

And 3.. perhaps the most interesting, most-discussed, and most debated feature regarding this program.. well.. what is it? Well let me introduce it to you. Recall the Browse Entries screen from previous versions; here I am showing the Chinese-English dictionary highlighting some vocabulary from the BLI system:

Image

Now, there’s a secret key; Select some entries (as many as you wish) and press F2:

Image

I’ve removed the window title to build suspense, but there is a clue in this image as to what I am working on. Are you ready to see this? It’s so awesome.. scroll down:

Image

Ahh, there it is! Kongzi’s FULLY INTEGRATED, FULLY DEBUGGED spaced repetition flashcard system!

It works off the dictionary so it’s completely configurable in every way all the quizzes are. I use it to teach myself Chinese and Japanese, and I use it to teach my students English. You can even configure your hints. I’ve included one more shot of a standard Chinese – Pinyin – English setup below; this is what you might see after clicking the “hint” button twice:

Image

Wow, I can’t tell you how proud I am of this system! It took Kongzi in a fresh direction and brought me back to working on the project big time. Although I must say, that the dual savefile structure was more difficult (in the sense that I had to keep track of a very large number of things at one time).

All in all, the dual savefile structure was really necessary for classroom instruction. That’s the biggest bit of info which came out of the recent 6 month beta test. And, oddly enough, it was sort of required for the SRS system because the SRS system would only be useful for one “user”.

So, now we’re at 0.7.6. The only thing left for Beta-8 is to add Audio quizzing. I’m a little unsure of how I should do this. There will be audio only quizzing which will repeat the word twice, but due to audio issues I may also include a “replay audio” button. That is, i’ve noticed audio issues in a lot of similar programs on a wide variety of computers, so I want to get that done right before I release it too.

beyond that, what else? A text analyzer, full-script cloze generator, and some sort of guide/helper would all be great but I think they are not going to be necessary to make a release-quality program. So after the audio (which itself might be thrown out and I’ll just release with the current set of features)… Working on those textbooks is now a big priority.

Okay so I am kind of rambling here, bouncing ideas off the wall, so that will be my decision. then. I’ll do a feature freeze now, put Kongzi back into another 2 months of beta testing to test the split savefile system and the SRS system in the classroom. I’ll work on the textbooks and stick to that June release schedule.

This is going to be a big release for me. I am very happy about this program!

If you’d like to be in the next beta test or you’d like to make any comments or suggestions, please, comment! Tell me what you want in a program like this. It’s going to be the best! Gotta be the best! ^^

Advertisements

Styling a Pop-Up Confirmation Dialog and Forcing Focus in Java

This is really Concurrent Programming in Java part II. So consider it part of that post.

Anyways I needed a pop up confirmation box which had a styled entry field. This isn’t possible in normal Java but I am going to show you how to do it anyways. First, why? Because I need the confirmation box entry field to be styled, and I need it to request focus. Unfortunately since I was adding the entryField myself (to get it styled, since I couldn’t figure out how to access the one that comes with Swing) Java wouldn’t autofocus to it. After a lot of hacking around I felt this wasn’t possible normally. So here’s what I did to get it done:

JTextField entryField = new JTextField(); // global so it's in the same scope as popUpConf and it's thread.
public String popUpConf(String title, String msg) {
        entryField.setText("");
        entryField.setFont(Kongzi.ForeignFontBE);

        // create a thread to wait until the dialog box pops up.
        (new Thread() {
            public void run() {
                // Sleep long enough for the window to pop up.....
                try {
                    // a half second should be fine...
                    this.sleep(500);
                } catch (Exception e) {
                    // not required
                }
                // request focus.
                entryField.requestFocus();
            }
        }).start();

        Object[] message = new Object[]{msg, entryField};
        JOptionPane.showConfirmDialog(mainFrame, message, title,
                JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.PLAIN_MESSAGE);

        // return the string.
        String s = entryField.getText();
        return s;
    }

In retrospect I probably should have used entryField.isShowing() and/or entryField.isVisible() to determine when I should request focus. Perhaps a short while loop with a small sleep value (50 or 100). Maybe I’ll go fix that now. But so far I’ve never had it barf on me. The only “error” is that it wouldn’t get focus, I suppose, which would be annoying but not unbearable.

Ok so that’s how you can set the font on a pop up confirmation box’s entry field. Cool, huh?

Concurrent Programming in Java

Perhaps the biggest problem facing concurrent programming today is the ‘herding of cats’ required to force programmers to adopt concurrent programming models. That, and concurrent programming is plain old difficult.

However, there are winds in the air that modern CPU architecture will finally force us to use concurrent programming. As it turns out, these winds are what has propelled good programmers all along; the desire to write a program that runs well on current hardware. To avoid bloat. To be efficient. And small.

As Java programmers, and more loosely as object oriented programmers, the desire to be re-usable (as OO programmers) and the desire to show that Java is superior (let’s face it, it is) similarly propels us to do our best to embody the principles of OO programming.

So let’s get to the point. Java doesn’t have an easy way to do Threads. You have to make all these complex checks and balances and it’s just a big bother, isn’t it? Plus, if you do design or think about program flow, it’s all too easy to visualize program flow as a straight line. A = 1, B = 2, A + B = 3. No one thinks about setting A and B at the same time. Why? Besides not perceiving a need (due to outdated, single-core hardware), one answer could be speed.

Setting A and B might take less than a handful of nanoseconds on a fast computer, but starting a new thread takes time. On my i7 system, I timed the creation-to-execution time and main program impact of 1 million threads. Every time I created a thread it cost my program about 35 milliseconds. Additionally, each thread began executing approximately 18 milliseconds after it was created. Obviously, creating a thread just to add two numbers at the same time is a waste of CPU time. Secondarily, you would need to wait for both threads to finish executing before you added the numbers. So all-in-all, calculating when you should use concurrent programming is a really big headache.

Incidentally this is also why the “sufficiently smart compiler” will never exist; calculating execution time can’t be done in advance. CPUs might be slower or faster, it’s based on real-time and not on some variable which can be known ahead of time.

So what do we know?

a) Concurrent Programming takes a small amount of time to set up (around 50 milliseconds on an i7, on average).
b) It’s easiest to use for small, independent, “fire and forget” tasks that don’t need to be synchronized with the main program.

Have any lightbulbs flashed yet? Well, let me tell you a story.

I was writing code on my Kongzi project, and it kept crashing in the UI thread, which locked up the program itself. I had to open task manager to close it which was a pain. I realized that I was committing a mortal sin of the UI world; I was doing extensive processing in the UI thread. The user would click a button, and the UI thread would fire the button event, which would take the software on a merry romp through CPU land. This was unacceptable, but I didn’t realize I was doing it. Later on, had I put the code into production, the UI would have seemed unresponsive and sluggish under more stressful “normal” use conditions.

So I decided to use a new thread to process the data and “return” immediately. After all, clicking the button just tells the program what to do. We don’t need to freeze up the UI thread each time.

It turned out to be a genius idea. I created a method like this:

// This function does whatever you want -- in a thread!
public void doWhatever()
{
        (new Thread() {
                public void run() {
                        // Thread Code Goes Here
                }
        }).start();
 // return immediately!
        return;
}

Now notably, such a method can’t return any data (but it can modify global variables), since it does everything in a thread. But it’s perfect for updating status labels, for auto-saving, for printing, for doing any kind of complex task that you don’t want to do in the UI thread. One example can be logging. If you need to institute extensive logging, using a method like the above will return in about 35 miliseconds. No I/O time will be added to the main program. There are surely many applications for this in gaming as well; adding a thread which changes the status of an object over time, and exits on it’s own after a predictable length of time, is an easy way to code simple physics like gravity. Say, for a mario-world/2d platform game. Shots from a spaceship, for example, could be controlled by a thread. This would clean up your game loop considerably.

Now, you normally wouldn’t want to create one thread for each force vector on an object, for example, because 35 miliseconds of game loop time is a lot; that would be only about 30 “shots” which could be fired, or 30 objects created, forces applied, etc. per second. This could have disastrous effects on a program which requires 60fps or higher. Never fear; Have a monitor thread that creates threads for you! If it’s backlocked, it can clone itself and work twice as fast. What it does is monitor a queue and create threads. So you just “list.add(“object name”); for example, and the little helper threads go crazy doing their little thing. It all seems so simple now! The only problem would be locking the list so only one helper thread can pull a value off of it at a time. That’s not really a problem. Use the volatile keyword. “public int”? “public volatile int”! No problem. Use a synchronized block of code. Use a SynchronizedList. No problem! The point is that it will take far less than 35 miliseconds to add data to a list and pull it off again. This kind of simple messaging will help you return values from methods which run in threads as shown above.

In short, threads aren’t really that difficult or time consuming. They can really help. And sometimes they’re even required to achieve certain effects.

I’ll be able to post some more specific examples of this in a bit. Right now, I have to go to work. Sayounara!

Kongzi Beta-8 announced for June

Okay. Kongzi Beta-7 has been in classroom-use testing for about 6 months now and it seems pretty solid. A lot of changes have gone on under the hood. It’s using a database for the main type of save files now and you can merge (import) data from other files without destroying your user info. This will be tuned as time goes by, but as of now it is solid for general use.

Image

All the quizzes have gotten a swift kick up in power, they now don’t just present random items but will sometimes present items which are similar to the correct answer. To do this I have created an engine which analyzes the user’s expected knowledge level and searches for similar words .This works in any language and with sentences (shown below) as well as with words (shown above).

Another thing which I’ve done is add the list of test mistakes to the score screen for easy studying. The following example is from the dictionary I use to teach “Let’s Talk in English” to Chinese students.

Image

Once I give the manual a once-over and double check a few features on my to-do list, I’m going to have to start looking at how to package this beast.

For one, I plan to blow away the competition by offering a companion textbook with preloaded vocabulary. The MCI Chinese project (see the navbar up top) isn’t dead at all and has actually expanded with sister projects such as MCI Japanese and so forth. Here are some shots of the MCI Japanese book, “Welcome to Japanese”:

Image

Image

Image

Image

As you can probably guess I’m really excited to have reached this point in the Kongzi project and I will be able to package and offer these materials to YOU (well, to anyone) very soon. Target is this summer, around June for a complete Chinese/Japanese/Korean package which will take you from step one to “fluency”.

Thank you for keeping patient all these years. The wait has been difficult for me, too! But it is almost ready now, for real!

One step at a time..

An old draft from September 2009…

In just a few short days I seem to have come far enough that I am regaining my confidence working on this project.

I’ve re-integrated all the old logic back into the forms and re-created the “kong” and “ze” graphics from the calligraphy work I had done before. I’ve also identified several key areas which could be improved. For example, Beta-3 had a selective export feature. I asked myself, why was this necessary? If someone wanted to selectively export something they could just delete the stuff they didn’t want and then save it. So, this seems to make more sense, just save everything at once.

I also found and fixed a bug in my unicode encoder-decoder ring. Additionally I’ve completed the new export dialog design and as soon as I hook it up I can delete the old code for exporting tags and what not.

There’s just one problem. I don’t know what look and feel I was using. You can see a blue tint on the screenshots. I like that. And I can’t remember what I was doing. Ungh. I’ll figure it out later. Top priority is getting the anki/stackz-style flashcards up and running.

One step at a time… I’ve been reminded why I’ve been so successful with Kongzi so far. One step at a time, keep chewing away…