Java Swing O Reilly // (Free php web host) Save the state
Wednesday, September 26th, 2007Java Swing O Reilly // Save the state of the app by storing the current state of the threebuttons. // We’ll use the buttons themselves as keys and their selected state asvalues. public void storeState(Hashtable ht) { ht.put(tog, new Boolean(tog.isSelected())); ht.put(cb, new Boolean(cb.isSelected())); ht.put(radio, new Boolean(radio.isSelected())); } // Restore state based on the values we saved when storeState() was called. // Note that StateEdit discards any state info that did not change frombetween // the start state and the end state, so we can’t assume that the state for all // 3 buttons is in the Hashtable. public void restoreState(Hashtable ht) { Boolean b1 = (Boolean)ht.get(tog); if (b1 != null) tog.setSelected(b1.booleanValue()); Boolean b2 = (Boolean)ht.get(cb); if (b2 != null) cb.setSelected(b2.booleanValue()); Boolean b3 = (Boolean)ht.get(radio); if (b3 != null) radio.setSelected(b3.booleanValue()); } private JToggleButton tog; private JCheckBox cb; private JRadioButton radio; private JButton undoButton; private JButton redoButton; private JButton startButton; private JButton endButton; private StateEdit edit; // Main program just creates the frame and displays it. public static void main(String[] args) { JFrame f = new UndoableToggleApp4(); f.addWindowListener(new BasicWindowMonitor()); f.setVisible(true); } } Note that we could have used whatever keys and values we needed to store the current state in the storeState() method. In this example, an easy strategy was to use the button itself as the key and a Boolean to hold the value. There are no restrictions on the keys and values you choose, as long as they are Objects and the storeState() and restoreState() methods are implemented to use the same keys. - 570 -
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.