Java Operations Registry

Source: Internet
Author: User
Tags gettext

public class Register {Log a map message to the registrypublic void Recordregistration (map<string,string>entry) throws backingstoreexception{If the choice is systemnode ... is saved in [hkey_local_machine\software\javasoft\prefs]//Preferences pre = Preferences.systemnodeforpackage (registration        Op.class); If the choice is usernode ....        Then save in [Hkey_current_user\software\javasoft\prefs] Preferences pre = Preferences.usernodeforpackage (Register.class); You can also import an XML in the form of a stream//preferences.importpreferences (IS);if (entry!=null) {Set<string> Keys=entry.keyset ();Iterator<string> Its=keys.iterator ();while (Its.hasnext ()) {String Key=its.next ();String Value=entry.get (key);Pre.put (Key,value);}}Pre.flush ();}Query whether there is information logged in the registrypublic string Findinfo (string key) {Preferences now=preferences.usernodeforpackage (Register.class);String result=now.get (key, NULL);return result;}Delete the information for the corresponding key in the registrypublic void Delinfo (String key) {Preferences now =preferences.usernodeforpackage (Register.class);Now.remove (key);}}


public class QQ {Register rg=new Register ();public String user;Public String pwd;protected shell shell;private text text;Private Text text_1;
public static void Main (string[] args) {try {QQ window = new QQ ();window.open ();} catch (Exception e) {E.printstacktrace ();}}
public void Open () {Display display = Display.getdefault ();Createcontents ();Shell.open ();Shell.layout ();while (!shell.isdisposed ()) {if (!display.readanddispatch ()) {Display.sleep ();}}}
protected void createcontents () {Shell = new Shell ();Shell.setsize (450, 300);Shell.settext ("SWT application");Shell.setlayout (SWT. New Filllayout. horizontal));Composite Composite = new Composite (Shell, SWT. NONE);Label label = new label (composite, SWT. NONE);Label.setbounds (29, 28, 61, 17);Label.settext ("\u8d26\u53f7\uff1a");Label Label_1 = new label (composite, SWT. NONE);Label_1.setbounds (29, 92, 61, 17);Label_1.settext ("\u5bc6\u7801\uff1a");Text = new text (composite, SWT. BORDER);Text.setbounds (97, 25, 170, 23);text_1 = new Text (composite, SWT. BORDER | Swt. PASSWORD);Text_1.setbounds (97, 89, 170, 23);Final button button = New button (composite, SWT. CHECK);Button.setbounds (33, 163, 98, 17);Button.settext ("\u8bb0\u4f4f\u5bc6\u7801");Button button_1 = New button (composite, SWT. NONE);Button_1.setbounds (187, 158, 80, 27);Button_1.settext ("\u767b\u9646");String loginname=rg.findinfo ("user");String loingpwd=rg.findinfo ("pwd");To determine if a login exists in the registryif (loginname!=null&&! "". Equals (LoginName)) {Text.settext (Rg.findinfo ("user"));if (loingpwd!=null&&! "". Equals (LOINGPWD)) {//If the user exists, the user's password is readText_1.settext (Rg.findinfo ("pwd"));}}Button.setselection (TRUE);Login EventsButton_1.addselectionlistener (New Selectionadapter () {@Overridepublic void widgetselected (Selectionevent e) {Map<string,string> mapuser=new hashmap<string,string> ();Map<string,string> mappwd=new hashmap<string,string> ();String Uname=text.gettext (). toString (). Trim ();String Upwd=text_1.gettext (). toString (). Trim ();if (uname==null| | "". Equals (uname)) {ShowMessage ("User name cannot be empty ...");Text.setfocus ();Return}if (upwd==null| | "". Equals (Upwd)) {ShowMessage ("Password cannot be empty ...");Text_1.setfocus ();Return}Mapuser.put ("User", uname);Mappwd.put ("pwd", upwd);String str=rg.findinfo ("user");if (Button.getselection () ==true) {//If the user chooses to save the password, write to the registryif (str==null| | Str.length () ==0) {//If the user key corresponds to a value of NULLtry {Rg.recordregistration (Mapuser); Writing to the RegistryRg.recordregistration (MAPPWD);} catch (Backingstoreexception E1) {E1.printstacktrace ();}Shell.close ();Login l=new login ();L.open ();}else{Rg.delinfo ("user");Rg.delinfo ("pwd");try {Rg.recordregistration (Mapuser);Rg.recordregistration (MAPPWD);} catch (Backingstoreexception E2) {E2.printstacktrace ();}Shell.close ();Login l=new login ();L.open ();}}}});}public void ShowMessage (String message) {MessageBox mb=new MessageBox (SHELL,SWT. NONE);Mb.settext ("error Prompt");Mb.setmessage (message);Mb.open ();}}

Java Operations Registry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.