Browse DevX
Sign up for e-mail newsletters from DevX


Build Your Own Messaging Application in Java with jYMSG : Page 3

This new Java API provides you all the necessary functionality to build your own messaging application in conjunction with Yahoo's instant messaging and chat software.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

The Example Application in Action
The sample Swing application for this article (download the code from the link in the left column) is shown in action in Figure 1.

Figure 1. Hello? The sample application uses the jYMSG API to send a message using the YIM protocol.

MySessionListener (the implementation of the SessionListener interface) has its own instance of the YahooClient object, which points to the instance created in the YahooClient class. This linking is how the updateMessagingPanel and handleConnectionClosed, which are designed to react to events received by the SessionListener implementation.

Closing the Swing application triggers a windowClosing event as defined by the WindowListener interface. You then make a call to the ymsg.network.Session object's logout method, which terminates the Yahoo session. The logout method can throw an IllegalStateException or an IOException.

Learn More with the Bundled Examples
This article barely scratches the surface of what the jYMSG API has to offer. The API, though not covering all of YMSG's offerings, does cover the lion's share of it (see project homepage for unsupported features).

This help documentation page is particularly useful for jumpstarting work with the API. For example, you can see the following code, which allows you to print your group and underlying friend's list from your ymsg.network.Session object (ss in the code below):

YahooGroup[] yg = ss.getGroups(); for(int i=0;i<yg.length;i++) { System.out.println(yg[i].getName()); for(int j=0;j<yg[i].size();j++) { YahooUser yu = yg[i].getUserAt(j); System.out.println(" "+yu.toString()); } }

As I tried to learn how to use the jYMSG API, I also found the example source code bundled with the jYMSG source download to be quite helpful. There are a huge number of classes in the ymsg.support package that you can analyze to understand how to use jYMSG to build your own messaging applications that can programmatically interact with Yahoo's messaging and chat services. For example, you might use jYMSG to build an applet on your Web site that visitors can use to interact with your customer service representatives. You might also consider building a jYMSG log4J appender to allow your Java applications to send critical log messages to the appropriate personnel in your organization via a Yahoo instant message.

Author's Note: The author would like to thank, S.E. Morris, the project admin of the jYMSG SourceForge.net project for his review of the conent of this article.

Kulvir Singh Bhogal works as an IBM consultant, devising and implementing J2EE-centric solutions at customer sites across the nation.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date