Professional Documents
Culture Documents
1 Applet and Basic AWT Lecture
1 Applet and Basic AWT Lecture
1 Applet and Basic AWT Lecture
What is an applet?
An applet is a java program that is intended to run upon call from within another
application particularly a web browser.
lblgreet.setForeground(Color.yellow);
txtgreet.setForeground(Color.blue);
lblgreet.setBackground(Color.blue);
txtgreet.setBackground(Color.yellow);
txtgreet.setText(name);
add(lblgreet);
add(txtgreet);
add(btnClear);
}
}
AWT is a set of classes that enables you to create a GUI (Graphical User
Interface)
AWT consists of:
o Components - anything that can be put onto the user interface
o Containers - a component that can contain other components
import java.awt.*;
Label
o Single line of text used for labeling components which cannot be edited
o Declaration & Instantiation:
Label name = new Label(String s);
Ex. Label lbl = new Label(“Name”);
o Properties:
text
foreground color
background color
o Constructors:
Label()- no text value
Label(String) - with text value
Label(String, Alignment) – with text value & alignment
Label.RIGHT
Label.CENTER
Label.LEFT
o Methods:
void setForeground(Color) – set the text color
void setBackground(Color) – set the background color
Color.cyan
Color.magenta
Color.lightGray
Color.darkGray
Color.(Other Basic Colors)
void setText(String) - set a new text value
void setFont(Font) -set the font type, format, and size
Type:
o “Font.Serif”
o “Font.Monospaced”
o “Font.SansSerif”
o “Font.Dialog”
o “Font.DialogInput”
Style
o Font.Plain
o Font.Bold
o Font.Italic
o Font.Plain+Font.Italic
o Font.Bold+Font.Italic
Size - 8 to 100
o Methods:
void setLabel(String) - set a label value
String getLabel() - returns the label value
void setEnabled(boolean) – set to false which makes inaccessible
Ex#1: Applet Program (Adding Events)
import java.applet.*;
import java.awt.*;
import java.awt.event.*;