Geertjan's Blog

  • August 4, 2005

Unjumble That Anagram!

Geertjan Wielenga
Product Manager
To illustrate how J2SE projects work in NetBeans IDE, an Anagram Game is included as a sample in the New Project wizard. This is what it looks like:

When you work through the NetBeans Anagram Game Plug-in Tutorial, you learn how to make the Anagram Game available as a NetBeans plug-in. However, whether or not you have the game available as a plug-in, at some point you want to try it out... only to find that your brain is too tiny to unscramble the anagram. The mentally challenged shouldn't worry too much, though -- this handy web service is freely available to help you out:


So, it seems that someone has taken the trouble to create an application that unjumbles anagrams! And they've made it available as a web service! Lucky you. So quickly use the IDE's Web Service Client wizard and literally within seconds you see the following in the Projects window:

This view shows you that the web service makes two operations available. The first (letterSolutions) unscrambles the anagram and provides all possible unjumbled words -- so if the anagram has 10 letters, all words found within the anagram are returned, right down to "an" and "a". You might be more discerning, however, and so you want to specify the minimum number of letters that each returned word should have. In that case, you'd use the second (letterSolutionsMin). This is my contribution to the client's code, in the servlet's processRequest method (all the rest -- including, especially, the code that connects the client to the web service -- is done automatically by the IDE):

 String anagram = request.getParameter("anagram");
String number = request.getParameter("number");
int intNumber = Integer.parseInt(number);
String[] s = getCountCheatServiceSoap().letterSolutionsMin(anagram,intNumber).getString();
for (int i = 0; i < s.length; i++) {
out.println("<font color='red'>"+s[i]+"</font>");

And this is the index.jsp that I created for the user's input (click to enlarge):

So now I paste in "batsartcoin" (which is the first anagram you get in the IDE's Anagram Game), I specify the minimum number of letters that each returned word should have, I click "Cheat!" -- and then many things happen behind the scenes: the values entered in the JSP are received by the servlet, sent to the web service, handled by the web service, and the words matching the input are returned to the servlet which presents them on the client side -- and here's the result (click to enlarge):

Now I paste the returned word into the IDE's Anagram Game and click "Guess". And this is the result:

So, web services are pretty cool -- all the more so when you can create the client as easily as you can with NetBeans IDE 4.1. Thanks Rico, Peter, Martin, et al!

Join the discussion

Comments ( 1 )
  • kylie Monday, December 17, 2007


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.