Components Types of Components Button Canvas Checkbox Choice Label List Scrollbar TextComponent TextArea TextField Button Button constructs a Button with no text Button String constructs a Button with the specified text void addActionListener ActionListener void removeActionListener ActionListener String getLabel void setLabel String String actionEvent getActionCommand A Button listener button addActionListener new MyButtonListener class MyButtonListener implements ActionListener public void actionPerformed ActionEvent event showStatus Button clicked Label constructors Label constructs a Label with no text Label String constructs a Label with the specified text Label String int constructs a label with the specified text and alignment Label LEFT Label RIGHT Label CENTER Label methods String getText void setText String int getAlignment void setAlignment int Scrollbar constructors Scrollbar creates a vertical Scrollbar Scrollbar int orientation Scrollbar HORIZONTAL or Scrollbar VERTICAL Scrollbar int orientation int initialValue int bubbleSize int minimum int maximum bubbleSize size of the bubble sometimes called elevator min value of Scrollbar minimum max value of Scrollbar maximum bubbleSize value of scrollbar is given by left or top edge of bubble initialValue the initial position setting of the bubble Scrollbars bubbleSi ze minimu m The units for bubbleSize are the same as those for minimum and maximum maximu m maximum bubbleSize Scrollbar methods void addAdjustmentListener AdjustmentListener void removeAdjustmentListener AdjustmentListener int getMinimum void setMinimum int int getMaximum void setMaximum int int getValue void setValue int A Scrollbar listener scrollbar addAdjustmentListener new MyScrollbarListener class MyScrollbarListener implements AdjustmentListener public void adjustmentValueChanged AdjustmentEvent event showStatus Scrollbar scrollbar getValue Checkbox constructors Checkbox Checkbox String Checkbox String boolean Checkbox String boolean CheckboxGroup Checkbox String CheckboxGroup boolean Checkbox methods void addItemListener ItemListener void removeItemListener ItemListener CheckboxGroup getCheckboxGroup void setCheckboxGroup CheckboxGroup String getLabel void setLabel String A Checkbox listener checkbox addItemListener new MyCheckboxListener class MyCheckboxListener implements ItemListener public void itemStateChanged ItemEvent event showStatus Checkbox status is now event getStateChange ItemEvent SELECTED CheckboxGroup methods Checkbox getSelectedCheckbox Suggested use myCG getSelectedCheckbox getLab el void setSelectedCheckbox Checkbox A CheckboxGroup listener No such thing listen to individual Checkboxes checkbox1 addItemListener myCheckboxGroupListener checkbox2 addItemListener myCheckboxGroupListener class MyCheckboxGroupListener implements ItemListener public void itemStateChanged ItemEvent event Checkbox d checkboxGroup getSelectedCheckbox showStatus CheckboxGroup d getLabel Choice constructor Choice After constructing a Choice use add String to add items to it Choice methods addItemListener ItemListener removeItemListener ItemListener void add String void remove String void removeAll String getSelectedItem void select String A Choice listener choice addItemListener new MyChoiceListener class MyChoiceListener implements ItemListener public void itemStateChanged ItemEvent event showStatus Choice choice getSelectedItem List constructors List constructs an empty list List int int the number of items visible a scrollbar is automatically added if needed List int boolean boolean true if multiple selection is allowed List methods I void addItemListener ItemListener void removeItemListener ItemListener void add String void remove String void removeAll List methods II String getSelectedItem String getSelectedItems int getSelectedIndex int getSelectedIndexes void select int can only select by index There are other methods for adding removing etc by index A List listener list addItemListener new MyListListener class MyListListener implements ItemListener public void itemStateChanged ItemEvent event showStatus List list getSelectedItem TextComponent No constructors Instead construct a TextField or TextArea void addTextListener TextListener void removeTextListener TextListener String getText void setText String boolean isEditable void setEditable boolean TextField constructors TextField TextField int int the approximate desired number of columns TextField String String the initial text in the TextField TextField String int TextField methods void addActionListener ActionListener void removeActionListener ActionListener The ActionListener for a TextField responds only when the Enter key is pressed TextArea constructors TextArea TextArea int rows int columns TextArea int rows int columns int scroll TextArea SCROLLBARS VERTICAL ONLY TextArea SCROLLBARS HORIZONTAL ONLY TextArea SCROLLBARS BOTH TextArea SCROLLBARS NONE TextArea String TextArea String int rows int columns TextComponent listeners textField addActionListener new MyTextFieldListeners textField addTextListener new MyTextFieldListeners class MyTextFieldListeners implements ActionListener TextListener public void actionPerformed ActionEvent event showStatus TextField ActionListener textField getText public void textValueChanged TextEvent event showStatus TextField TextListener textField getText Canvas This is a rectangular blank area that you can paint on Constructor Canvas Don t use Canvas directly instead subclass it and override its void paint Graphics method The End
View Full Document
Unlocking...