PDA

View Full Version : ذخیره وضعیت نرم افزار preference



jeus
یک شنبه 26 خرداد 1387, 08:38 صبح
دوستان من از preference برای ذخیره یک value در registery استفاده کردم توی سایتها من پیدا کردم که کجا ذخیره میکنه HKEY_CURRENT_USER\Software\JavaSoft\Prefs
اما از منو جای دیگه ای ذخیره میکنه HKEY_CURRENT_USER\Software\JavaSoft\Prefs\com\ociw eb\preferencestest
وقتی هم که میخواهم از متد get استفاده کنم error میده
لطفا راهنماییم کنید
ممنون
راستی کدم هم اینه
/*
* ali.java
*
* Created on June 14, 2008, 3:30 AM
*/
package com.ociweb.preferencestest;



import java.util.prefs.*;
import javax.swing.JFrame;
/**
*
* @author khat_farda
*/
public class ali extends javax.swing.JFrame {
private Preferences myPreferences ;

public static final String formTitle = "Form_Title";
/** Creates new form ali */
public ali() {
super("Preferences Test Window");
initComponents1();
settitleform();
myPreferences = Preferences.userNodeForPackage(getClass());
}

private void settitleform()
{
int formdef = myPreferences.getInt(formTitle,100);
setTitle(formdef+"");
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
setTitle("Salam Man Allan Baz Shodam ");
addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseExited(java.awt.event.MouseEvent evt) {
formMouseExited(evt);
}
});
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosed(java.awt.event.WindowEvent evt) {
formWindowClosed(evt);
}
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});

jButton1.setText("Man Mitavanam");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jButton2.setText("Man Khaham Tavanest ");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jButton3.setText("Talash Moghadameye pirozi");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

jButton4.setText("Shekast Rah omidvari ");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
.addComponent(jButton4)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_S IZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
.addContainerGap(23, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jButton3)
.addComponent(jButton4))
.addGap(20, 20, 20))
);

pack();
}// </editor-fold>

private void initComponents1() {

jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);

addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosed(java.awt.event.WindowEvent evt) {
formWindowClosed(evt);
}
});

jButton1.setText("Man Mitavanam");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jButton2.setText("Man Khaham Tavanest ");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("Talash Moghadameye pirozi");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

jButton4.setText("Shekast Rah omidvari ");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
.addComponent(jButton4)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_S IZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
.addContainerGap(23, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jButton3)
.addComponent(jButton4))
.addGap(20, 20, 20))

);
pack();
}


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
setTitle(jButton1.getText());
myPreferences.putInt(formTitle,100);
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
setTitle(jButton2.getText());
myPreferences.put(formTitle,getTitle());
}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
setTitle(jButton3.getText());
myPreferences.put(formTitle,getTitle());
}

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
setTitle(jButton4.getText());
myPreferences.put(formTitle,getTitle());
}

private void formWindowClosed(java.awt.event.WindowEvent evt) {
myPreferences.put("Closing","Baste Shod");
}

private void formWindowClosing(java.awt.event.WindowEvent evt) {
myPreferences.put("Closing","Baste Shod");
}

private void formMouseExited(java.awt.event.MouseEvent evt) {
myPreferences.put("Closing","Baste Shod");
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ali().setVisible(true);

}
});
}


// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
// End of variables declaration

}

jeus
یک شنبه 26 خرداد 1387, 11:00 صبح
دوستان مشکلم حل شد میگم حواس پرتم هیچکس باور نمیکنه من اول این متد اجرا مشد
mypreference.get("name",Def) و بعد از preference رفرنس میگرفتم این گیج بازی 6 ساعت وقت منو گرفت:عصبانی: