package jp.gr.java_conf.skrb.prefs; import java.util.prefs.*; import javax.swing.*; import javax.swing.border.*; import java.awt.*; import java.awt.event.*; public class PrefsGUISample3 extends PrefsGUISample1 { public PrefsGUISample3(){ super(); prefs.addPreferenceChangeListener(new PreferenceChangeListener(){ public void preferenceChange(PreferenceChangeEvent event){ String message = "Node: [" + event.getNode() + "] Key: [" + event.getKey() + "] Value: [" + event.getNewValue() + "]"; System.out.println(message); } }); frame.addComponentListener(new ComponentAdapter(){ public void componentMoved(ComponentEvent event){ Rectangle rect = frame.getBounds(); updateLocationX(rect.x); updateLocationY(rect.y); } public void componentResized(ComponentEvent event){ Rectangle rect = frame.getBounds(); updateWidth(rect.width); updateHeight(rect.height); } }); } private void updateLocationX(int x){ locationX = x; prefs.putInt(LOCATION_X, locationX); labelLocationX.setText(String.valueOf(locationX)); } private void updateLocationY(int y){ locationY = y; prefs.putInt(LOCATION_Y, locationY); labelLocationY.setText(String.valueOf(locationY)); } private void updateWidth(int w){ width = w; prefs.putInt(WIDTH, width); labelWidth.setText(String.valueOf(width)); } private void updateHeight(int h){ height = h; prefs.putInt(HEIGHT, height); labelHeight.setText(String.valueOf(height)); } public static void main(String[] args){ new PrefsGUISample3(); } }