Advanced Java Programming · Unit 2 · 10 hrs
User Interface Components with Swing
Exam-focused notes for User Interface Components with Swing (Advanced Java Programming, CSC419): what the TU syllabus asks and how it has actually been tested, with 14 solved past questions from this unit.
What this unit covers
- Introduction: Concept of AWT, AWT vs Swing, Java Applets, Applet Life Cycle, Swing Class Hierarchy, Component and Containers
- Layout Management: No Layout, Flow layout, Border Layout, Grid Layout, Gridbag Layout, Group Layout
- GUI Controls: Text Fields, Password Fields, Text Areas, Scroll Pane, Labels, Check Boxes, Radio Buttons, Borders, Combo Boxes, Sliders
- Menu, Menu Item, Icons in Menu Items, Check Box and Radio Buttons in Menu Items, Pop-up Menus, Keyboard Mnemonics and Accelerators, Enabling and Disabling Menu Items, Toolbars, Tooltips
- Option Dialogs, Creating Dialogs, File Choosers, Color Choosers, Internal Frames, Frames, Tables, Trees, and Tables
GUI Controls
What are the tasks of sliders and scroll pane? Explain any four types of layout manager.[10]
--- A Slider is a GUI component that allows the user to select a numeric value by sliding a knob (thumb) along a track between a defined minimum and maximum value. Tasks of Sliders: - Allow the user to select a value from a continuous or discrete range of v...
Full solved answer →Design a simple form that takes name, password, hobbies and gender as input. [5]
The form below collects name, password, hobbies (multiple values using checkboxes), and gender (using radio buttons). Since password is sensitive data, the POST method is used. --- --- Field Input Type Servlet Method Used Reason ----------------------------...
Full solved answer →Why do we need swing components? Explain the uses of check boxes and radio buttons in GUI programming. [5]
--- Java Swing is part of the Java Foundation Classes (JFC) used to create window-based (GUI) applications. It is built on top of AWT (Abstract Windowing Toolkit) and is entirely written in Java. We need Swing components because of the following advantages ...
Full solved answer →Design a GUI form using swing with a text field, a text label for displaying the input message 'Input any String', and three buttons with caption CheckPalindrome, Reverse, FindVowels. Write a complete program for above scenario and for checking palindrome in first button, reverse it after clicking second button and extract the vowels from it after clicking third button.[10]
--- Input String Button Clicked Output Displayed --------- madam CheckPalindrome "madam" is a Palindrome hello CheckPalindrome "hello" is NOT a Palindrome hello Reverse Reversed String: olleh hello FindVowels Vowels in "hello": e o (Count = 2) --- - Extends...
Full solved answer →Menu, Menu Item, Icons in Menu Items, Check Box and Radio Buttons in Menu Items, Pop-up Menus, Keyboard Mnemonics and Accelerators, Enabling and Disabling Menu Items, Toolbars, Tooltips
How do you insert pop-up menu? Distinguish between GET and POST request. [5]
--- In Java AWT, the Choice class is used to create a pop-up menu (combo box). The object of the Choice class shows a pop-up menu of choices, and the choice selected by the user is shown on the top of the menu. 1. Create a Choice object 2. Add items using a...
Full solved answer →Write a program to create a menu named 'File' with menu items 'New', 'Save,' and 'Exit'. [5]
In Java Swing, menus are created using: - JMenuBar - the menu bar that holds menus - JMenu - a single menu (e.g., "File") - JMenuItem - individual items inside a menu (e.g., "New", "Save", "Exit") - ActionListener - to handle click events on menu items --- ...
Full solved answer →Layout Management
Describe any two types of Layout manager. Using swing components, design a form with three buttons with captions 'RED,' 'BLUE,' and 'GREEN,' respectively. Then write a program to handle the event such that when the user clicks the button, the color of that button will be the same as its caption.[10]
FlowLayout is the default layout manager for JPanel. It arranges components in a left-to-right flow, much like lines of text in a paragraph. When one row is filled, it starts a new row. Key features: - Components are placed in a row from left to right - Whe...
Full solved answer →Why do we need layout management? Explain any two layout managers with example. Write a simple GUI program that displays 'Hello World' in a text field. The program should display output if user clicks a button.[10]
Layout management is needed to automatically arrange and position GUI components (buttons, text fields, labels, etc.) within a container (like JFrame or JPanel). Without a layout manager, we would have to manually specify the exact pixel coordinates of ever...
Full solved answer →What is grid layout? Compare grid layout with grid bag layout. [5]
Grid Layout is a layout manager in Java that arranges components in a rectangular grid of rows and columns. Every cell in the grid has the same size, and each component is placed in one cell, filling the entire cell. Components are added to the grid from le...
Full solved answer →What is the task of Layout manager? Describe about default layout manager. [5]
A Layout Manager is responsible for controlling the size and position (arrangement) of components placed inside a container. The main tasks of a layout manager are: - Positioning components within a container automatically - Determining the size of each com...
Full solved answer →Why do we need layout management? What is GridBag layout? [5]
In Java, when we build a GUI application, we place multiple components (buttons, labels, text fields, etc.) inside a container (like a Frame or Panel). Layout management is needed for the following reasons: 1. Platform Independence: Java runs on different o...
Full solved answer →Write short notes on: a. Grid Layout b. Ragged Array [2.5+2.5]
--- GridPane (Grid Layout in JavaFX) is a layout manager that arranges nodes in a flexible grid of rows and columns. It allows multiple nodes to be placed in multiple rows and columns within a single container. - Nodes can be placed in any cell of the grid ...
Full solved answer →Option Dialogs, Creating Dialogs, File Choosers, Color Choosers, Internal Frames, Frames, Tables, Trees, and Tables
When do we need an internal frame? How do you create a table using Swing? [5]
An Internal Frame (JInternalFrame) is needed in the following situations: - When we want to create a Multiple Document Interface (MDI) application, where several windows (documents) exist inside a single main window. - When we need a lightweight frame-like ...
Full solved answer →Introduction
Compare AWT with Swing. Write a GUI program using components to find sum and difference of two numbers. Use two text fields for giving input and a label for output. The program should display sum if user presses mouse and difference if user release mouse.[10]
--- Feature AWT (Abstract Window Toolkit) Swing --------- Package java.awt javax.swing Components Heavyweight (depend on OS native components) Lightweight (drawn by Java itself, not OS) Look and Feel Platform dependent (looks different on each OS) Platform ...
Full solved answer →Make Unit 2 stick
Practice CSC419 with flashcards & quizzes