DOC PREVIEW
Penn CIT 591 - Components

This preview shows page 1-2-14-15-29-30 out of 30 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

ComponentsTypes of ComponentsButtonA Button listenerLabel constructorsLabel methodsScrollbar constructorsScrollbarsScrollbar methodsA Scrollbar listenerCheckbox constructorsCheckbox methodsA Checkbox listenerCheckboxGroup methodsA CheckboxGroup listenerChoice constructorChoice methodsA Choice listenerList constructorsList methods IList methods IIA List listenerTextComponentTextField constructorsTextField methodsTextArea constructorsTextComponent listenersSuggestion: Don’t use text listeners!CanvasThe EndJan 14, 2019Components2 Types of ComponentsButtonCanvasCheckboxChoiceLabelListScrollbarTextComponentTextAreaTextField3Buttonnew Button() constructs a Button with no textnew Button(String) constructs a Button with the specified textvoid addActionListener(ActionListener)void removeActionListener(ActionListener)String getLabel()void setLabel(String)String actionEvent.getActionCommand()Returns the “action command” associated with this ButtonBy default, the action command = the text on the Button4A Button listener button.addActionListener (new MyButtonListener ()); class MyButtonListener implements ActionListener { public void actionPerformed (ActionEvent event) { showStatus ("Button clicked."); }}5Label constructorsnew Label() constructs a Label with no textnew Label(String) constructs a Label with the specified textnew Label(String, alignment) constructs a label with the specified text and alignment:Label.LEFTLabel.RIGHTLabel.CENTER(These are int constants defined in the Label class)6Label methodsString getText()void setText(String)int getAlignment()void setAlignment(int)7Scrollbar constructorsnew Scrollbar() creates a vertical Scrollbarnew Scrollbar(int orientation)Scrollbar.HORIZONTAL or Scrollbar.VERTICALnew 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 bubble8ScrollbarsbubbleSizemaximummaximum — bubbleSizeminimumThe units for bubbleSize are the same as those for minimum and maximumThe scrollbar reading is takenfrom the left edge of the bubble9Scrollbar methodsvoid addAdjustmentListener(AdjustmentListener)void removeAdjustmentListener(AdjustmentListener)int getMinimum()void setMinimum(int)int getMaximum()void setMaximum(int)int getValue()void setValue(int)10A Scrollbar listenerscrollbar.addAdjustmentListener(new MyScrollbarListener ()); class MyScrollbarListener implements AdjustmentListener { public void adjustmentValueChanged (AdjustmentEvent event) { showStatus ("Scrollbar: " + scrollbar.getValue ()); }};11Checkbox constructorsnew Checkbox()new Checkbox(String)new Checkbox(String, boolean)new Checkbox(String, boolean, CheckboxGroup)new Checkbox(String, CheckboxGroup, boolean)12Checkbox methodsvoid addItemListener(ItemListener)void removeItemListener(ItemListener)CheckboxGroup getCheckboxGroup()void setCheckboxGroup(CheckboxGroup)String getLabel()void setLabel(String)13A Checkbox listener checkbox.addItemListener (new MyCheckboxListener ()); class MyCheckboxListener implements ItemListener { public void itemStateChanged (ItemEvent event) { showStatus ("Checkbox status is now " + (event.getStateChange () == ItemEvent.SELECTED)); }};14CheckboxGroup methodsCheckbox getSelectedCheckbox()Suggested use:myCG.getSelectedCheckbox().getLabel()void setSelectedCheckbox(Checkbox)15A 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 ()); }}16Choice constructornew Choice()After constructing a Choice, use add(String) to add items to it17Choice methodsaddItemListener(ItemListener)removeItemListener(ItemListener)void add (String)void remove(String)void removeAll()String getSelectedItem()void select(String)18 A Choice listener choice.addItemListener (new MyChoiceListener ()); class MyChoiceListener implements ItemListener { public void itemStateChanged (ItemEvent event) { showStatus ("Choice: " + choice.getSelectedItem ()); }};19List constructorsnew List() constructs an empty listnew List(int)int: the number of items visible (a scrollbar is automatically added if needed)new List(int, boolean)boolean: true if multiple selection is allowed20List methods Ivoid addItemListener(ItemListener)void removeItemListener(ItemListener)void add(String)void remove(String)void removeAll()21List 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 index22A List listener list.addItemListener (new MyListListener ()); class MyListListener implements ItemListener { public void itemStateChanged (ItemEvent event) { showStatus ("List: " + list.getSelectedItem ()); }};23TextComponentNo constructorsInstead, construct a TextField or TextAreavoid addTextListener(TextListener)void removeTextListener(TextListener)String getText()void setText(String)boolean isEditable()void setEditable(boolean)24TextField constructorsnew TextField()new TextField(int)int: the approximate desired number of columnsnew TextField(String)String: the initial text in the TextFieldnew TextField(String, int)25TextField methodsvoid addActionListener(ActionListener)void removeActionListener(ActionListener)The ActionListener for a TextField responds only when the Enter key is pressed26TextArea constructorsnew TextArea()new TextArea(int rows, int columns)new TextArea(int rows, int columns, int scroll)TextArea.SCROLLBARS_VERTICAL_ONLYTextArea.SCROLLBARS_HORIZONTAL_ONLYTextArea.SCROLLBARS_BOTHTextArea.SCROLLBARS_NONEnew TextArea(String)new


View Full Document

Penn CIT 591 - Components

Documents in this Course
Stacks

Stacks

11 pages

Arrays

Arrays

30 pages

Arrays

Arrays

29 pages

Applets

Applets

24 pages

Style

Style

33 pages

JUnit

JUnit

23 pages

Java

Java

32 pages

Access

Access

18 pages

Methods

Methods

29 pages

Arrays

Arrays

32 pages

Methods

Methods

9 pages

Methods

Methods

29 pages

Vectors

Vectors

14 pages

Eclipse

Eclipse

23 pages

Vectors

Vectors

14 pages

Recursion

Recursion

24 pages

Animation

Animation

18 pages

Animation

Animation

18 pages

Static

Static

12 pages

Eclipse

Eclipse

23 pages

JAVA

JAVA

24 pages

Arrays

Arrays

29 pages

Animation

Animation

18 pages

Numbers

Numbers

21 pages

JUnit

JUnit

23 pages

Access

Access

18 pages

Applets

Applets

24 pages

Methods

Methods

30 pages

Buttons

Buttons

20 pages

Java

Java

31 pages

Style

Style

28 pages

Style

Style

28 pages

Load more
Download Components
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Components and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Components 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?