Alvin Alexander | Java, Scala, Unix, Perl, Mac OS X

Here's some sample code that demonstrates how to use the Java JOptionPane showConfirmDialog method. I've included the method call in the context of a real containing method (doExitAction()) so you can see how it might be used in real-world code.

Here's another one of those postings that are just here to help my bad memory. I currently travel a fair amount, work on different systems and projects, and can't remember the Java syntax for adding a Java ActionListener to a JButton, so here's a little sample code to help me remember:

This isn't the most high-tech way to do things, but I thought I'd share these Windows (DOS) shell scripts that I'm currently using to compile a Java application, create a Jar file to distribute the application, and finally run the application. I ended up creating these scripts because of configuration problems on my Windows PC, but I thought they might be useful samples for others.

Here's a "Java clipboard" method I use when writing a Java/Swing program that needs to place plain text (a String) on the system clipboard:

Earlier tonight I installed JRuby on a Windows XP system, and it was about as easy as anything I've installed. Here were the steps on my computer:

You know what will really screw with your mind? When there is a 1.4.2 version of a java.exe file in the C:\Windows\System32 directory of your Windows XP system, and you're trying to compile and run a Java 1.5 program from the command line. I kept getting this error message and couldn't figure it out, even though I knew what it meant(!):

This is just my second JRuby program, but I thought I might as well go for the gusto. This Ruby/JRuby program creates an instance of a Java Robot class (java.awt.Robot), then moves the mouse to a position where it clicks the Minimize button on a full-screen window (assuming a display resolution of 1024x768). Warning: if you have something else in that location it will click that instead!

Here's the Ruby/JRuby code:

Nothing too major today, I just wanted to note this site that features stylized line drawings. I like this form of art, and didn't want to forget the name/type, as well as this artist.


(Note: This article was originally written in 2005.) As far as design goes, products like the Mac, TextMate, and JFormDesigner have really opened my eyes to the possibilities of great design, and it's impact on people (I was going to say "users", but that say more inhuman than ever before), and my personal feelings about using these products. At the moment I don't really ever want to go back to using a Windows PC ever again, in spite of the few things I don't like about Mac OS X.

After a fairly large number of emails I've started working on my type-ahead, predictive text editor project. In support of this effort I'm looking at different algorithms to best predict the word the user next wants to type. The first part of this is looking at documents I've written in the past, and analyzing the frequency of word occurrences within those documents.

I recently needed to print the information in a Ruby hash, with the results sorted by value. Here's a general recipe on how to print the hash results sorted by value. I've created a sample hash, and populated the hash with sample data, to show how this works.

First, here's the sample code, using the first name of each person as the key, and the last name as the value of the key/value pair:

There are a lot of commands for navigating through a file with the vi editor (or, more recently, the vim editor), but the reality is that I've used various forms of Unix (Ultrix, AIX, CLIX, SCO Unix, etc.), Linux, and more recently Mac OS X, and there are only a few vi commands that I use for moving around in a file.

So I thought I'd list those here, the most common vi commands.

In a heavy day of JFormDesigner use, I just learned how to create a JComboBox in a column in a JTable, using only JFormDesigner.

First, create your JTable in JFormDesigner. I'll skip the details here, hoping that process is easy enough. Then, click the ellipsis button for the model property in the Properties list. This brings up the JTable model editor.

I just learned how to create a ButtonGroup using JFormDesigner, and it's pretty easy and pretty cool.

First, add all the related buttons you want on your JFormDesigner form. Next, click all the buttons while holding down the [Control] or [Apple] key, depending on your platform, so the all the buttons are selected at one time. Then right-click one of the buttons, then select the "Group Buttons" option from the popup menu.

I just noticed that you can set the preferred size of a column in a JTable using JFormDesigner. If you're looking at a JTable in the normal JFormDesigner view, click the ellipsis button for the model property in the Properties list. This brings up the JTable model editor.

Next, click a cell in the column you want to modify. Then on the bottom-right of this dialog you'll see a few fields labeled "Pref. Width", "Min. Width", and "Max. Width". Just type in a value you want for the preferred width of your column.

AppleScript iTunes search FAQ: How do I search for an iTunes song using AppleScript?

AppleScript iTunes song search and play example

I'm not sure if the following AppleScript example is the best way to search for an iTunes song and then play that song using AppleScript, but it is one way that I discovered recently while working on my AppleScript alarm clock application.

AppleScript iTunes FAQ: Can you demonstrate an AppleScript iTunes example (such as an AppleScript iTunes alarm clock)?

For a little while now I've been creating an AppleScript iTunes alarm clock application (an AppleScript alarm that would work with iTunes). The basic idea of the application was to do the following:

AppleScript time subroutine FAQ: Can you share an example of an AppleScript subroutine (function) that returns te current time?

Here's an example AppleScript subroutine (also known as a function or method) that returns the current time as hours and minutes, along with the AM/PM modifier. For the purposes of creating an alarm clock AppleScript program, I didn't like the default format of the AppleScript current date command, so I use this method to extract the current time information I want.

Still reading Calculus Made Easy, they note that 'e' (the natural logarithm, or natural log) is the limit of the following series:

1 + 1/1! + 1/2! + 1/3! ...

To test this I created the following Ruby natural log program.

AppleScript result output FAQ: How can I display the output of my AppleScript script (the AppleScript result)?

Cool, I just learned how to get AppleScript output to show up in the ScriptEditor Result tab. In short, just leave a string at the end of your AppleScript script, and it is printed in the ScriptEditor Result tab.

ScriptEditor Result output: An AppleScript output "Hello world" example

Here's a quick AppleScript result example that puts "Hello world" in the ScriptEditor Result tab: