AWT Components Table
AWT Components Table
1
5. Choice Choice() String getSelectedItem() ^ index: index of the desired item
(pop-up list which -Creates empty list int getSelectedIndex()^^ ^ If more than one item is selected
shows only currently int getItemCount() or is no selection is made, null is
selected item) void select(int index) returned
(ItemListener) void select(String name) ^^ If more than one item is selected
(Single item displayed String getItem(int index) or is no selection is made, -1 is
with scrollbar arrow) returned
6. List List() void add(String name)* index: index of the desired item
(ActionListener) List(int numRows) void add(String name, int * Item added at the end
throws List(int numRows, boolean index)** ** Item added at the specified index
HeadlessException multipleSelect) String getSelectedItem() or Indexing begins at 0.
All items are displayed. int getSelectedIndex() Index can be -1 to add the item at
May show scrollbar. String[] getSelectedItems() or the end.
Double click int[] getSelectedIndexes() ^
ActionListener int getItemCount() ^^
Single click void select(int index)
ItemListener
7. Scroll Bar ScrollBar() int getValue() Styles: Scrollbar.HORIZONTAL
(AdjustmentListener) ScrollBar(int Style) void setValue(int newValue) Scrollbar.VERTICAL
throws ScrollBar(int Style, int int getMaximum() + Default is 1
HeadlessException initialValue, int thumbsize, int getMinimum() ++Default is 10
int min, int max) void setUnitIncrement(int new
incr)+
void setBlockIncrement(int new
incr)++
8. TextField TextField() String getText() @returns true if the text may be
(ActionListener, TextField(String str) void setText(String str) changed
TextListener) TextField(int numchars) String getSelectedText() @@ If canEdit is true, text may be
throws TextField(String str, int void select(int startindex, int changed. If false, text cannot be
HeadlessException numchars) endindex) altered
boolean isEditable()@
2
void setEditable(Boolean @@@ To check if echo char has
canEdit)@@ been set for the textfield
void setEchochar(char c)
boolean echoCharIsSet()@@@
char getEchoChar()
3
14 MenuItem MenuItem() void setEnabled(Boolean
(ActionListener) MenuItem(String enabledFlag)
itemName) if enabledFlag is true,
MenuItem(String menuItem is enabled, otherwise
itemName, it is disabled
MenuShortcutkey Accel)) boolean isEnabled()
void setLabel()
15 CheckboxMenuItem CheckboxMenuItem() Checkable entry is unchecked.
(ItemListener) CheckboxMenuItem(String
itemName)
CheckboxMenuItem(String
itemName, Boolean on)) If on is true, checkable entry is
initially checked.
16 Dialog Dialog(Frame parentWindow is the owner of When modal dialog box is active, all
parentWindow, boolean the dialog box, Mode can be input is directed to it until it is
mode) modal or modal or modeless. closed.
Dialog(Frame When modeless dialog box is active,
parentWindow, boolean input focus can be directed to
mode, Boolean mode) another window in your program.
17 FileDialog FileDialog(Frame parent, String getdirectory() If how is FileDialog.LOAD, box is
String boxName) String getFile() selecting the file for reading, If how
FileDialog(Frame parent, is FileDialog.SAVE, box is selecting
String boxName, int how) the file for writing,
FileDialog(Frame parent)
4
compRef is a reference to an instance of the control that you want to add. A reference to the object is returned. Once a control has
been added, it will automatically be visible whenever its parent window is displayed.
A control can be removed from the window by calling remove() method.
Syntax:
void remove(Component compRef)
You can remove all controls by calling removeAll() method.
public void drawRect(int x, int y, int width, int height) Draws a rectangle with the specified width and height.
Used to fill rectangle with the default color and specified width and
public abstract void fillRect(int x, int y, int width, int height)
height.
public abstract void drawOval(int x, int y, int width, int height) Used to draw oval with the specified width and height.
public abstract void fillOval(int x, int y, int width, int height) Used to fill oval with the default color and specified width and height.
public abstract void drawLine(int x1, int y1, int x2, int y2) Used to draw line between the points(x1, y1) and (x2, y2).
public abstract void drawArc(int x, int y, int width, int height, int
Used draw a circular or elliptical arc.
startAngle, int arcAngle)
public abstract void fillArc(int x, int y, int width, int height, int
Used to fill a circular or elliptical arc.
startAngle, int arcAngle)
public abstract void setColor(Color c) Used to set the graphics current color to the specified color.
abstract void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) Draws a closed polygon defined by arrays of x and y coordinates.
abstract void drawRoundRect(int x, int y, int width, int height, Draws an outlined round-cornered rectangle using this graphics context's
int arcWidth, int arcHeight) current color.
5
Font Styles: Font.PLAIN, Font.BOLD, and Font.ITALIC. The
public Font (String name, int style, int size)
combination Font.BOLD | Font.ITALIC specifies bold italics.
abstract void setFont(Font font) Sets this graphics context's font to the specified font.
Component.setForeground(Color c) Sets the foreground color of this component.
Component.Background(Color c) Sets the background color of this component.