AWT controls, Listeners

101 views 20 slides Jul 12, 2021
Slide 1
Slide 1 of 20
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20

About This Presentation

this lecture slide introduces the controls, classes , events and listeners that can be implemented in JAVA using Frames or Applets


Slide Content

UNIT 5 CHAPTER :1 AWT CLASSES & WINDOWS FUNDAMENTALS Dr.K.Kalaiselvi Dept of computer science Kristu Jayanti College Bangalore

AWT CLASSES

5 To build a GUI... Make somewhere to display things—usually a Frame or Dialog (for an application), or an Applet Create some Components , such as buttons, text areas, panels, etc. Add your Components to your display area Arrange, or lay out , your Components Attach Listeners to your Components Interacting with a Component causes an Event to occur A Listener gets a message when an interesting event occurs, and executes some code to deal with it

6 An Applet HIERARCHY java.lang.Object | +---- java.awt.Component | +---- java.awt.Container | +---- java.awt.Panel | +---- java.applet.Applet …so you can display things in an Applet

AWT – Class Hierarchy Panel Button Checkbox Choice Label List Component Container Frame Window TextArea TextField TextComponent Note: There are more classes, however, these are what are covered in this chapter

9 Example: A "Life" applet Container ( Applet ) Containers ( Panel s) Component ( Canvas ) Components ( Button s) Components ( Label s) Components ( TextField s)

10 Some types of components Label Button Button Checkbox Choice List Scrollbar TextField TextArea CheckboxGroup Checkbox

11 Creating a Graphical User Interface GUI programming in Java is based on three concepts: Components. A component is an object that the user can see on the screen and—in most cases—interact with. Containers. A container is a component that can hold other components. Events. An event is an action triggered by the user, such as a key press or mouse click. Designing a graphical user interface involves creating components, putting them into containers, and arranging for the program to respond to events.

COMPONENT: Component class is at the top of the AWT hierarchy. Its an abstract class that encapsulates all of the attributes of a visual component . All the user interface elements that are displayed on the screen and that interact with the user are subclasses of Component. CONTAINER: The Container class is a subclass of Component. It has additional methods that allow other Component objects to be nested within it. other container objects can be stored inside a Container. Various layouts can be used by implementing Layout Manager. PANEL: It’s a subclass of Container . It does not have any new methods .It implements Container . Panel is the super class for Applet . The output on the screen directed to an Applet is actually drawn on the surface of Panel object .A panel is a window that does not has a title bar ,Menu bar or a border. Components can be added to the Panel using add() method inherited from Container. Once the components are added they can be resized , positioned using setSize () , setLocation (), setBounds () etc. WINDOW: A Window class creates a top-level window.Window is not contained within any other object. It is placed directly on the desktop.

FRAME: It’s a subclass of Window and has a title bar, menu bar and resizing corners also. When a Frame object is created a warning msg such as “Java Applet Window” will be displayed to ensure the user that the Frame is created by the Applet Window not by any other running software. CANVAS: It is not the hierarchy of Frame of applet. But it is another type of Window used in GUI.

Working with Frame Windows Frames are most widely used after the usage of applets. The Constructors use are The first form creates the window without ant title. The second form creates the window with a title . Windows can be resized , made to visible and closed also using the following methods.

Closing the windows can be done by either using setVisible (false) or using windowClosing () method of windowListener interface.

Thank you