JAVA PROGRAMMING - AWT
Prof. Navya Francis
Asst. Professor
Kristu Jayanti College
ABSTRACT WINDOW TOOL KIT
• Java AWT is an API that contains large number of classes and methods
to create and manage graphical user interface ( GUI ) applications.
• The AWT was designed to provide a common set of tools for GUI design
that could work on a variety of platforms.
• AWT was Java’s first GUI Framework.
• AWT is the foundation upon which Swing is made i.e Swing is a
improved GUI API that extends the AWT.
AWT
• Java AWT components are platform-dependent i.e. components are
displayed according to the view of operating system.
• AWT is heavy weight i.e. its components are using the resources of
underlying operating system (OS)
• Java AWT components are platform-dependent i.e. components are
displayed according to the view of operating system.
• The java.awt package provides classes for AWT API such as TextField,
Label, TextArea, RadioButton, CheckBox, Choice, List etc.
JAVA AWT HIERARCHY
COMPONENTS
• All the elements like the button, text fields, scroll bars, etc. are called
components.
• In Java AWT, there are classes for each component as shown in above
diagram.
• In order to place every component in a particular position on a screen,
we need to add them to a container.
CONTAINER
• The Container is a component in AWT that can contain another
components like buttons, textfields, labels etc.
• The classes that extends Container class are known as container such as
Frame, Dialog and Panel.
• It is basically a screen where the components are placed at their specific
locations.
• Thus it contains and controls the layout of components.
TYPES OF CONTAINERS:
There are four types of containers in Java AWT:
• Window
• Panel
• Frame
• Dialog
TYPES OF CONTAINERS:
• Window
• The window is the container that have no borders and menu bars. You must use frame, dialog or
another window for creating a window. We need to create an instance of Window class to create
this container
• Panel
• The Panel is the container that doesn't contain title bar, border or menu bar. It is generic container
for holding the components. It can have other components like button, text field etc. An instance of
Panel class creates a container, in which we can add components.
TYPES OF CONTAINERS:
• Frame
• The Frame is the container that contain title bar and border and can have
menu bars.
• It can have other components like button, text field, scrollbar etc.
• Frame is most widely used container while developing an AWT application.
• Frame is a subclass of Window and have resizing canvas.
TYPES OF CONTAINERS:
• The Dialog control
• The Dialog control represents a top level window with a border and a
title used to take some form of input from the user.
• It inherits the Window class.
• Unlike Frame, it doesn't have maximize and minimize buttons.
• Frame and Dialog both inherits Window class.
• Frame has maximize and minimize buttons but Dialog doesn't have.
CREATING A FRAME
There are two ways to create a Frame. They are,
• By Instantiating Frame class
• By extending Frame class
POINTS TO REMEMBER:
• While creating a frame (either by instantiating or extending Frame class),
Following two attributes are must for visibility of the frame:
• setSize(int width, int height);
• setVisible(true);
• When you create other components like Buttons, TextFields, etc. Then
you need to add it to the frame by using the method -
add(Component's Object);
• You can add the following method also for resizing the frame -
setResizable(true);
BY INSTANTIATING FRAME CLASS
BY EXTENDING FRAME CLASS
BY EXTENDING FRAME CLASS
UNDERSTANDING LAYOUT MANAGERS
• The layout manager automatically positions all the components within
the container. If we do not use layout manager then also the
components are positioned by the default layout manager.
• Each Container object has a layout manager associated with it.
• A layout manager is an instance of any class that implements the
LayoutManagerinterface.
UNDERSTANDING LAYOUT MANAGERS
• The layout manager is set by the setLayout( ) method.
• If no call to setLayout( ) is made,then the default layout manager is
used.
• Whenever a container is resized (or sized for the first time), the layout
manager is used to position each of the components within it.
• The setLayout( ) method has the following general form:
• void setLayout(LayoutManager layoutObj)
FLOWLAYOUT
• It is the default layout manager.
• FlowLayout implements a simple layout style, which is similar to how words flow in a text editor.
• FlowLayout.LEFT
• FlowLayout.CENTER
• FlowLayout.RIGHT
• FlowLayout.LEADING
• FlowLayout.TRAILING
• These values specify left, center, right, leading edge, and trailing edge alignment, respectively
BORDERLAYOUT
• The BorderLayout class implements a common layout style for top-level windows.
• It has four narrow, fixed-width components at the edges and one large area in the center.
• The four sides are referred to as north, south, east, and west. The middle area is called the center.
BorderLayout defines the following constants that specify the regions:
• BorderLayout.CENTER
• BorderLayout.SOUTH
• BorderLayout.EAST
• BorderLayout.WEST
• BorderLayout.NORTH
AWT CONTROL FUNDAMENTALS
• The AWT supports the following types of controls:
• These controls are subclasses of Component.
• Labels
• Buttons
• Check boxes
• Check box groups
• Choice control
• Lists
• Scroll bar
• Text field
• Text area
ADDING AND REMOVING CONTROLS
• In order to include a control in a window, we must add it to the window.
• So, we must first create an instance of the desired control and then add
it to a window by calling add( ), which is defined by Container.
• Component add(Component compObj)
ADDING AND REMOVING CONTROLS
• Once a control has been added, it will automatically be visible whenever
its parent window is displayed.
• Sometimes we will want to remove a control from a window when the
control is no longer needed.
• For doing this, call remove( ).
• This method is also defined by Container.
• It has this general form: void remove(Component obj) Here, obj is a
reference to the control that we want to remove.
• We can remove all controls by calling removeAll( )
LABEL
• A label is a user for placing text inside the container.
• A label is used only for inputting text.
• The label does not imply that the text can be altered or it can be used as
a button which can be further worked upon.
Label n=new Label("Name:",Label.CENTER);
LABEL
BUTTON
• This command generates a button in the User Interface.
• Clicking on the button would move the command to another page or
another web server which is used to show several other outputs in the
user interface page.
a1=new Button("submit");
a2=new Button("cancel");
BUTTON
CHECK BOXES
• A check box is a control that is used to turn an option on or off. It
consists of a small box that can either contain a check mark or not.
• There is a label associated with each check box that describes what
option the box represents.
• We change the state of a check box by clicking on it. Check boxes can be
used individually or as part of a group.
• Check boxes are objects of the Checkbox class
• Checkbox checkbox1 = new Checkbox("Hello World");
CHECK BOXES
CHECKBOX GROUP
• It is possible to create a set of mutually exclusive check boxes in which one
and only one check box in the group can be checked at any one time.
• These are often called radio buttons.
• For creating a set of mutually exclusive check boxes, we must first define the
group to which they will belong and then specify that group when we
construct the check boxes.
• Check box groups are objects of type CheckBoxGroup.
CheckboxGroup cb = new CheckboxGroup();
Checkbox checkBox1 = new Checkbox("Hello", cb, true);
checkBox1.setBounds (100,100, 50,50);
CHECKBOX GROUP
MANAGING SCROLL BARS
• Scroll bars are used to select continuous values between a specified
minimum and maximum. Scroll bars may be oriented horizontally or
vertically.
• Each end has an arrow that you can click to move the current value of
the scroll bar one unit in the direction of the arrow.
Scrollbar s=new Scrollbar();
s.setBounds(100,100, 50,100);
MANAGING SCROLL BARS
TEXTFIELD
• The TextField class implements a single-line text-entry area, usually
called an edit control.
• Text fields allow the user to enter strings and to edit the text using the
arrow keys, cut and paste keys, and mouse selections.
na=new TextField(“my name”);
TEXTFIELD
TEXTAREA
• Sometimes a single line of text input is not enough for a given task. To
handle these situations, the AWT includes a simple multiline editor
called TextArea.
TextArea area=new TextArea("Welcome to the
universe");
area.setBounds(10,30, 300,300);
TEXTAREA
CHOICE CONTROLS
• The Choice class is used to create a pop -up list of items from which the user
may choose. Thus, a Choice control is a form of menu.
• When inactive, a Choice component takes up only enough space to show
the currently selected item. When the user clicks on it, the whole list of
choices pops up, and a new selection can be made.
Choice c=new Choice();
c.setBounds(100,100, 75,75);
c.add("Subject 1");
c.add("Subject 2");
c.add("Subject 3");
CHOICE CONTROLS
LISTS
• The List class provides a compact, multiple-choice, scrolling selection
list.
• Unlike the Choice object, which shows only the single selected item in
the menu, a List object can be constructed to show any number of
choices in the visible Window.
• It can also be created to allow multiple selections.
LISTS
MENU BARS AND MENUS
• A top-level window can have a menu bar associated with it.
• A menu bar displays a list of top-level menu choices.
• Each choice is associated with a drop-down menu.
• This concept is implemented in the AWT by the following classes:
MenuBar, Menu,and MenuItem.
MENU BARS AND MENUS
• In general, a menu bar contains one or more Menu objects. Each Menu
object contains a list of MenuItem objects.
• Each MenuItem object represents something that can be selected by the
user.
• Since Menu is a subclass of MenuItem, a hierarchy of nested submenus
can be created.
• It is also possible to include checkable menu items.
• These are menu options of type CheckboxMenuItem and will have a
check mark next to them when they are selected.
MENU BARS AND MENUS
MENU BARS AND MENUS
• Creating Menubar
MenuBar mb=new MenuBar();
• Menu a creation
Menu mnu1=new Menu("BCA");
Menu mnu2=new Menu("BBA");
• sm1 and sm2 will be treated as submenus
Menu sm1=new Menu("Semester");
Menu sm2=new Menu("Year");
• adding items and submenus to menu
mnu1.add(sm1);
mnu1.add(sm2);
• //adding items to submenu
sm1.add(i1);
sm1.add(i2);
sm2.add(i3);
• //adding menu to menubar
mb.add(mnu1);
mb.add(mnu2);
• Creating menu items
MenuItem i1,i2,i3;
i1=new MenuItem("I");
i2=new MenuItem("II");
i3=new MenuItem("2023");
DIALOG BOXES
• Dialog boxes are primarily used to obtain user input and are often child
windows of a top-level window.
• Dialog boxes don’t have menu bars, but in other respects, they function
like frame windows. (You can add controls to them, for example, in the
same way that you add controls to a frame window.)
• When a modal dialog box is active, all input is directed to it until it is
closed.
DIALOG BOXES
• This means that you cannot access other parts of your program until you
have closed the dialog box.
• When a modeless dialog box is active, input focus can be directed to
another window in your program.
• Thus, other parts of your program remain active and accessible. In the
AWT, dialog boxes are of type Dialog
DIALOG BOXES
FILEDIALOG
• Java provides a built-in dialog box that lets the user specify a file.
• To create a file dialog box, instantiate an object of type FileDialog. This
causes a file dialog box to be displayed.
• Usually, this is the standard file dialog box provided by the operating
system.
FILEDIALOG
HANDLING EVENTS BY EXTENDING AWT
COMPONENTS
• Handling events by extending AWT components.
• The delegation event model was introduced in Event handling, and all of
the programs in this book so far have used that design. But Java also
allows you to handle events by subclassing AWT components.
• Doing so allows you to handle events in much the same way as they
were handled under the original 1.0 version of Java. Of course, this
technique is discouraged, because it has the same disadvantages of the
Java 1.0 event model, the main one being inefficiency.
• To extend an AWT component, you must call the enableEvents( ) method
of Component. Its general form is shown here:

More Related Content

PPTX
regular expression
PPTX
Unit2 Toc.pptx
PPTX
PPT
Network layer tanenbaum
PDF
DCDR Unit-3 Huffman Coding
PPTX
Viterbi algorithm
PDF
TOC 2 | Deterministic Finite Automata
PPTX
Theory of computation Lec3 dfa
regular expression
Unit2 Toc.pptx
Network layer tanenbaum
DCDR Unit-3 Huffman Coding
Viterbi algorithm
TOC 2 | Deterministic Finite Automata
Theory of computation Lec3 dfa

What's hot (20)

PPTX
closure properties of regular language.pptx
PPTX
Automata theory - CFG and normal forms
PDF
20CS2008 Computer Networks
PPTX
String Matching (Naive,Rabin-Karp,KMP)
PPTX
Context Free Grammar
PPTX
Network Layer
PDF
Recursive algorithms
PDF
Asynchronous Transfer Mode ATM
PDF
CN R16 -UNIT-5.pdf
PPTX
Finite state Transducers and mealy Machine
PDF
Syntax Directed Definition and its applications
PPTX
Superscalar Processor
PPT
Kleene's theorem
PPTX
Transport Layer In Computer Network
PPT
PPTX
Merge sort algorithm
PPT
Switching
PPTX
Regular expressions
PPSX
Subnetting
closure properties of regular language.pptx
Automata theory - CFG and normal forms
20CS2008 Computer Networks
String Matching (Naive,Rabin-Karp,KMP)
Context Free Grammar
Network Layer
Recursive algorithms
Asynchronous Transfer Mode ATM
CN R16 -UNIT-5.pdf
Finite state Transducers and mealy Machine
Syntax Directed Definition and its applications
Superscalar Processor
Kleene's theorem
Transport Layer In Computer Network
Merge sort algorithm
Switching
Regular expressions
Subnetting
Ad

Similar to JAVA Programming: Topic -AWT(Abstract Window Tool ) (20)

PPTX
UNIT-I.pptx awt advance java abstract windowing toolkit and swing
PPTX
tL19 awt
PPT
events,key,life cycle-abstract window tool kit,abstract class
PPTX
AWT.pptx
PPTX
object oriented programming examples
PPT
13457272.ppt
PPTX
17625-1.pptx
PPTX
AWT stands for Abstract Window Toolkit. AWT is collection of classes and int...
PPTX
MODULE 5.pptx gui programming and applets
PDF
The Concept of Abstract Window Took Kit In Java
PDF
The Concept of Abstract Window Took Kit In Java
PPT
Unit 1- awt(Abstract Window Toolkit) .ppt
PPT
introduction to JAVA awt programmin .ppt
PDF
Ajp notes-chapter-01
PPTX
Gui programming
PPT
fdtrdrtttxxxtrtrctctrttrdredrerrrrrrawt.ppt
PPT
awdrdtfffyfyfyfyfyfyfyfyfyfyfyfyyfyt.ppt
PPT
1.Abstract windowing toolkit.ppt of AJP sub
PPT
awt.ppt java windows programming lecture
PPTX
Chapter iii(building a simple user interface)
UNIT-I.pptx awt advance java abstract windowing toolkit and swing
tL19 awt
events,key,life cycle-abstract window tool kit,abstract class
AWT.pptx
object oriented programming examples
13457272.ppt
17625-1.pptx
AWT stands for Abstract Window Toolkit. AWT is collection of classes and int...
MODULE 5.pptx gui programming and applets
The Concept of Abstract Window Took Kit In Java
The Concept of Abstract Window Took Kit In Java
Unit 1- awt(Abstract Window Toolkit) .ppt
introduction to JAVA awt programmin .ppt
Ajp notes-chapter-01
Gui programming
fdtrdrtttxxxtrtrctctrttrdredrerrrrrrawt.ppt
awdrdtfffyfyfyfyfyfyfyfyfyfyfyfyyfyt.ppt
1.Abstract windowing toolkit.ppt of AJP sub
awt.ppt java windows programming lecture
Chapter iii(building a simple user interface)
Ad

More from Navya Francis (11)

PPTX
Data Warehosuing & Data Mining: Apriori Algorithm
PPTX
Data Warehosuing & Data Mining: FP Growth
PPTX
C Programming: Looping Statements in C Pgm
PPTX
C Programming: Control Statements in C Pgm
PPTX
Data Warehousing & Data Mining: Introduction
PPTX
C Programming: Basic Structure of C Program
PPTX
Data Structures: Introduction to Data Structures
PPTX
JAVA Programming : Topic JAVA Programming Swing
PPTX
Data Structures: Classification of Data Structures
PPTX
Software Engineering Topic: Risk Management
PPTX
Software Engineering: Topic: Waterfall Model
Data Warehosuing & Data Mining: Apriori Algorithm
Data Warehosuing & Data Mining: FP Growth
C Programming: Looping Statements in C Pgm
C Programming: Control Statements in C Pgm
Data Warehousing & Data Mining: Introduction
C Programming: Basic Structure of C Program
Data Structures: Introduction to Data Structures
JAVA Programming : Topic JAVA Programming Swing
Data Structures: Classification of Data Structures
Software Engineering Topic: Risk Management
Software Engineering: Topic: Waterfall Model

Recently uploaded (20)

PDF
Climate and Adaptation MCQs class 7 from chatgpt
PDF
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
PDF
M.Tech in Aerospace Engineering | BIT Mesra
PDF
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
PDF
My India Quiz Book_20210205121199924.pdf
PDF
Journal of Dental Science - UDMY (2022).pdf
PDF
semiconductor packaging in vlsi design fab
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
fundamentals-of-heat-and-mass-transfer-6th-edition_incropera.pdf
PPTX
What’s under the hood: Parsing standardized learning content for AI
PDF
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
PDF
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
DOCX
Cambridge-Practice-Tests-for-IELTS-12.docx
PDF
Empowerment Technology for Senior High School Guide
PDF
Literature_Review_methods_ BRACU_MKT426 course material
PPTX
Core Concepts of Personalized Learning and Virtual Learning Environments
PDF
1.Salivary gland disease.pdf 3.Bleeding and Clotting Disorders.pdf important
PDF
Race Reva University – Shaping Future Leaders in Artificial Intelligence
PDF
Farming Based Livelihood Systems English Notes
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
Climate and Adaptation MCQs class 7 from chatgpt
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
M.Tech in Aerospace Engineering | BIT Mesra
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
My India Quiz Book_20210205121199924.pdf
Journal of Dental Science - UDMY (2022).pdf
semiconductor packaging in vlsi design fab
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
fundamentals-of-heat-and-mass-transfer-6th-edition_incropera.pdf
What’s under the hood: Parsing standardized learning content for AI
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
Cambridge-Practice-Tests-for-IELTS-12.docx
Empowerment Technology for Senior High School Guide
Literature_Review_methods_ BRACU_MKT426 course material
Core Concepts of Personalized Learning and Virtual Learning Environments
1.Salivary gland disease.pdf 3.Bleeding and Clotting Disorders.pdf important
Race Reva University – Shaping Future Leaders in Artificial Intelligence
Farming Based Livelihood Systems English Notes
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx

JAVA Programming: Topic -AWT(Abstract Window Tool )

  • 1. JAVA PROGRAMMING - AWT Prof. Navya Francis Asst. Professor Kristu Jayanti College
  • 2. ABSTRACT WINDOW TOOL KIT • Java AWT is an API that contains large number of classes and methods to create and manage graphical user interface ( GUI ) applications. • The AWT was designed to provide a common set of tools for GUI design that could work on a variety of platforms. • AWT was Java’s first GUI Framework. • AWT is the foundation upon which Swing is made i.e Swing is a improved GUI API that extends the AWT.
  • 3. AWT • Java AWT components are platform-dependent i.e. components are displayed according to the view of operating system. • AWT is heavy weight i.e. its components are using the resources of underlying operating system (OS) • Java AWT components are platform-dependent i.e. components are displayed according to the view of operating system. • The java.awt package provides classes for AWT API such as TextField, Label, TextArea, RadioButton, CheckBox, Choice, List etc.
  • 5. COMPONENTS • All the elements like the button, text fields, scroll bars, etc. are called components. • In Java AWT, there are classes for each component as shown in above diagram. • In order to place every component in a particular position on a screen, we need to add them to a container.
  • 6. CONTAINER • The Container is a component in AWT that can contain another components like buttons, textfields, labels etc. • The classes that extends Container class are known as container such as Frame, Dialog and Panel. • It is basically a screen where the components are placed at their specific locations. • Thus it contains and controls the layout of components.
  • 7. TYPES OF CONTAINERS: There are four types of containers in Java AWT: • Window • Panel • Frame • Dialog
  • 8. TYPES OF CONTAINERS: • Window • The window is the container that have no borders and menu bars. You must use frame, dialog or another window for creating a window. We need to create an instance of Window class to create this container • Panel • The Panel is the container that doesn't contain title bar, border or menu bar. It is generic container for holding the components. It can have other components like button, text field etc. An instance of Panel class creates a container, in which we can add components.
  • 9. TYPES OF CONTAINERS: • Frame • The Frame is the container that contain title bar and border and can have menu bars. • It can have other components like button, text field, scrollbar etc. • Frame is most widely used container while developing an AWT application. • Frame is a subclass of Window and have resizing canvas.
  • 10. TYPES OF CONTAINERS: • The Dialog control • The Dialog control represents a top level window with a border and a title used to take some form of input from the user. • It inherits the Window class. • Unlike Frame, it doesn't have maximize and minimize buttons. • Frame and Dialog both inherits Window class. • Frame has maximize and minimize buttons but Dialog doesn't have.
  • 11. CREATING A FRAME There are two ways to create a Frame. They are, • By Instantiating Frame class • By extending Frame class
  • 12. POINTS TO REMEMBER: • While creating a frame (either by instantiating or extending Frame class), Following two attributes are must for visibility of the frame: • setSize(int width, int height); • setVisible(true); • When you create other components like Buttons, TextFields, etc. Then you need to add it to the frame by using the method - add(Component's Object); • You can add the following method also for resizing the frame - setResizable(true);
  • 16. UNDERSTANDING LAYOUT MANAGERS • The layout manager automatically positions all the components within the container. If we do not use layout manager then also the components are positioned by the default layout manager. • Each Container object has a layout manager associated with it. • A layout manager is an instance of any class that implements the LayoutManagerinterface.
  • 17. UNDERSTANDING LAYOUT MANAGERS • The layout manager is set by the setLayout( ) method. • If no call to setLayout( ) is made,then the default layout manager is used. • Whenever a container is resized (or sized for the first time), the layout manager is used to position each of the components within it. • The setLayout( ) method has the following general form: • void setLayout(LayoutManager layoutObj)
  • 18. FLOWLAYOUT • It is the default layout manager. • FlowLayout implements a simple layout style, which is similar to how words flow in a text editor. • FlowLayout.LEFT • FlowLayout.CENTER • FlowLayout.RIGHT • FlowLayout.LEADING • FlowLayout.TRAILING • These values specify left, center, right, leading edge, and trailing edge alignment, respectively
  • 19. BORDERLAYOUT • The BorderLayout class implements a common layout style for top-level windows. • It has four narrow, fixed-width components at the edges and one large area in the center. • The four sides are referred to as north, south, east, and west. The middle area is called the center. BorderLayout defines the following constants that specify the regions: • BorderLayout.CENTER • BorderLayout.SOUTH • BorderLayout.EAST • BorderLayout.WEST • BorderLayout.NORTH
  • 20. AWT CONTROL FUNDAMENTALS • The AWT supports the following types of controls: • These controls are subclasses of Component. • Labels • Buttons • Check boxes • Check box groups • Choice control • Lists • Scroll bar • Text field • Text area
  • 21. ADDING AND REMOVING CONTROLS • In order to include a control in a window, we must add it to the window. • So, we must first create an instance of the desired control and then add it to a window by calling add( ), which is defined by Container. • Component add(Component compObj)
  • 22. ADDING AND REMOVING CONTROLS • Once a control has been added, it will automatically be visible whenever its parent window is displayed. • Sometimes we will want to remove a control from a window when the control is no longer needed. • For doing this, call remove( ). • This method is also defined by Container. • It has this general form: void remove(Component obj) Here, obj is a reference to the control that we want to remove. • We can remove all controls by calling removeAll( )
  • 23. LABEL • A label is a user for placing text inside the container. • A label is used only for inputting text. • The label does not imply that the text can be altered or it can be used as a button which can be further worked upon. Label n=new Label("Name:",Label.CENTER);
  • 24. LABEL
  • 25. BUTTON • This command generates a button in the User Interface. • Clicking on the button would move the command to another page or another web server which is used to show several other outputs in the user interface page. a1=new Button("submit"); a2=new Button("cancel");
  • 27. CHECK BOXES • A check box is a control that is used to turn an option on or off. It consists of a small box that can either contain a check mark or not. • There is a label associated with each check box that describes what option the box represents. • We change the state of a check box by clicking on it. Check boxes can be used individually or as part of a group. • Check boxes are objects of the Checkbox class • Checkbox checkbox1 = new Checkbox("Hello World");
  • 29. CHECKBOX GROUP • It is possible to create a set of mutually exclusive check boxes in which one and only one check box in the group can be checked at any one time. • These are often called radio buttons. • For creating a set of mutually exclusive check boxes, we must first define the group to which they will belong and then specify that group when we construct the check boxes. • Check box groups are objects of type CheckBoxGroup. CheckboxGroup cb = new CheckboxGroup(); Checkbox checkBox1 = new Checkbox("Hello", cb, true); checkBox1.setBounds (100,100, 50,50);
  • 31. MANAGING SCROLL BARS • Scroll bars are used to select continuous values between a specified minimum and maximum. Scroll bars may be oriented horizontally or vertically. • Each end has an arrow that you can click to move the current value of the scroll bar one unit in the direction of the arrow. Scrollbar s=new Scrollbar(); s.setBounds(100,100, 50,100);
  • 33. TEXTFIELD • The TextField class implements a single-line text-entry area, usually called an edit control. • Text fields allow the user to enter strings and to edit the text using the arrow keys, cut and paste keys, and mouse selections. na=new TextField(“my name”);
  • 35. TEXTAREA • Sometimes a single line of text input is not enough for a given task. To handle these situations, the AWT includes a simple multiline editor called TextArea. TextArea area=new TextArea("Welcome to the universe"); area.setBounds(10,30, 300,300);
  • 37. CHOICE CONTROLS • The Choice class is used to create a pop -up list of items from which the user may choose. Thus, a Choice control is a form of menu. • When inactive, a Choice component takes up only enough space to show the currently selected item. When the user clicks on it, the whole list of choices pops up, and a new selection can be made. Choice c=new Choice(); c.setBounds(100,100, 75,75); c.add("Subject 1"); c.add("Subject 2"); c.add("Subject 3");
  • 39. LISTS • The List class provides a compact, multiple-choice, scrolling selection list. • Unlike the Choice object, which shows only the single selected item in the menu, a List object can be constructed to show any number of choices in the visible Window. • It can also be created to allow multiple selections.
  • 40. LISTS
  • 41. MENU BARS AND MENUS • A top-level window can have a menu bar associated with it. • A menu bar displays a list of top-level menu choices. • Each choice is associated with a drop-down menu. • This concept is implemented in the AWT by the following classes: MenuBar, Menu,and MenuItem.
  • 42. MENU BARS AND MENUS • In general, a menu bar contains one or more Menu objects. Each Menu object contains a list of MenuItem objects. • Each MenuItem object represents something that can be selected by the user. • Since Menu is a subclass of MenuItem, a hierarchy of nested submenus can be created. • It is also possible to include checkable menu items. • These are menu options of type CheckboxMenuItem and will have a check mark next to them when they are selected.
  • 43. MENU BARS AND MENUS
  • 44. MENU BARS AND MENUS
  • 45. • Creating Menubar MenuBar mb=new MenuBar(); • Menu a creation Menu mnu1=new Menu("BCA"); Menu mnu2=new Menu("BBA");
  • 46. • sm1 and sm2 will be treated as submenus Menu sm1=new Menu("Semester"); Menu sm2=new Menu("Year"); • adding items and submenus to menu mnu1.add(sm1); mnu1.add(sm2);
  • 47. • //adding items to submenu sm1.add(i1); sm1.add(i2); sm2.add(i3); • //adding menu to menubar mb.add(mnu1); mb.add(mnu2);
  • 48. • Creating menu items MenuItem i1,i2,i3; i1=new MenuItem("I"); i2=new MenuItem("II"); i3=new MenuItem("2023");
  • 49. DIALOG BOXES • Dialog boxes are primarily used to obtain user input and are often child windows of a top-level window. • Dialog boxes don’t have menu bars, but in other respects, they function like frame windows. (You can add controls to them, for example, in the same way that you add controls to a frame window.) • When a modal dialog box is active, all input is directed to it until it is closed.
  • 50. DIALOG BOXES • This means that you cannot access other parts of your program until you have closed the dialog box. • When a modeless dialog box is active, input focus can be directed to another window in your program. • Thus, other parts of your program remain active and accessible. In the AWT, dialog boxes are of type Dialog
  • 52. FILEDIALOG • Java provides a built-in dialog box that lets the user specify a file. • To create a file dialog box, instantiate an object of type FileDialog. This causes a file dialog box to be displayed. • Usually, this is the standard file dialog box provided by the operating system.
  • 54. HANDLING EVENTS BY EXTENDING AWT COMPONENTS • Handling events by extending AWT components. • The delegation event model was introduced in Event handling, and all of the programs in this book so far have used that design. But Java also allows you to handle events by subclassing AWT components. • Doing so allows you to handle events in much the same way as they were handled under the original 1.0 version of Java. Of course, this technique is discouraged, because it has the same disadvantages of the Java 1.0 event model, the main one being inefficiency.
  • 55. • To extend an AWT component, you must call the enableEvents( ) method of Component. Its general form is shown here: