This document provides an overview of GUI programming basics using the AWT API in Java. It discusses the key component, container and layout manager classes used to create graphical user interfaces in Java. Component classes like Button, Label and TextField are used to add interactive elements, while container classes like Frame and Panel hold other components. Layout managers help position and organize components visually. The document also provides examples of creating simple frames and applications using these AWT classes.
This document provides information about the Advanced Java Programming course including the teaching and examination scheme, chapter details, and content about Abstract Windowing Toolkit (AWT) and Swings. The teaching scheme covers 5 chapters worth 100 marks total. The first chapter on AWT and Swings is worth 24 marks and covers designing graphical user interfaces using AWT and Swing components, arranging components using different layouts, and details on common AWT classes like Container, Panel, Frame, and controls like Buttons, Checkboxes, and Lists.
AWT stands for Abstract Window Toolkit. AWT is collection of classes and int...Prashant416351
油
AWT stands for Abstract Window Toolkit.
AWT is collection of classes and interfaces.
AWT package contains large number of classes which help to include various graphical components in the java program.
AWT provides a platform-independent and device-independent interface to develop graphic programs that runs on all platforms, including Windows, Mac OS X, and Unixes.
Swing is a Java GUI widget toolkit that improves upon the older AWT toolkit. It includes common GUI components like JFrame, JPanel, and JLabel. JFrame represents a window, JPanel is used to group and layout components, and JLabel displays text. These components have constructors and methods to create, configure, add, and listen to GUI elements. Layout managers automatically position components and should be used for most applications.
This document provides an overview of the Abstract Window Toolkit (AWT) in Java. It discusses AWT components like frames, panels, buttons, checkboxes, lists, text fields, scrollbars and layout managers like flow, border, grid and card layouts. The document also provides examples of creating AWT windows and using various AWT components and layout managers to design graphical user interfaces.
The document discusses the Abstract Window Toolkit (AWT) classes in Java, which allow developers to create graphical user interfaces. It describes key AWT classes like Component, Container, Window, Frame, and Panel. It also covers common AWT controls like labels, buttons, checkboxes, scrollbars, choice boxes, lists, text fields, and text areas. Finally, it briefly introduces layout managers for positioning UI components.
Java AWT (Abstract Windowing Toolkit) is an API for developing GUI applications in Java. It contains components like buttons, text fields, labels etc. that are platform-dependent and heavyweight. The AWT hierarchy includes containers like Frame and Panel that can hold other components. Common methods like add(), setSize() and setLayout() are used to manage components. Event handling in AWT involves implementing listener interfaces, registering components with listeners, and placing event code in the same class, a separate class, or anonymously.
The document discusses the Abstract Window Toolkit (AWT) in Java. Some key points:
- AWT allows developing graphical user interfaces (GUIs) in Java and its components are platform-dependent.
- The AWT class hierarchy includes Component, Container, Window, Panel, Frame, and Dialog classes. Containers hold other components.
- Layout managers determine how components are arranged. Common layouts include flow, grid, border, and card layouts.
This document discusses window fundamentals in Java, including the component, container, panel, window, and frame classes. It explains that component is the base class that defines common attributes, container allows nesting of components, panel is a container without borders, window creates a top-level window, and frame creates a standard application window with title bar and borders. The document also covers basic graphics drawing methods like drawLine, drawRect, drawOval, drawArc and use of color.
The document discusses Java Abstract Window Toolkit (AWT) which provides components to build graphical user interfaces. It describes that AWT components are platform dependent and heavy weight since they are built on top of native OS components. It then discusses the AWT component hierarchy including common components like buttons, text fields and containers like frames and panels that hold components. Specific AWT container types and common methods for working with AWT components are also summarized.
The document discusses different layout managers in Java including FlowLayout, BorderLayout, GridLayout, CardLayout, and GridBagLayout. It explains that layout managers automatically arrange and position components within containers. Each layout manager has a different approach - for example, FlowLayout arranges components line-by-line, BorderLayout has fixed areas on the edges and a flexible center, and GridBagLayout uses a grid with customizable constraints. The document provides details on how each layout manager works and how to implement them.
Java provides two frameworks for building GUI applications: AWT and Swing. AWT (Abstract Window Toolkit) is the older framework and provides platform-dependent components. Swing is more advanced and its components are platform-independent. Both frameworks use containers like frames and panels to hold other components like buttons, text fields, and labels. Applets are Java programs that run in web browsers and extend the Applet class. They have a lifecycle of init(), start(), paint(), stop(), and destroy() methods. Graphics methods like drawString() are used to display graphics in applets. AWT and Swing components can both be used within applets.
This document discusses labels and buttons in Java. It covers adding controls to windows, the different types of controls including labels and buttons, and how to handle button events. Labels are used to display text while buttons generate action events when pressed. The code examples demonstrate how to create labels and buttons, set their text/labels, add them to windows, and handle button press events.
ABSTRACT WINDOW TOOLKIT- AWT CONTROL
WINDOW FUNDAMENTALS
WORKING WITH FRAME WINDOW
LAYOUT MANAGERS
DIALOG CLASS
FILE DIALOG CLASS
MENUS AND MENUBAR
HANDLING EVENTS BY EXTENDING COMPONENTS
AWT (Abstract Window Toolkit) is a collection of classes and methods that allows creation and management of windows. It provides support for applets and contains support for window-based graphical user interfaces. Different window classes defined by AWT add functionality, with Component and Container being the base classes. Layout managers determine how components are arranged in frames using algorithms. Common layout managers include FlowLayout, BorderLayout, and GridLayout. Graphics methods allow for drawing shapes and text to windows.
This document discusses various AWT components in Java including:
1. Canvas - A lightweight component for drawing that does not use a layout manager.
2. Panel - A container that uses FlowLayout by default to organize child components.
3. Frame - A top-level window with a title bar, border, and menu bar that uses BorderLayout by default.
4. Components like Button, Checkbox and other basic controls are also discussed. Event handling, serialization, and best practices for adding components to containers are covered.
brightonSEO - Metehan Yesilyurt - Generative AI & GEO: the new SEO race and h...Metehan Yeilyurt
油
This talk is for SEO experts, consultants, leads, managers, founders and growth marketers
SEO has evolved significantly over the years; when the user first entered the field, tactics like meta keywords and backlink packages were commonplace. With the rapid advancements in AI, their approach to SEO has transformed, necessitating constant adaptation and refinement of techniques.
As tools like Perplexity, SearchGPT emerge, the landscape will shift further with new algorithms, rankings, and optimization strategies, pushing the boundaries of SEO expertise even further.
Metehan is a seasoned Growth Lead with extensive experience in SEO, recognized for driving impactful growth through AI-driven solutions. Known for his unique expertise, he consistently delivers data-backed, effective organic growth strategies.
This document provides information about the Advanced Java Programming course including the teaching and examination scheme, chapter details, and content about Abstract Windowing Toolkit (AWT) and Swings. The teaching scheme covers 5 chapters worth 100 marks total. The first chapter on AWT and Swings is worth 24 marks and covers designing graphical user interfaces using AWT and Swing components, arranging components using different layouts, and details on common AWT classes like Container, Panel, Frame, and controls like Buttons, Checkboxes, and Lists.
AWT stands for Abstract Window Toolkit. AWT is collection of classes and int...Prashant416351
油
AWT stands for Abstract Window Toolkit.
AWT is collection of classes and interfaces.
AWT package contains large number of classes which help to include various graphical components in the java program.
AWT provides a platform-independent and device-independent interface to develop graphic programs that runs on all platforms, including Windows, Mac OS X, and Unixes.
Swing is a Java GUI widget toolkit that improves upon the older AWT toolkit. It includes common GUI components like JFrame, JPanel, and JLabel. JFrame represents a window, JPanel is used to group and layout components, and JLabel displays text. These components have constructors and methods to create, configure, add, and listen to GUI elements. Layout managers automatically position components and should be used for most applications.
This document provides an overview of the Abstract Window Toolkit (AWT) in Java. It discusses AWT components like frames, panels, buttons, checkboxes, lists, text fields, scrollbars and layout managers like flow, border, grid and card layouts. The document also provides examples of creating AWT windows and using various AWT components and layout managers to design graphical user interfaces.
The document discusses the Abstract Window Toolkit (AWT) classes in Java, which allow developers to create graphical user interfaces. It describes key AWT classes like Component, Container, Window, Frame, and Panel. It also covers common AWT controls like labels, buttons, checkboxes, scrollbars, choice boxes, lists, text fields, and text areas. Finally, it briefly introduces layout managers for positioning UI components.
Java AWT (Abstract Windowing Toolkit) is an API for developing GUI applications in Java. It contains components like buttons, text fields, labels etc. that are platform-dependent and heavyweight. The AWT hierarchy includes containers like Frame and Panel that can hold other components. Common methods like add(), setSize() and setLayout() are used to manage components. Event handling in AWT involves implementing listener interfaces, registering components with listeners, and placing event code in the same class, a separate class, or anonymously.
The document discusses the Abstract Window Toolkit (AWT) in Java. Some key points:
- AWT allows developing graphical user interfaces (GUIs) in Java and its components are platform-dependent.
- The AWT class hierarchy includes Component, Container, Window, Panel, Frame, and Dialog classes. Containers hold other components.
- Layout managers determine how components are arranged. Common layouts include flow, grid, border, and card layouts.
This document discusses window fundamentals in Java, including the component, container, panel, window, and frame classes. It explains that component is the base class that defines common attributes, container allows nesting of components, panel is a container without borders, window creates a top-level window, and frame creates a standard application window with title bar and borders. The document also covers basic graphics drawing methods like drawLine, drawRect, drawOval, drawArc and use of color.
The document discusses Java Abstract Window Toolkit (AWT) which provides components to build graphical user interfaces. It describes that AWT components are platform dependent and heavy weight since they are built on top of native OS components. It then discusses the AWT component hierarchy including common components like buttons, text fields and containers like frames and panels that hold components. Specific AWT container types and common methods for working with AWT components are also summarized.
The document discusses different layout managers in Java including FlowLayout, BorderLayout, GridLayout, CardLayout, and GridBagLayout. It explains that layout managers automatically arrange and position components within containers. Each layout manager has a different approach - for example, FlowLayout arranges components line-by-line, BorderLayout has fixed areas on the edges and a flexible center, and GridBagLayout uses a grid with customizable constraints. The document provides details on how each layout manager works and how to implement them.
Java provides two frameworks for building GUI applications: AWT and Swing. AWT (Abstract Window Toolkit) is the older framework and provides platform-dependent components. Swing is more advanced and its components are platform-independent. Both frameworks use containers like frames and panels to hold other components like buttons, text fields, and labels. Applets are Java programs that run in web browsers and extend the Applet class. They have a lifecycle of init(), start(), paint(), stop(), and destroy() methods. Graphics methods like drawString() are used to display graphics in applets. AWT and Swing components can both be used within applets.
This document discusses labels and buttons in Java. It covers adding controls to windows, the different types of controls including labels and buttons, and how to handle button events. Labels are used to display text while buttons generate action events when pressed. The code examples demonstrate how to create labels and buttons, set their text/labels, add them to windows, and handle button press events.
ABSTRACT WINDOW TOOLKIT- AWT CONTROL
WINDOW FUNDAMENTALS
WORKING WITH FRAME WINDOW
LAYOUT MANAGERS
DIALOG CLASS
FILE DIALOG CLASS
MENUS AND MENUBAR
HANDLING EVENTS BY EXTENDING COMPONENTS
AWT (Abstract Window Toolkit) is a collection of classes and methods that allows creation and management of windows. It provides support for applets and contains support for window-based graphical user interfaces. Different window classes defined by AWT add functionality, with Component and Container being the base classes. Layout managers determine how components are arranged in frames using algorithms. Common layout managers include FlowLayout, BorderLayout, and GridLayout. Graphics methods allow for drawing shapes and text to windows.
This document discusses various AWT components in Java including:
1. Canvas - A lightweight component for drawing that does not use a layout manager.
2. Panel - A container that uses FlowLayout by default to organize child components.
3. Frame - A top-level window with a title bar, border, and menu bar that uses BorderLayout by default.
4. Components like Button, Checkbox and other basic controls are also discussed. Event handling, serialization, and best practices for adding components to containers are covered.
brightonSEO - Metehan Yesilyurt - Generative AI & GEO: the new SEO race and h...Metehan Yeilyurt
油
This talk is for SEO experts, consultants, leads, managers, founders and growth marketers
SEO has evolved significantly over the years; when the user first entered the field, tactics like meta keywords and backlink packages were commonplace. With the rapid advancements in AI, their approach to SEO has transformed, necessitating constant adaptation and refinement of techniques.
As tools like Perplexity, SearchGPT emerge, the landscape will shift further with new algorithms, rankings, and optimization strategies, pushing the boundaries of SEO expertise even further.
Metehan is a seasoned Growth Lead with extensive experience in SEO, recognized for driving impactful growth through AI-driven solutions. Known for his unique expertise, he consistently delivers data-backed, effective organic growth strategies.
A key metric for current SaaS companies is Weekly Active Users. Its also a dangerous one because the graph we use to represent it, even when it looks up and to the right, can be hiding a growth ticking bomb.
This bomb is the byproduct of how we think and how we try to improve Activation, that stage that goes from Signup to happy loyal user.
In this talk, you will learn a new way to think about Activation:
- What are the users trying to achieve during this period?
-
- What is blocking them in their journey to happy users?
- How can you solve the blockers without creating bigger problems down the funnel?
- How to measure all of that so you have an accurate depiction of your current activation.
In the era of big data and AI, ethical data handling is no longer optionalit's essential. This presentation explores the core principles of data ethics, data privacy regulations (like GDPR), consent, bias, and the responsibilities analysts must uphold. Learn how to protect users and build trust through responsible data practices.
Turinton Insights - Enterprise Agentic AI Platformvikrant530668
油
Enterprises Agentic AI Platform that helps organization to build AI 10X faster, 3X optimised that yields 5X ROI. Helps organizations build AI Driven Data Fabric within their data ecosystem and infrastructure.
Enables users to explore enterprise-wide information and build enterprise AI apps, ML Models, and agents. Maps and correlates data across databases, files, SOR, creating a unified data view using AI. Leveraging AI, it uncovers hidden patterns and potential relationships in the data. Forms relationships between Data Objects and Business Processes and observe anomalies for failure prediction and proactive resolutions.
SQL (Structured Query Language) is the foundation of data analytics. If you're an aspiring analyst, data scientist, or business intelligence professional, mastering SQL is non-negotiable. In this presentation, youll discover the top 10 most essential SQL queries used by professionals in real-world scenarios. From SELECT and WHERE statements to powerful JOINs, aggregations (GROUP BY, SUM, COUNT), and subqueries, this crash course will teach you how to extract actionable insights from large datasets. Learn to solve practical data problems and make data-driven decisions with confidencewithout needing a CS degree. Whether you're working with MySQL, PostgreSQL, or SQL Server, these query patterns will give you a strong, job-ready foundation in analytics.
The rise of AI Agents - Beyond Automation_ The Rise of AI Agents in Service ...Yasen Lilov
油
Deep dive into how agency service-based business can leverage AI and AI Agents for automation and scale. Case Study example with platforms used outlined in the slides.
Social Media Trends in Bangladesh - A Data-Driven Analysis for 2025.pdfNgital
油
Navigate the future of social media in Bangladesh with this comprehensive, data-driven research report. Prepared by Tajul Islam, the visionary Founder of Ngital Limited, a leading digital marketing agency based in Bangladesh, this analysis offers invaluable insights into the evolving social media landscape of the nation as we approach 2025. 油
In today's rapidly changing digital world, understanding the nuances of social media trends is crucial for businesses, marketers, and anyone seeking to connect with the Bangladeshi audience. This report delves deep into the key shifts and emerging patterns that will define social media usage and engagement across the country. 油
Inside this report, you will discover:
In-depth analysis of popular and emerging social media platforms in Bangladesh: Understand which platforms are gaining traction, their demographics, and their unique strengths for reaching different segments of the population.
Data-backed predictions for user behavior and engagement: Gain insights into how Bangladeshi users are expected to interact with social media content, including preferred formats, content consumption habits, and peak engagement times.
Identification of key content trends and emerging formats: Stay ahead of the curve by understanding the types of content that will resonate most with the Bangladeshi audience in 2025, from video marketing and influencer collaborations to interactive experiences and short-form content.
Analysis of the impact of technological advancements: Explore how factors like increasing internet penetration, mobile technology adoption, and the rise of new technologies will shape social media trends in Bangladesh.
Actionable insights for businesses and marketers: Equip yourself with practical strategies and recommendations to effectively leverage social media for brand building, customer engagement, lead generation, and achieving your marketing objectives in the Bangladeshi market. 油
Expert perspectives from a leading digital marketing agency: Benefit from the real-world experience and data-driven approach of Ngital Limited, a trusted partner for businesses seeking digital success in Bangladesh. 油
Statistics for Management - standard deviation.pptxJeya Sree
油
Steel rods are manufactured to be 3 inches in diameter, but they are acceptable if they are inside the limits of 2.99 inches and 3.01 inches. It is observed that 5% are rejected as oversize and 5% are rejected as undersize. Assuming that the diameters are normally distributed, how will you find the standard deviation of the distribution. Further how will you find the proportion of rejects would be, if the permissible limits were widened to 2.985 to 3.015 inches? Explain
Z-Table is used.
2. Introduction to AWT
AWT Classes
The AWT classes are contained in the java.awt package.
Window Fundamentals
AWT defines windows according to a class hierarchy that adds
functionality & specificity in each level.
The two most common windows are
those derived from Panel
those derived from Frame
3. The following fig. shows the class hierarchy for Panel and Frame
Component
Container
Window Panel
Frame Applet
4. Component
All user interface elements that are displayed on the screen and that
interact with the user are subclasses of Component.
Responsible for managing events, such as mouse and keyboard input,
positioning and sizing the window, and repainting.
Container
subclass of Component
Responsible for laying out(i.e. positioning) any components that it
contain.
It does this through the use of various layout managers.
5. Panel
Concrete subclass of Container.
No new methods; it simply implements Container.
Panel is the superclass for Applet.
Panel is a window that does not contain a title bar, menu bar or
border. (AppletViewer provides this; browser wont)
Components can be added to a Panel object by its add( )
method.
Once added, they can be positioned and resized manually using the
setLocation( ), setSize( ), or setBounds( ) methods defined by
Component.
6. Window
creates top-level window.
Window objects generally are not created directly; instead we will use a
subclass of Window called Frame.
Frame
subclass of Window and has a title bar, menu bar, border and resizing
corners.
Frame object can be created from within an applet window
it will contain a message Java Applet Window
When a Frame window is created by a program ; a normal window is
created.
Canvas
not part of hierarchy.
Canvas encapsulates a blank window upon which you can draw.
7. Commonly Used Methods of Component Class
setBackground(): used to change the background color of a component.
public void setBackground ( Color c)
Note: color is a helper class.
setForeground(): used to change the foreground color of a
component.
public void setForeground ( Font obj)
Font is represented by java.awt.Font.
public Font (String FontName, int Style, int Size)
e.g. : Font f = (Times New Roman, Font.BOLD, 20);
setBounds(): used to specify size and position of component in a container.
public void setBounds (int left, int top, int width, int height)
8. Commonly used methods of Container
Class
add(): used to add components to a container.
public void add (Component c)
setSize(): used to specify the size of a container.
public void setSize(int width, int height)
setLayout(): used to specify the layout manager for a container.
public void setLayout (LayoutManager mgr)
setVisible(boolean visibility): used to set the visibility of
container.
public void setVisible (boolean visibility)
9. Working with Frame
Windows
Frames Constructors
Frame( )
creates a standard window that does not contain a title.
Frame(String title)
creates a window with the title specified by title.
Setting the Windows Dimensions
void setSize(int newWidth, int newHeight)
void setSize(Dimension newSize)
set the dimensions of the window
Dimension getSize( )
obtain the current size of a window
10. Hiding and Showing a Window
After a frame window has been created, it will not be visible until you
call setVisible( )
void setVisible(boolean visibleFlag)
-> visible if true otherwise hidden
Setting a Windows Title
void setTitle(String newTitle)
Closing a Frame Window
Remove window from the screen by calling setVisible(false), when it is
closed.
If Frame window is a child window, to intercept window-close event,
implement windowClosing( ) method of the WindowListener interface.
Inside windowClosing( ), remove the window from the screen.
11. import java.awt.Frame;
public class SampleFrame extends Frame {
SampleFrame(String title) {
super( );
this.setTitle(title);
this.setSize(300,200);
this.setVisible(true);
}
public static void main(String args[
]) {
SampleFrame sf = new
SampleFrame(My
Window);
12. Layout managers
Each Container object has a layout manager associated with it.
A layout manager is an instance of any class that implements the
LayoutManager interface.
The layout manager is set by the setLayout( ) method.
If no call to setLayout( ) is made, then the default layout manager is
used.
The setLayout( ) method has the following form
void setLayout(LayoutManager layoutObj)
layoutObj -> reference to the
desired layout manager
Java has several predefined LayoutManager
classes.
13. FlowLayout
FlowLayout is the default layout manager.
FlowLayout implements a simple layout style, which is similar to how
words flow in a text editor.
direction -> by default it is left to right, top to bottom
By default, components are laid out line-by-line beginning at the upper-left
corner.
A small space is left between each component, above and below, as well as
left and right.
Constructors
FlowLayout( ) -> creates the default layout, which centers components
and leaves 5 pixels of space between each component.
14. FlowLayout(int how)
-> valid values for how are as follows:
FlowLayout.LEFT
FlowLayout.CENTER
FlowLayout.RIGHT
FlowLayout.LEADING
FlowLayout.TRAILING
FlowLayout(int how, int horz, int vert)
-> horz and vert allows to specify the horizontal and vertical
space between components
15. BorderLayout
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
Constructors
BorderLayout( ) -> default border layout
BorderLayout(int horz, int vert)
16. When adding components to border layout, call the following add( )
method
void add(Component compObj, Object region)
compObj component to be added
region specifies where the component will
be added
BorderLayout defines the following constants that specify the regions
BorderLayout.CENTER
BorderLayout.SOUTH
BorderLayout.EAST
BorderLayout.WEST
BorderLayout.NORTH
18. GridLayout
GridLayout lays out components in a two-dimensional grid.
Constructors
GridLayout( ) creates a single-column grid layout
GridLayout(int numRows, int numColumns)
-> creates a grid layout with the specified number of rows and
columns
GridLayout(int numRows, int numColumns, int horz, int vert)
Specifying numRows as zero allows for unlimited-length columns
Specifying numColumns as zero allows for unlimited-length rows
20. CardLayout
It is used to arrange containers in the form of deck of cards.
Methods:
first() / last()/ next()/ previous(): is used to make the first/
last/ next/ previous card visible.
show(): is used to make a specified card visible.
public void show ( Container deck, String CardName)
To give a name to the container while it is added to the
deck:
public void add ( Container card, String CardName)
21. AWT
Controls
The AWT supports the following types of controls
Labels
Push Buttons
Check boxes
Choice lists
Lists
Scroll bars
Text editing
-> subclasses of Component
22. Adding and Removing Controls
To add a control to a window
first create an instance of the desired control.
then add it to a window by calling add(
) Component add(Component
compObj)
compObj -> instance of the
control to add
To remove a control
void remove(Component obj)
obj -> control to be removed
removeAll( ) -> to remove all controls
Except for labels, which are passive controls, all controls generate
events when they are accessed by user.
Example
23. Label
s
A label is an object of type Label, and it contains a string which it
displays.
Passive controls do not support any interaction with the user.
Label defines the following constructors
Label( )
Label(String str) string is left-justified
Label(String str, int how)
- alignment specified by how
- value of how must be one of
the 3 constants
- Label.LEFT, Label.RIGHT,
Label.CENTER
24. To set or change the text in a label, use the setText( ) method.
void setText(String str)
To obtain the current label, call getText( )
String getText( )
To set the alignment of the string within the label, call setAlignment( )
void setAlignment(int how)
To obtain the current alignment, call getAlignment( )
int getAlignment( )
Example
25. Button
s
A push button is a component that contains a label and that
generates an event when it is pressed.
Push buttons are objects of type Button.
Button defines these two constructors
Button( )
Button(String str) contains str
as a label
To set the label of a button, call
setLabel( ) void setLabel(String str)
To retrieve the label of a button, call
getLabel( ) String getLabel( )
26. 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.
Check boxes can be used individually or as part of a group.
Check boxes are objects of the Checkbox class.
Checkbox supports these constructors
Checkbox( ) label is initially blank; state of the checkbox is
unchecked.
Checkbox(String str) label is specified by str; state of the
checkbox is unchecked.
27. Checkbox(String str, boolean on)
- if on is true, the checkbox is initially checked;
otherwise cleared.
Checkbox(String str, boolean on, CheckboxGroup cbGroup)
- group is specified by cbGroup; if this checkbox is not
part of a group, then cbGroup must be null.
Checkbox(String str, CheckboxGroup cbGroup, boolean on)
To retrieve the current state of a checkbox, call getState( )
boolean getState( )
To set the state of a checkbox, call setState( ):
void setState(Boolean on)
To obtain the current label associated with a checkbox, call getLabel( )
String getLabel( )
28. CheckboxGroup
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 check boxes are often called radio buttons.
To create a set of mutually excusive check boxes, first define the
group to which they will belong and then specify that group when
constructing the checkboxes.
Check box groups are objects of type CheckboxGroup
Only default constructor CheckboxGroup( ) -> creates an empty
group.
29. To determine which checkbox in a group is currently selected, call
getSelectedCheckbox( )
Checkbox getSelectedCheckbox( )
To set a check box, call setSelectedCheckbox( )
void setSelectedCheckbox(Checkbox which)
which -> checkbox that has to be selected; previously
selected check box will be turned off
Example
30. 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 only defines the default constructor, which creates an empty
list.
To add a selection to the list, call add( ). Items are added to the list in the
order in which calls to add( ) occur.
void add(String name)
31. To determine which item is currently selected, call getSelectedItem( ) or
getSelectedIndex( )
String getSelectedItem( )
-> returns a string containing the name of the item
int getSelectedIndex( )
-> returns the index of the item. The first item is at index 0
To obtain the number of items in the list, call getItemCount( )
int getItemCount( )
To set the currently selected item with either a zero-based index or a string that will
match a name in the list, call select( )
void select(int index)
void select(String name)
To obtain the name
associated with the item at
an index, call getItem( )
32. Lists
The List class provides a compact, multiple-choice, scrolling selection list.
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.
List provides 3 constructors
List( ) creates a List control that allows only one item to be
selected at any one time.
List(int numRows) numRows specifies the number of entries in
the list that will always be visible.
List(int numRows, boolean multipleSelect) if multipleSelect is true,
then the user may select two or more items at a
time. If it is false, only one item may be
selected.
33. To add a selection to the list, call add( )
void add(String name) name is the name of the item added to the list.
void add(String name, int index) adds the item at the index specified
by index.
For lists that allow only single selection, to determine which item is currently
selected, call getSelectedItem( ) or getSelectedIndex( )
For lists that allow multiple selection, call getSelectedItems( ) or
getSelectedIndexes( )
String[ ] getSelectedItems( )
int[ ] getSelectedIndexes( )
34. TextFields
The TextField class implements a single-line text-entry area, usually called
an edit control.
TextField is a subclass of TextComponent.
TextField defines the following constructors
TextField( ) creates a default text field
TextField(int numChars) creates a text
field that is numChars wide.
TextField(String str) initializes the text
field with the string contained
in str.
TextField(String str, int numChars)
35. To obtain the string currently contained in the text field, call getText( )
String getText( )
To set the text, call setText( )
void setText(String str) str is the new string
To select a portion of the text in a text field, call
select( )
void select(int startIndex, int endIndex)
- selects the characters beginning at
startIndex and ending at
endIndex 1
To obtain the currently selected text, call getSelectedText( )
String getSelectedText( )
36. To control whether the contents of a text field may be modified by the
user or not, call setEditable( )
void setEditable(boolean canEdit)
- if canEdit is true, the text may be changed. If
it is false, the text cannot be altered.
To determine the editability, call isEditable( )
boolean isEditable( )
- returns true if the text may be changed and false if not.
37. To disable the echoing of characters as they are typed(eg.while typing
passwords), call setEchoChar( ) method.
void setEchoChar(char ch)
- ch specifies the character to be echoed.
To check a text field to see if it is in this mode, call echoCharIsSet( )
method.
boolean echoCharIsSet( )
To retrieve the echo character, call getEchoChar( ) method.
char getEchoChar( )
Example
38. TextAre
a
Sometimes, a single line of text input is not enough for a given task. to
handle these situations, the AWT includes a multiline editor called
TextArea.
Constructors
TextArea( )
TextArea(int numLines, int numChars)
-> numLines specifies the height, in lines, of the text area
-> numChars specifies its width, in characters.
TextArea(String str)
-> initial text can be specified by str
39. TextArea(String str, int numLines, int numChars)
TextArea(String str, int numLines, int numChars, int sBars)
-> sBars specify the scroll bars. sBars must be one of these
values
SCROLLBARS_BOTH
SCROLLBARS_NONE
SCROLLBARS_HORIZONTAL_ONLY
SCROLLBARS_VERTICAL_ONLY
TextArea is a subclass of TextComponent.
It supports the getText( ), setText( ), getSelectedText( ), select,
isEditable( ), and setEditable( )
40. TextArea adds the following methods
void append(String str)
-> appends the string specified by str to the end of the
current text.
void insert(String str, int index)
-> inserts the string passed in str at the specified index.
void replaceRange(String str, int startIndex, int endIndex)
-> replaces the characters from startIndex to
endIndex -1,
with the replacement text passed in str.
41. Scroll Bar
Scroll bars are used to select continuous values between
a specified minimum and maximum.
Scroll bars may be oriented horizontally or vertically.
Scrollbar defines the following constructors:
Scrollbar( ) throws HeadlessException
Scrollbar(int style) throws HeadlessException
Scrollbar(int style, int initialValue, int thumbSize, int min,
int max) throws HeadlessException
42. Continue
If style is Scrollbar.VERTICAL, a vertical scroll bar is
created.
If style is Scrollbar.HORIZONTAL the scroll bar is
horizontal.
the height of the thumb is passed in thumbSize.
The minimum and maximum values for the scroll bar are
specified by min and max.
43. Method
void setValues(int initialValue, int thumbSize, int min, int
max)
int getValue( )
void setValue(int newValue)
int getMinimum( )
int getMaximum( )
void setUnitIncrement(int newIncr) //scroll line up and
down
void setBlockIncrement(int newIncr) //scroll page-up and
down
44. Menu Bars and Menus
Menu is implemented in AWT by the following classes: MenuBar,
Menu, and MenuItem.
A menu bar displays a list of top-level menu choices. Each choice is
associated with a drop-down menu.
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.
Checkable menu items are menu options of type
CheckboxMenuItem and will have a check mark next to them when
they are selected
45. Creating Menu
To create a menu bar, first create an instance of MenuBar.
This class only defines the default constructor.
public MenuBar()
setMenuBar() method is used to add menubar on window.
Next, create instances of Menu that will define the selections
displayed on the bar. Following are the constructors for
Menu:
Menu( ) throws HeadlessException
Menu(String optionName) throws HeadlessException
46. Menu(String optionName, boolean removable) throws
HeadlessException
Individual menu items are of type MenuItem. It defines these
constructors:
MenuItem( ) throws HeadlessException
MenuItem(String itemName) throws HeadlessException
MenuItem(String itemName, MenuShortcut keyAccel) throws
HeadlessException
47. Methods
We can disable or enable a menu item by using the setEnabled( )
method.
void setEnabled (boolean enabledFlag)
If the argument enabledFlag is true, the menu item is enabled. If false,
the menu item is disabled.
We can determine an items status by calling isEnabled( ).
boolean isEnabled( )
isEnabled( ) returns true if the menu item on which it is called is
enabled. Otherwise, it returns false.
We can change the name of a menu item by calling setLabel( ).
We can retrieve the current name by using getLabel( ).
void setLabel(String newName)
String getLabel( )
49. Example
item2 = new MenuItem("Open...");
item3 = new MenuItem("Close");
item4 = new MenuItem("-");
item5 = new MenuItem("Quit...");
// add menu items on menu
file.add(item1); file.add(item2);
file.add(item3); file.add(item4);
file.add(item5);
// add menu on menubar mbar.add(file);
}
Public static void main(String arg[]) {
MenuDemo md=new MenuDemo();
md.setVisible(true);
md.setTitle(Menu);
md.setSize(400,400);
}
Import java.awt.*;
Class MenuDemo extends
Frame
{
MenuDemo()
{
MenuBar mbar = new
MenuBar();
setMenuBar(mbar);
// create the menu and menu
items
Menu file = new Menu("File");
MenuItem item1, item2, item3,
item4, item5;
item1 = new MenuItem
("New...");
50. Dialog Boxes
Dialog boxes are primarily used to obtain user input and are
often child windows of a top-level window.
Dialog boxes dont 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.
Dialog boxes are of type Dialog
Dialog(Frame parentWindow, boolean mode)
Dialog(Frame parentWindow, String title, boolean mode)
parentWindow is the owner of the dialog box.
51. Continue..
Dialog boxes may be modal or modeless.
When a modal dialog box is active, all input is directed to it
until it is closed. 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.
52. Example
Create subclass of Dialog
class
Class DemoDialog extends
Dialog{
DemoDialog(Frame par,
String title)
{
Button b1= new Button
(ok); add(b1);
setSize(300,100);
setVisible(true);
}
}
Class Fdemo extends Frame{
Fdemo()
{
setSize(300,400);
}
Public static void main (String
arg[])
{
Fdemo fd=new Fdemo();
Fd.setVisible(true);
DemoDialog dd=new
DemoDialog(fd,First Dialog);
}
53. File Dialog
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 constructors:
FileDialog(Frame parent)
FileDialog(Frame parent, String boxName)
FileDialog(Frame parent, String boxName, int how)
54. If how is FileDialog.LOAD, then the box is selecting a file for
reading.
If how is FileDialog.SAVE, the box is selecting a file for writing. If
how is omitted, the box is selecting a file for reading.
FileDialog provides methods that allow you to determine the
name of the file and its path as selected by the user. Here are
two examples:
String getDirectory( )
String getFile( )