You are on page 1of 2

1

Introduction to AWT
provides a
 AWT, which stands for Abstract Window Toolkit, is a set of set of components that you can use to create
graphical user interface (GUI) components and classes in Java graphical user interfaces (GUIs) in Java
that allow developers to create platform-independent applications. These components are part of
windowed applications and graphical user interfaces. the `java.awt` package. Here are some of the
common AWT components:
 The Abstract Window Toolkit (AWT) is a set of application
1. **Frame**: A top-level window with a
programming interfaces (APIs) provided by Java for creating
graphical user interfaces (GUIs) in Java applications. title and border. Frames are typically used
as the main application window.
 AWT is part of the Java Foundation Classes (JFC) and serves 2. **TextField**: An input component for
as the foundation for building GUI components in Java.
single-line text input. Users can type text
into a text field.

Key features of AWT include: 3. **Label**: A non-editable text component


used for displaying text or captions in a GUI.

1. GUI Component Classes: AWT provides a wide 4. **Button**: A clickable button that can
range of classes for creating common GUI components trigger actions when clicked. You can add
action listeners to buttons to handle events.
like buttons, checkboxes, text fields, and more.
2. Layout Managers: AWT includes layout manager
classes that help in arranging GUI components within
containers, ensuring that they adapt to different screen
sizes and orientations.
3. Event Handling: AWT supports event-driven
programming, allowing developers to define actions or
responses to user interactions (e.g., button clicks or
mouse movements) through event listeners.
4. Graphics and Drawing: AWT provides classes and
methods for drawing graphics, shapes, and images on
GUI components and canvases.
5. Platform Independence: AWT was designed to be
platform-independent, allowing Java GUI applications to
run on various operating systems without modification. Fig 1.1

Remark : GUI is a visual way for users to interact with a computer or software application through graphical elements like
windows, icons, buttons, and menus, rather than using text-based commands.

Software Enginnering 1
2

Examples
E x a m p l e s
import java.awt.*; // this code shows how text field
inserted in frame
class myframe {
package javaapplication1;
myframe(){
import java.awt.*;
Frame f=new Frame();
class myframe {
f.setVisible(true);
myframe(){
f.setSize(400,400);
Frame f=new Frame();
f.setTitle("food app");
f.setSize(400,400);
f.setResizable(false);
f.setTitle("food app");
}
f.setResizable(false);
}
TextField t=new TextField();
public class JavaApplication2 {
t.setBounds(10,10,30,20);
public static void main(String[] args) {
f.add(t);
myframe m=new myframe();
f.setVisible(true);
}
f.setLayout(new FlowLayout());
} Output : }
}
public class JavaApplication1 {
public static void main(String[] args)
{
myframe m=new myframe();
}

} Output :
// this is how label works within frame
package javaapplication1;
import java.awt.*;
class myframe {
myframe(){
Frame f=new Frame();
f.setSize(400,400);
// this code shows how button inserted in
f.setTitle("food app"); frame
f.setResizable(false); package javaapplication1;
Label l1 =new Label("name"); import java.awt.*;
f.add(l1); class myframe {
f.setVisible(true); myframe(){
} Frame f=new Frame();
} f.setVisible(true);
public class JavaApplication1 { f.setSize(400,400);
public static void main(String[] args) { f.setTitle("food app");
myframe m=new myframe(); f.setResizable(false);
} Button b=new Button("submit");

} Output : f.add(b);
f.setLayout(new FlowLayout())
}
}
public class JavaApplication1 {
public static void main(String[] args)
{
myframe m=new myframe();
}

} Output :

EPHREM -MEKONNEN HAILEAB ZINABU EBRAHIM JENBERU


NSR/893/13 NSR/T/AM/14/640 NSR/796/13
Software Enginnering 2

You might also like