Advanced Java Programming · Unit 3
GUI Programming with AWT and Swing
Exam-focused notes for GUI Programming with AWT and Swing (Advanced Java Programming, BIT401): what the TU syllabus asks and how it has actually been tested, with 11 solved past questions from this unit.
What this unit covers
- Components and containers
- Layout managers: flow layout, grid layout, border layout
- Event handling and action commands
- Button and label widgets
- Text boxes and text fields
- Menu items with mnemonics and accelerators
- Mouse events and keyboard events
- JPanel usage and customization
Layout managers
Distinguish between component and containers. What do you mean by keyboard mnemonics and accelerators? Illustrate the concept of Grid layout with an example.[10]
Components: - Basic building blocks of GUI applications - Lightweight objects that represent visual elements - Examples: JButton, JLabel, JTextField, JCheckBox, JRadioButton - Cannot contain other components - Directly display information or accept user inp...
Full solved answer →What is layout manager? Explain working of flow layout with example. [5]
A layout manager is a component in Java GUI programming that automatically arranges and positions components (like buttons, labels, text fields) within a container. It controls the size and position of components based on predefined rules, eliminating the n...
Full solved answer →Discuss working of grid layout with example. [5]
Grid layout is a CSS-based two-dimensional layout system that allows developers to create complex, responsive web page layouts by dividing the page into rows and columns, forming a grid of cells where content can be placed. - A grid container is created by ...
Full solved answer →Text boxes and text fields
Design a form that contains two text fields and two buttons with caption 'OK' and 'CANCEL' using AWT. [5]
Component Purpose -------------------- Frame Container window for the form TextField Input fields for user data (2 fields) Button Clickable buttons with captions 'OK' and 'CANCEL' FlowLayout Arranges components in a row ActionListener Handles button click e...
Full solved answer →Write a Java program to create a UI with three labels and three text boxes for First Number, Second Number and Result. Also put Four buttons (Add, Subtract, Multiply, and Divide) in the form and handle the event accordingly.[10]
Feature Description ---------------------- JFrame Main window container JLabel Display text labels for input fields JTextField Input fields for numbers; result field is non-editable JButton Four operation buttons ActionListener Interface to handle button cl...
Full solved answer →Write a java program to create a UI with four labels and three text boxes for Principal, Time, Rate, and Interest. Also put two buttons "Simple Interest" and Reset in the form and handle the event accordingly.[10]
Key Components: 1. Labels (4): Display field names for Principal, Time, Rate, and Interest 2. Text Boxes (3): Input fields for Principal, Time, and Rate; Interest field is read-only 3. Buttons (2): - "Simple Interest": Calculates SI using formula SI = (P × ...
Full solved answer →Mouse events and keyboard events
Write a program to illustrate the concept of Mouse Events. [5]
Event Type Method Description -------------------------------- Mouse Click mouseClicked() Triggered when mouse button is clicked Mouse Press mousePressed() Triggered when mouse button is pressed down Mouse Release mouseReleased() Triggered when mouse button...
Full solved answer →Write a program to show the use of mouse event. [5]
Since reference notes are not provided, this answer follows standard web-based mouse event handling appropriate for BSc CSIT curriculum. Event Description -------------------- mouseover Triggered when mouse pointer enters element mouseout Triggered when mou...
Full solved answer →Menu items with mnemonics and accelerators
When do we use JPanel? How do you add mnemonics and accelerators to menu items? Explain.[10]
JPanel is a lightweight container component in Java Swing used in the following scenarios: 1. Organizing Components: JPanel groups related GUI components together logically. For example, grouping buttons, text fields, or labels that form a functional unit. ...
Full solved answer →Event handling and action commands
Write a program to design a form with a button and label, such that the number of times the button is clicked will be displayed in label. [5]
Key Components: 1. Window Creation: tk.Tk() creates the main application window with title and size. 2. Global Counter: clickcount variable stores the number of button clicks. 3. Click Handler Function: onbuttonclick() function: - Increments the counter by ...
Full solved answer →What is action command? How it is used in java programs? Explain with example. [5]
An action command is a string that identifies or labels an action event in Java. It is associated with components like buttons, menu items, and text fields to distinguish between different user actions and determine what operation should be performed when a...
Full solved answer →Make Unit 3 stick
Practice BIT401 with flashcards & quizzes