0% found this document useful (0 votes)
35 views23 pages

Java AWT

Uploaded by

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

Java AWT

Uploaded by

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

AWT

Chittaranjan Pradhan

Web Technology 16 Working with Graphics

Working with Color

AWT Working with Font

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

• All graphics are drawn relative to a window Working with Font

AWT
• Graphics class defines a number of drawing functions
AWT Controls
Label
Button

Drawing Lines Checkbox


Radio Button
TextField
void drawLine(int x1, int y1, int x2, int y2)

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

Working with Font


void drawRoundRect(int top, int left, int width, int height,
AWT
int arcWidth, int arcHeight)
AWT Controls
void fillRoundRect(int top, int left, int width, int height, int Label
Button
arcWidth, int arcHeight) Checkbox
Radio Button
TextField

16.3
AWT
Working with Graphics...
Chittaranjan Pradhan

Working with Graphics

Drawing Arcs Working with Color

Working with Font


void drawArc(int top, int left, int width, int height, int AWT
startAngle, int sweepAngle) AWT Controls

void fillArc(int top, int left, int width, int height, int Label
Button

startAngle, int sweepAngle) Checkbox


Radio Button
TextField

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

Working with Font

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

Working with Color Working with Graphics

Working with Color

• Color is a class which is inherited from Object class and Working with Font

implements Paint and Serializable interfaces AWT

AWT Controls
Label

• The default colors are: {Color.black, Color.blue, Color.cyan Button


Checkbox

Color.magenta, Color.gray Color.green, Color.lightGray, Radio Button


TextField
Color.orange, Color.pink, Color.red, Color.white,
Color.yellow }

• Color(float r, float g, float b)


Color(int r, int g, int b)

Ex: Color c=new Color(255,100,100);


• void setColor(Color newColor)
Color getColor()

16.6
AWT
Working with Color...
Chittaranjan Pradhan
Working with Color...
Working with Graphics

Working with Color

Working with Font

AWT

AWT Controls
Label
Button
Checkbox
Radio Button
TextField

16.7
AWT
Working with Font
Chittaranjan Pradhan

Working with Font Working with Graphics

Working with Color

• 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

Working with Graphics

Working with Color

Working with Font

AWT

AWT Controls
Label
Button
Checkbox
Radio Button
TextField

16.9
AWT
AWT
Chittaranjan Pradhan

Working with Graphics

AWT Working with Color

Working with Font


• AWT (Abstract Window Toolkit) represents a class library AWT

to develop applications using GUI AWT Controls


Label
• java.awt package contains all classes used for creating Button
Checkbox
GUI, painting graphics, images, colors and fonts Radio Button
TextField
• A user interface element such as a button is called a
Component. The Component class is the super class of all
AWT components. These components fire events when
users interact with these components
• A Container is one which contains components and other
containers. A container has a layout manager that
determines the visual placement of components in the
container

16.10
AWT
AWT...
Chittaranjan Pradhan
Commonly used AWT Classes
Working with Graphics

Working with Color

Working with Font

AWT

AWT Controls
Label
Button
Checkbox
Radio Button
TextField

16.11
AWT
AWT Controls
Chittaranjan Pradhan

AWT Controls Working with Graphics

Working with Color


• AWT supports the following types of controls:
Working with Font
• Label
AWT
• Button
AWT Controls
• Checkbox Label
Button
• RadioButton Checkbox
• Choice Radio Button
TextField
• List
• TextComponent
• ScrollBar
• Adding/Removing Controls
Component add (Component compObj)
void remove(Component compObj)
• HeadlessException: The constructors of AWT controls
can throw a HeadlessException when an attempt is made
to instantiate a GUI component in a non-interactive
environment

16.12
AWT
Label
Chittaranjan Pradhan

Label Working with Graphics

Working with Color


• It contains a string, which is a passive control that doesn’t Working with Font

support any user interaction AWT

AWT Controls
• Label() Label

Label(String str) Button


Checkbox
Label(String str, int align) Radio Button
TextField
align may be Label.LEFT or Label.RIGHT or
Label.CENTER
Label lbl=new Label("Hello");

• lbl.setText (New Text");


String txt=lbl.getText();

• lbl.setAlignment(Label.RIGHT);
int algn=lbl.getAlignment();

16.13
AWT
Label...
Chittaranjan Pradhan

Label... Working with Graphics

Working with Color

Working with Font

AWT

AWT Controls
Label
Button
Checkbox
Radio Button
TextField

16.14
AWT
Button
Chittaranjan Pradhan

Working with Graphics

Working with Color

Working with Font


Button AWT

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

Working with Color

Working with Font

AWT

AWT Controls
Label
Button
Checkbox
Radio Button
TextField

16.16
AWT
Checkbox
Chittaranjan Pradhan

Working with Graphics

Working with Color

Checkbox Working with Font

AWT
• It is used to turn an option on or off AWT Controls
Label
• Checkbox() Button
Checkbox
Checkbox(String str) Radio Button

Checkbox(String str, boolean state) TextField

Checkbox name=new Checkbox(Names", null, false);

• 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

Working with Color

Working with Font

AWT

AWT Controls
Label
Button
Checkbox
Radio Button
TextField

16.18
AWT
Checkbox...
Chittaranjan Pradhan

Checkbox...
Working with Graphics

Working with Color

Working with Font

AWT

AWT Controls
Label
Button
Checkbox
Radio Button
TextField

16.19
AWT
Radio Button
Chittaranjan Pradhan

Working with Graphics

Working with Color

Working with Font

AWT
Radio Button AWT Controls
Label
Button
• These are a special kind of checkboxes. CheckboxGroup Checkbox

class is used to group together a set of checkboxes Radio Button


TextField

• CheckboxGroup fruits=new CheckboxGroup();


add(new Checkbox(Mango",fruits, false);
add(new Checkbox(Äpple",fruits,false);

16.20
AWT
Radio Button...
Chittaranjan Pradhan
Radio Button...
Working with Graphics

Working with Color

Working with Font

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

• TextField() Working with Font

TextField(int noChars) AWT

AWT Controls
TextField(String str) Label

TextField(String str, int noChars) Button


Checkbox
Radio Button
TextField

• String getText()
void setText(String str)

• String getSelectedText()
void select(int startIndex, int endIndex)

• boolean isEditable()
void setEditable(boolean isedit)

• void setEchoChar(char ch)


16.22
AWT
TextField
Chittaranjan Pradhan
TextField
Working with Graphics

Working with Color

Working with Font

AWT

AWT Controls
Label
Button
Checkbox
Radio Button
TextField

16.23

You might also like