Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Listening for Changes to Preference Values in a Preference Node

                         

In this section you will learn how to access the user's node and retrieve the stored information in the class. Here we are going to make it easier to understand by the complete example on this topic here we illustrate all the methods used in this example and also explain that what are the uses of them so be attentive on all the step for fully trained in preferences.

In this section you will see about the way of the access user's preference node and and retrieving all information for the appropriate node. Here an example is also provided for learning about the topic in detailed form with line by line explanation.

First of all we import a package for using it's classes and methods which are not accessible by default. For using specific class we have to import it's package i.e. as follows:

import java.util.prefs.*;

The second step is in the main part we use the NodeChangeListener by definition "A listener which is for receiving preference node change events". In The given code line we are using the NodeChangeListenr and also make a object of that and then after adding new we make a constructer and the we define the next two part of the program. 

NodeChangeListener nodeChangeListener = new NodeChangeListener()

 They are work in there separate manner the descriptions of them is as under first of them is the childAdded(NodeChangeEvent event) and by the definition It is the method which gets called when a child node is added .

childAdded(NodeChangeEvent event)

As we earlier mention that the two part of the Node change listener have two method and they are work in there separate manner the descriptions of them is as under Second of them is the childRemoved(NodeChangeEvent event) and by the definition It is the method which gets called when a child node is removed .

childRemoved(NodeChangeEvent event)

In above assumptions, both have the event which is a parameter and by definition "It is A node change event object describing the parent and child node".

Preferences parent = event.getParent();

Preferences child  = event.getChild();

In the above lines of the code getparent() and getchild() are method used to gets the parent items that contains the collection and the same work done by the getchild() method.

Retrieving a Preference Node:
                                                    

Preferences prefs = Preferences.userRoot().node("roseindia");

In the same example we can easily understand that how a Preference node can be access using a class object or a string and the string used to access a preference node is called path and same as a file path. In the given example the root node of the class is define that is why here it is access by the absolute path. There are so many way to access or retrieve the root of the reference node. All of them are define as under while one of them are simply show in our example.
There are also the two type of the Preference node first is the System Preference nodes and the second is the User Preference nodes and there many different method to retrieve the nodes are as under --

  //  System Preference nodes
    
    // Retrieve method of Using a Class
    Preferences prefs = Preferences.systemNodeForPackage(
java.lang.String.class);
    
    // Retrieve method of Using an absolute path
    prefs = Preferences.systemRoot().node(
"/java/lang/String");
    
    //  Retrieve method of Using a relative path
    prefs = Preferences.systemRoot().node(
"/javax/swing");
    prefs = prefs.node(
"text/html");
    
    // User preference nodes
    
    // Retrieve method of Using a class
    prefs = Preferences.userNodeForPackage(
roseindia.MyClass.class);
    
    // Retrieve method of Using an absolute path
    prefs = Preferences.userRoot().node(
"roseindia");
    
    // Retrieve method of Using a relative path
    prefs = Preferences.userRoot().node(
"/javax/swing");
    prefs = prefs.node(
"doc/html");

All of the above mention method of the retrieving of the node either it is related to the user node or it is related to the system root it can be access by the same process and you can easily know that what is the procedure of that method for work.

Here is the complete code of the program:

import java.util.prefs.*;
public class Prefs
  {
  public static void main(String args[]) 
    {
    String employee[] {"HR""Programmer""Team Leadere"};
    String post[] {"Deepak""Amit""Chandan"};
    NodeChangeListener nodeChangeListener = new NodeChangeListener()
    {
        public void childAdded(NodeChangeEvent event) {
          Preferences parent = event.getParent();
          Preferences child  = event.getChild();
         }
       public void childRemoved(NodeChangeEvent event
       {
          Preferences parent = event.getParent();
          Preferences child  = event.getChild();
       }
    };
    PreferenceChangeListener preferenceChangeListener = new PreferenceChangeListener() 
    {
        public void preferenceChange(PreferenceChangeEvent event
      {
          String key = event.getKey();
          String value = event.getNewValue();
          Preferences node = event.getNode();
          System.out.println(node.name() " company has a employee named " + value + " As a " + key);
      }
        };
    // Here is the user root define
      Preferences prefs = Preferences.userRoot().node("roseindia");
    // Here we are just add the listeners
    prefs.addNodeChangeListener(nodeChangeListener);
    prefs.addPreferenceChangeListener(preferenceChangeListener);
    // Save a bunch of key-value pairs
    for (int i=0, n=employee.length; i < n; i++) {
      prefs.put(employee[i], post[i]);
    }

   }
}

After thoroughly knowing the code you should save the file by "Prefs.java" file name and when after compiling the code you run your program you will get the output given below .

Here is the Output of the program:


C:\anshu>javac prefs.java

C:\anshu>java prefs
roseindia company has a employee named Deepak As a HR
C:\anshu>

Downoload this example.

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Latest Searches:
Java Count Vowels
compare two arraylist
jsp pdf
JSP Cookies Example
Display Data from Data
java registration form
Button method
File Separator
Nested loops for JAVA
PHP Database Related C
rules to use java coll
Combattons la programm
inserting select box m
driving
file upload in jsp
message box display in
File Upload
pst.setInt()
identify html items
applet message frame
struts2 checkbox
dwr reverse ajax
public void actionPerf
Building a Simple EJB
date class
netbeans jsp jdbc
modity
facesmessage
login session servlet
diff between struts1.1
standered jar to downl
hast table
jsps in flex
excel style sheet
java for loops
init
how to use unique cons
java string
code for simple calcul
jsp MENU SELECT MAKES
Retrieving Data From d
jtree cellrenderer
adding label and textb
java registration form
socket_create php
how to pass same varia
TCP
Gimp Tutorials
KeyListener
Tuning garbage collect
passing values from js
IVR
hashset
write to text file ret
clear values from a fo
read space character f
radio button using tld
saving a file in a fol
table j2me
java: read string arra
authentication and aut
array list
java bean array
retrive data from data
spring applicationcont
extracting day from da
Java Count words,reve
Javascript Date and Ti
timer
caching in hibernate
getter setter methods
XML READER
Photoshop tutorial : A
Photoshop Web Layouts
Java GUI example
Photoshop Drawing Drag
textfield method
Array in Java
Visual Basic Networkin
design patterns
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.