Java AWT
Java AWT
Chittaranjan Pradhan
AWT
AWT Controls
Label
Button
Checkbox
Radio Button
TextField
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
16.1
AWT
Working with Graphics
Chittaranjan Pradhan
Working with Graphics
Working with Graphics
• AWT supports a rich assortment of graphics methods
Working with Color
AWT
• Graphics class defines a number of drawing functions
AWT Controls
Label
Button
16.2
AWT
Working with Graphics...
Chittaranjan Pradhan
Drawing Rectangles
void drawRect(int top, int left, int width, int height) Working with Graphics
void fillRect(int top, int left, int width, int height) Working with Color
16.3
AWT
Working with Graphics...
Chittaranjan Pradhan
void fillArc(int top, int left, int width, int height, int Label
Button
16.4
AWT
Working with Graphics...
Chittaranjan Pradhan
Drawing Ellipses & Circles
void drawOval(int top, int left, int width, int height) Working with Graphics
void fillOval(int top, int left, int width, int height) Working with Color
AWT
AWT Controls
Label
Button
Checkbox
Radio Button
TextField
Drawing Polygons
void drawPolygon(int x[], int y[], int noPts)
void fillPolygon(int x[], int y[], int noPts)
16.5
AWT
Working with Color
Chittaranjan Pradhan
• Color is a class which is inherited from Object class and Working with Font
AWT Controls
Label
16.6
AWT
Working with Color...
Chittaranjan Pradhan
Working with Color...
Working with Graphics
AWT
AWT Controls
Label
Button
Checkbox
Radio Button
TextField
16.7
AWT
Working with Font
Chittaranjan Pradhan
• Font class extends Object class and implements Working with Font
AWT
Serializable interface
AWT Controls
Label
Button
• The variables of Font are: {Name, PointSize, size, style} Checkbox
Radio Button
TextField
• Font(Font font)
Font(String name, int style, int size)
• name specifies the name of the desired Font
• style specifies the style of the desired Font, which can be
Font.PLAIN, Font.BOLD, Font.ITALIC or any combination
like Font.ITALIC | Font.BOLD
• size specifies the size of the Font in points
• Once the Font is created, setFont() method of Component
class is used to select it
16.8
AWT
Working with Font...
Chittaranjan Pradhan
AWT
AWT Controls
Label
Button
Checkbox
Radio Button
TextField
16.9
AWT
AWT
Chittaranjan Pradhan
16.10
AWT
AWT...
Chittaranjan Pradhan
Commonly used AWT Classes
Working with Graphics
AWT
AWT Controls
Label
Button
Checkbox
Radio Button
TextField
16.11
AWT
AWT Controls
Chittaranjan Pradhan
16.12
AWT
Label
Chittaranjan Pradhan
AWT Controls
• Label() Label
• lbl.setAlignment(Label.RIGHT);
int algn=lbl.getAlignment();
16.13
AWT
Label...
Chittaranjan Pradhan
AWT
AWT Controls
Label
Button
Checkbox
Radio Button
TextField
16.14
AWT
Button
Chittaranjan Pradhan
AWT Controls
• It is a component that contains a label and that generates Label
Button
an event when it is pressed Checkbox
Radio Button
• Button() TextField
Button(String str)
Button btn=new Button("Hello");
• btn.setLabel(New Text");
String txt=btn.getLabel();
16.15
AWT
Button...
Chittaranjan Pradhan
Button...
Working with Graphics
AWT
AWT Controls
Label
Button
Checkbox
Radio Button
TextField
16.16
AWT
Checkbox
Chittaranjan Pradhan
AWT
• It is used to turn an option on or off AWT Controls
Label
• Checkbox() Button
Checkbox
Checkbox(String str) Radio Button
• boolean st=name.getState();
name.setState(boolean state);
String str=name.getLabel();
name.setLabel(New Text");
16.17
AWT
Checkbox...
Chittaranjan Pradhan
Checkbox...
Working with Graphics
AWT
AWT Controls
Label
Button
Checkbox
Radio Button
TextField
16.18
AWT
Checkbox...
Chittaranjan Pradhan
Checkbox...
Working with Graphics
AWT
AWT Controls
Label
Button
Checkbox
Radio Button
TextField
16.19
AWT
Radio Button
Chittaranjan Pradhan
AWT
Radio Button AWT Controls
Label
Button
• These are a special kind of checkboxes. CheckboxGroup Checkbox
16.20
AWT
Radio Button...
Chittaranjan Pradhan
Radio Button...
Working with Graphics
AWT
AWT Controls
Label
Button
Checkbox
Radio Button
TextField
16.21
AWT
TextField
Chittaranjan Pradhan
TextField
Working with Graphics
• It handles single line of text Working with Color
AWT Controls
TextField(String str) Label
• String getText()
void setText(String str)
• String getSelectedText()
void select(int startIndex, int endIndex)
• boolean isEditable()
void setEditable(boolean isedit)
AWT
AWT Controls
Label
Button
Checkbox
Radio Button
TextField
16.23