MSBTE Diploma: Java AWT Chapter 1

NeatestBasilisk avatar
NeatestBasilisk
·
·
Download

Start Quiz

Study Flashcards

14 Questions

What does AWT stand for?

Abstract Window Toolkit

Which Java feature is considered a heavyweight GUI library?

AWT

Containers in AWT GUI are responsible for adding components to the GUI.

True

AWT is a set of native user interface components which are platform-__________.

dependent

Match the following AWT containers with their descriptions:

Window = A container without borders and menu bars Panel = A generic container for holding components without title bar or menu bar Frame = A container with title bar, border, and menu bars Dialog = A container used to display components for user event messages

Which abstract class is the superclass of all menu related classes?

MenuComponent

The most commonly used layout managers are ______.

All of these

Default layout manager for subclasses of window is _____

Gridbag layout

Each menu is associated with a _______ list of menu items.

Drop-down

Which is a component in AWT that can contain other components like buttons, textfields, labels, etc.?

Container

How many types of controls does AWT support?

7

Which is the container that doesn't contain a title bar and menu bars, but can have other components like buttons, text fields, etc.?

Window

Which object can be constructed to show any number of choices in the visible window?

List

By which method can we set or change the text in a label in AWT?

setText()

Study Notes

Abstract Windowing Toolkit (AWT)

  • AWT is a Java API to develop graphical user interface (GUI) or windows-based applications.
  • AWT components are platform-dependent, i.e., they are displayed according to the view of the operating system.
  • AWT is heavy weight, i.e., its components use the resources of the underlying operating system (OS).
  • AWT is a GUI library that provides packages and classes to add graphical components (e.g., buttons, text boxes, check boxes) to applications.

Features of AWT

  • AWT is a set of native user interface components.
  • It is based on a robust event-handling model.
  • It provides graphics and imaging tools, such as shape, color, and font classes.
  • AWT avails layout managers, which help in increasing the flexibility of window layouts.
  • It includes data transfer classes that help in cut-and-paste through the native platform clipboard.

Container in Java

  • A container is a component that holds other components.
  • A container is a subclass of java.awt.Component and is responsible for keeping track of components being added.
  • There are four types of containers:
    • Window: A window with neither border nor title.
    • Frame: A frame with title, border, and menu bars.
    • Dialog: A dialog with border and title.
    • Panel: A generic container for holding GUI components.

AWT Controls

  • java.awt.Button: A labeled button that triggers a certain programmed action upon clicking.
  • java.awt.TextField: A single-line text box for users to enter texts.
  • java.awt.Label: A descriptive text string that is visible on the GUI.
  • java.awt.Canvas: A rectangular area where you can draw or receive user inputs.
  • java.awt.Choice: A pop-up menu of choices.
  • java.awt.ScrollBar: A horizontal and vertical scrollbar in the GUI.
  • java.awt.List: A list of text items.
  • java.awt.CheckBox: A graphical component with two states: true and false.

Layout Managers

  • Layout managers are used to arrange components in a particular manner.
  • There are five types of layout managers:
    • java.awt.BorderLayout: Components are positioned in five different areas (regions): North, South, East, West, and Center.
    • java.awt.FlowLayout: Components are placed from left to right, as they were added.
    • java.awt.GridLayout: Components are placed in a grid of cells (rectangular).
    • java.awt.CardLayout: Manages two or more components that share the same display space, in such a way that only one component is visible at a time.
    • java.awt.GridBagLayout: A flexible layout manager that allows for complex layouts.

Example: Developing a Calculator with Java AWT

  • A calculator application can be developed using AWT components, such as buttons, text fields, and labels.

  • The application can perform basic mathematical operations, such as addition, subtraction, multiplication, and division.### Card Layout Manager

  • Each card is like a playing card in a stack, where only the top card is visible at any time.

  • The Card Layout Manager is used to manage components in a stack.

  • Each card is normally a panel that can use any layout manager.

Flow Layout Manager

  • Example code is provided to illustrate the use of FlowLayout.
  • The FlowLayout is used to arrange components in a row or column.
  • The FlowLayout class is used to create a flow layout manager.

GridBag Layout Manager

  • The GridBag layout manager manages components in rows or columns, allowing specified components to span multiple rows and columns.
  • Not all rows and columns have the same height and width.
  • This is the most complex layout manager, as it specifies the size and position characteristics of its components by specifying constraints for each component.
  • Example code is provided to illustrate the use of GridBagLayout.
  • The MenuItem class adds a simple labeled menu item on a menu.
  • The Menu class is a pull-down menu component that is displayed on the menu bar.
  • Menus are very familiar to programmers in the Windows environment.
  • A menu has a pull-down list of menu items from which the user can select one at a time.
  • A click on the MenuItem generates an ActionEvent and is handled by an ActionListener.
  • A Menu and a MenuItem are not components, as they are not subclasses of the java.awt.Component class.
  • They are derived from the MenuComponent class.
  • The procedure for creating menus involves:
    • Creating a menu bar
    • Adding the menu bar to the frame
    • Creating menus
    • Adding menus to the menu bar
    • Creating menu items
    • Adding menu items to menus
    • Event handling
  • The MenuComponent is the highest level class of all menu classes.
  • A MenuBar is capable of holding menus, and a Menu can hold menu items.
  • Menus are placed on a menu bar.

MCQ Questions

  • The abstract class that is the superclass of all menu-related classes is MenuComponent.
  • The most commonly used layout managers are Flow layout, Border layout, and Grid layout.
  • The default layout manager for subclasses of Window is BorderLayout.
  • Each menu is associated with a drop-down list of menu items.

This quiz covers the basics of Java AWT, including components, containers, and layout managers, specifically for MSBTE diploma students.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Java AWT Controls and Menus Quiz
5 questions
Java AWT and Event Driven Programming Quiz
10 questions
AWT in Java Quiz
5 questions

AWT in Java Quiz

VisionaryPeridot6562 avatar
VisionaryPeridot6562
Use Quizgecko on...
Browser
Browser