To Create a Frame with Preferences

In this section you will learn how to use the preferences in frame. The example will make it easier to understand to use the preferences with frame window.

To Create a Frame with Preferences

In this section you will learn how to use the preferences in frame. The example will make it easier to understand to use the preferences with frame window.

To Create a Frame with Preferences

To Create a Frame with Preferences

     

In this section you will learn how to use the preferences in frame. The example will make it easier to understand to use the preferences with frame window. the required package to use the preferences with frame window are java.awt, java.awt.event, javax.swing and java.util.prefs. I the given example we make a preferences object and call it in main.

 

 

Here is the Complete Code of the Example :

 import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

 import java.util.prefs.*;
  
  public class PreferenceTestFrame extends JFrame {
  
  // A reference to Preferences object
  private Preferences myPreferences = null;
  
  public PreferenceTestFrame() {
  super("Preferences Test Window");
  
  // Obtain a references to a Preferences object
  myPreferences = Preferences.userNodeForPackage(this.getClass());
  }
 public static void main(String[] args) {
  JFrame window = new PreferenceTestFrame();
    window.setVisible(true);
    }

  }
  

After thoroughly knowing the code you should save the file by "PreferenceTestFrame.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 Example :

Download this example.