89 90 /** 91 * The index of the current choice for this <code>Choice</code> 92 * or -1 if nothing is selected. 93 * @serial 94 * @see #getSelectedItem() 95 * @see #select(int) 96 */ 97 int selectedIndex = -1; 98 99 transient ItemListener itemListener; 100 101 private static final String base = "choice"; 102 private static int nameCounter = 0; 103 104 /* 105 * JDK 1.1 serialVersionUID 106 */ 107 private static final long serialVersionUID = -4075310674757313071L; 108 109 /** 110 * Creates a new choice menu. The menu initially has no items in it. 111 * <p> 112 * By default, the first item added to the choice menu becomes the 113 * selected item, until a different selection is made by the user 114 * by calling one of the <code>select</code> methods. 115 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 116 * returns true 117 * @see java.awt.GraphicsEnvironment#isHeadless 118 * @see #select(int) 119 * @see #select(java.lang.String) 120 */ 121 public Choice() throws HeadlessException { 122 GraphicsEnvironment.checkHeadless(); 123 pItems = new Vector(); 124 } 125 126 /** 127 * Constructs a name for this component. Called by 128 * <code>getName</code> when the name is <code>null</code>. 694 * @see #writeObject(ObjectOutputStream) 695 */ 696 private void readObject(ObjectInputStream s) 697 throws ClassNotFoundException, IOException, HeadlessException 698 { 699 GraphicsEnvironment.checkHeadless(); 700 s.defaultReadObject(); 701 702 Object keyOrNull; 703 while(null != (keyOrNull = s.readObject())) { 704 String key = ((String)keyOrNull).intern(); 705 706 if (itemListenerK == key) 707 addItemListener((ItemListener)(s.readObject())); 708 709 else // skip value for unrecognized key 710 s.readObject(); 711 } 712 } 713 714 715 ///////////////// 716 // Accessibility support 717 //////////////// 718 719 720 /** 721 * Gets the <code>AccessibleContext</code> associated with this 722 * <code>Choice</code>. For <code>Choice</code> components, 723 * the <code>AccessibleContext</code> takes the form of an 724 * <code>AccessibleAWTChoice</code>. A new <code>AccessibleAWTChoice</code> 725 * instance is created if necessary. 726 * 727 * @return an <code>AccessibleAWTChoice</code> that serves as the 728 * <code>AccessibleContext</code> of this <code>Choice</code> 729 * @since 1.3 730 */ 731 public AccessibleContext getAccessibleContext() { 732 if (accessibleContext == null) { 733 accessibleContext = new AccessibleAWTChoice(); | 89 90 /** 91 * The index of the current choice for this <code>Choice</code> 92 * or -1 if nothing is selected. 93 * @serial 94 * @see #getSelectedItem() 95 * @see #select(int) 96 */ 97 int selectedIndex = -1; 98 99 transient ItemListener itemListener; 100 101 private static final String base = "choice"; 102 private static int nameCounter = 0; 103 104 /* 105 * JDK 1.1 serialVersionUID 106 */ 107 private static final long serialVersionUID = -4075310674757313071L; 108 109 static { 110 /* ensure that the necessary native libraries are loaded */ 111 Toolkit.loadLibraries(); 112 /* initialize JNI field and method ids */ 113 if (!GraphicsEnvironment.isHeadless()) { 114 initIDs(); 115 } 116 } 117 118 /** 119 * Creates a new choice menu. The menu initially has no items in it. 120 * <p> 121 * By default, the first item added to the choice menu becomes the 122 * selected item, until a different selection is made by the user 123 * by calling one of the <code>select</code> methods. 124 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 125 * returns true 126 * @see java.awt.GraphicsEnvironment#isHeadless 127 * @see #select(int) 128 * @see #select(java.lang.String) 129 */ 130 public Choice() throws HeadlessException { 131 GraphicsEnvironment.checkHeadless(); 132 pItems = new Vector(); 133 } 134 135 /** 136 * Constructs a name for this component. Called by 137 * <code>getName</code> when the name is <code>null</code>. 703 * @see #writeObject(ObjectOutputStream) 704 */ 705 private void readObject(ObjectInputStream s) 706 throws ClassNotFoundException, IOException, HeadlessException 707 { 708 GraphicsEnvironment.checkHeadless(); 709 s.defaultReadObject(); 710 711 Object keyOrNull; 712 while(null != (keyOrNull = s.readObject())) { 713 String key = ((String)keyOrNull).intern(); 714 715 if (itemListenerK == key) 716 addItemListener((ItemListener)(s.readObject())); 717 718 else // skip value for unrecognized key 719 s.readObject(); 720 } 721 } 722 723 /** 724 * Initialize JNI field and method IDs 725 */ 726 private static native void initIDs(); 727 728 ///////////////// 729 // Accessibility support 730 //////////////// 731 732 733 /** 734 * Gets the <code>AccessibleContext</code> associated with this 735 * <code>Choice</code>. For <code>Choice</code> components, 736 * the <code>AccessibleContext</code> takes the form of an 737 * <code>AccessibleAWTChoice</code>. A new <code>AccessibleAWTChoice</code> 738 * instance is created if necessary. 739 * 740 * @return an <code>AccessibleAWTChoice</code> that serves as the 741 * <code>AccessibleContext</code> of this <code>Choice</code> 742 * @since 1.3 743 */ 744 public AccessibleContext getAccessibleContext() { 745 if (accessibleContext == null) { 746 accessibleContext = new AccessibleAWTChoice(); |