0% found this document useful (0 votes)
21 views6 pages

AWT Components Table

Uploaded by

Tejas Narwade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views6 pages

AWT Components Table

Uploaded by

Tejas Narwade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

AWT Components

Sr.No. Name of Constructor Methods Value


Component
1. Label Label() void setText(String str) align:
throws Label(String str) String getText() Label.LEFT
HeadlessException Label(String str, int align) void setAlignment(int align) Label.RIGHT
int getAlignment() Label.CENTER
2. Button Button() void setLabel(String str)
(ActionListener) Button(String txt) String getLabel()
throws
HeadlessException
3. Check Box Checkbox() boolean getState() check:
(ItemListener) Checkbox(String lb) void setState(Boolean on) True (Selected)
(Shape: square) Checkbox(String lb, String getLabel() False
throws boolean check) void setLabel(String str)
HeadlessException Checkbox(String lb,
First three constructors boolean check,
create checkboxes CheckboxGroup cbg)
Last two constructors Checkbox(String lb,
create checkboxes for CheckboxGroup cbg,
CheckboxGroup boolean check)
4. CheckboxGroup CheckboxGroup() Checkbox which: Checkbox to be selected
(Radio Button) -Default constructor creates getselectedCheckbox()
(Shape: round) empty group void
(ItemListener) setselectedCheckbox(Checkbox
which)

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()

9 TextArea() TextArea() All above methods sBars: SCROLLBARS_BOTH


(ActionListener, TextArea(int numlines, int void append(String str) SCROLLBARS_NONE
TextListener) numchars) void insert(String str, int index) SCROLLBARS_HORIZONTAL_O
throws TextArea(String str) void replaceRange(String str, int NLY
HeadlessException TextArea(int numlines, int start index, int endindex) SCROLLBARS_VERTICAL_ONL
numchars, int sBars) Y
10 Frame Frame() void setTitle(String title)
(WindowListener) Frame(String title) void setVisible(true/false)
throws void setSize(int width, int
HeadlessException height)
void setSize(Dimension
newsize)
Dimension getSize()
11 Panel Panel()
Panel(LayoutManager obj)
12 MenuBar MenuBar() void setMenuBar(Object obj)
13 Menu Menu() MenuItem add(MenuItem mi) (Adds or inserts menu items in the
(ActionListener, Menu(String optionName) void add(String label) menu)
ItemListener) Menu(String optionName, void addSeparator()
Boolean removable) MenuItem getItem(int index)
int getItemCount()
void insert(MenuItem
menuitem, int index)
void insert(String label, int
index)
void insertSeparator(int index)

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)

Adding and removing controls


To include a control in a window, you must add it to the window. To do this, you must first create an instance of the desired control
and then add it to a window, by calling the add() method
Syntax:
Component add(Component compRef)

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.

Graphics class methods


Method Description
public abstract void drawString(String str, int x, int y) Used to draw the specified string.

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.

You might also like