Viewing Contact Information


The UserInfo.java file creates the user interface that allows end users to view the contact information of the selected end user from the tree structure of the Contact List application. Listing 7-8 shows the contents of the UserInfo.java file:

Listing 7-8: The UserInfo.java File

start example
 /*Import required javax.swing classes*/ import javax.swing.*; /*Import required java.awt classes*/ import java.awt.*; /*Import required java.awt.event. classes*/ import java.awt.event.*; /* class UserInfo - This class is used to show user profile which, is selected in the roster tree. Constructor: UserInfo-This constructor creates GUI. Methods: setInfo: This method is used to show user information text into labels. */ public class UserInfo extends JDialog  implements ActionListener {    /*Declares object of Container class.*/    Container container;    /*Declares objects of JLabel class.*/    JLabel heading= null;    JLabel userid = null;    JLabel nickname = null;    JLabel email = null;    JLabel phone = null;    JLabel address = null;    JLabel useriddata = null;    JLabel nicknamedata = null;    JLabel emaildata = null;    JLabel phonedata = null;    JLabel addressdata = null;    /*Declares objects of String class.*/    String vcardxml;    String fname="";    String nname="";    String addressinfo="";    String telnumber="";    /*Declares object of JButton class.*/    JButton okbutton;    public UserInfo()    {       container = this.getContentPane();       /*Declares and initializes the object of JPanel class.*/       JPanel toppanel = new JPanel();       setTitle("Contact Information");       /*Declares and initializes the objects of JLabel class.*/       heading = new JLabel("Contact Information");       userid = new JLabel("User Id:");       nickname = new JLabel("User Name:");       email=new JLabel("Email:");       phone=new JLabel("Phone:");       address=new JLabel("Address:");       useriddata=new JLabel("");       nicknamedata=new JLabel("");       emaildata=new JLabel();       phonedata=new JLabel("");       addressdata=new JLabel("");       /*Declares and initializes the objects of JButton class.*/       okbutton=new JButton("OK");       /*Sets the font of the heading.*/       heading.setFont(new Font("Verdana", Font.BOLD, 12));       /*Adds heading to the toppanel.*/       toppanel.add(heading);       container.add(toppanel,BorderLayout.NORTH);         /*Declares and initializes the objects of JPanel class.*/       JPanel userinfopanel = new JPanel(new GridLayout(5, 6, 10, 20));       /*Adds userid to the userinfopanel.*/       userinfopanel.add(userid);       /*Sets the font of the useriddata.*/       useriddata.setFont(new Font("Verdana", Font.BOLD, 10));       /*Adds useriddata to the userinfopanel.*/       userinfopanel.add(useriddata);       /*Adds nickname to the userinfopanel.*/       userinfopanel.add(nickname);       /*Sets the font of the nicknamedata.*/       nicknamedata.setFont(new Font("Verdana", Font.BOLD, 10));       /*Adds nicknamedata to the userinfopanel.*/       userinfopanel.add(nicknamedata);       /*Adds email to the userinfopanel.*/       userinfopanel.add(email);       /*Sets the font of the emaildata.*/       emaildata.setFont(new Font("Verdana", Font.BOLD,10));       /*Adds emaildata to the userinfopanel.*/       userinfopanel.add(emaildata);       /*Adds phone to the userinfopanel.*/       userinfopanel.add(phone);       /*Sets the font of the phonedata.*/       phonedata.setFont(new Font("Verdana", Font.BOLD, 10));       /*Adds phonedata to the userinfopanel.*/       userinfopanel.add(phonedata);       /*Adds address to the userinfopanel.*/       userinfopanel.add(address);       /*Sets the font of the addressdata.*/       addressdata.setFont(new Font("Verdana",Font.BOLD,10));       /*Adds addressdata to the userinfopanel.*/       userinfopanel.add(addressdata);       container.add(userinfopanel);       /*Declares and initializes the objects of JPanel class.*/       JPanel buttonpanel = new JPanel();       buttonpanel.add(okbutton);       okbutton.addActionListener(this);       container.add(buttonpanel,BorderLayout.SOUTH);       setSize(350,300);       setVisible(true);    }    /*    setInfo: This method is used to show user information text into labels.    Parameter: vcardString - Object of String class, nicknameto - Object of String class,     UserID - Object of String class    Return Value: String    */    public void setInfo(String vcardString,String nicknameto,String UserID)    {       vcardxml=vcardString;       fname=vcardxml.substring(vcardxml.indexOf("<FN>")+4,vcardxml.indexOf("</FN>"));       nname=vcardxml.substring(vcardxml.indexOf("<NICKNAME>")+10,vcardxml.indexOf       ("</NICKNAME>"));       if ((vcardxml.indexOf("<HOME/>")==-1)&&(vcardxml.indexOf("</HOME>")!=-1))       {          telnumber=vcardxml.substring(vcardxml.indexOf("<HOME>")+6,vcardxml.indexOf          ("</HOME>"))+"\n";       }       if ((vcardxml.indexOf("<LOCALITY/>")==-1)&&(vcardxml.indexOf       ("</LOCALITY>")!=-1))       {          addressinfo=addressinfo+vcardxml.substring(vcardxml.indexOf("<LOCALITY>")+10,          vcardxml.indexOf("</LOCALITY>"));       }       if ((vcardxml.indexOf("<LOCALITY/>")==-1)&&       (vcardxml.indexOf ("</LOCALITY>")!=-1))       {          addressinfo=addressinfo+vcardxml.substring(vcardxml.indexOf("<LOCALITY>")+10,          vcardxml.indexOf("</LOCALITY>"));       }       useriddata.setText(UserID.substring(1,UserID.length()-1));        nicknamedata.setText(nname);       addressdata.setText(addressinfo);       phonedata.setText(telnumber);    }    public void actionPerformed(ActionEvent ae)    {       if(ae.getSource() == okbutton)       {          this.dispose();       }    } } 
end example

Download this listing.

In the above code, the constructor of the UserInfo class creates the user interface to view the contact information of the selected end user.

The methods defined in Listing 7-8 are:

  • setInfo(): Shows the contact information text of the selected end user.

  • actionPerformed(): Acts as an event listener and activates an appropriate method based on the action the end user performs.

The UserInfo.java file creates the user interface that allows an end user to view the contact information of the selected end user, as shown in Figure 7-8:

this figure shows the user interface to view the contact information, which includes user id, user name, address, phone number, and e-mail of the selected end user.
Figure 7-8: The Contact Information Window




Developing Applications Using Jabber
Developing Applications Using Jabber
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 68

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net