0% found this document useful (0 votes)
3 views3 pages

Java Event Handling and Programming Examples

The document provides a series of Java programming exercises and explanations covering various topics such as event handling, class creation, file manipulation, exception handling, and GUI development using Swing. It includes examples of implementing ActionListener, creating custom exceptions, and using layout managers. Additionally, it discusses Java features, packages, and the structure of Java programs.

Uploaded by

OM YADAV
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Java Event Handling and Programming Examples

The document provides a series of Java programming exercises and explanations covering various topics such as event handling, class creation, file manipulation, exception handling, and GUI development using Swing. It includes examples of implementing ActionListener, creating custom exceptions, and using layout managers. Additionally, it discusses Java features, packages, and the structure of Java programs.

Uploaded by

OM YADAV
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Complete Java Answers (Q1 to Q12)

Q3 (a) Event Handling with ActionListener


Event handling triggers actions when the user interacts. Swing uses delegation model.
ActionListener handles button clicks. actionPerformed runs automatically. Example code included.

Q3 (b) Doctor Class with Array of Objects


Program demonstrates creating Doctor class, storing multiple objects and displaying info.

Q3 (c) Mouse Events in Swing


Program shows MOUSE_MOVED and MOUSE_CLICK events and displays coordinates.

Q4 Set 1 (a) File Reverse Copy


Program reads file, reverses text and writes to another file.

Q4 Set 1 (b) Interface Explanation


Interface contains abstract methods, supports multiple inheritance. Example code included.

Q4 Set 1 (c) Simple Swing GUI


Basic GUI with label, textfield and button.

Q5 Set 1 (a) Packages in Java


Use package keyword, import to access. Helps organize classes.

Q5 Set 1 (b) Custom Exception


User defined exception handling example.

Q3 Set 2 (a) Abstract Shape → Circle


Circle inherits Shape. Uses final keyword for constant PI.

Q3 Set 2 (b) Employee Info Swing Form


Swing form to enter employee details, display and clear.
Q3 Set 2 (c) Name Validation Exception
Throws custom exception for invalid names.

Q4 Set 2 (a) Super Keyword


Used to access parent constructor, methods, and variables.

Q4 Set 2 (b) String Processing


Reverse case and replace digits with *.

Q4 Set 2 (c) Prime Number Array


Stores only prime numbers entered by user.

Q5 Set 2 (a) Static vs Instance Variables


Covers ownership, memory, and behavior differences.

Q3 Set 3 (b) Student Swing Form


Swing screen to input student details and display.

Q3 Set 3 (c) Rectangle Area


Abstract Shape implementation to compute rectangle area.

Q4 Set 3 (a) Invalid Name Exception


Throws user-defined exception for name validation.

Q4 Set 3 (b) Layout Manager


Explains FlowLayout, BorderLayout, GridLayout.

Q4 Set 3 (c) Final Keyword


Covers final variable, method, class.

Q5 Set 3 (a) Features of Java


Simple, OOP, platform independent, secure, portable.
Q5 Set 3 (b) Delegation Event Model
Event source → event object → listener.

Q3 Set 4 (a) Delete .txt Files


Program deletes .txt files using command line arguments.

Q3 Set 4 (b) Project Form Swing


Swing screen for project details.

Q3 Set 4 (c) Triangle Area


Abstract Shape overridden to compute triangle area.

Q4 Set 4 (a) Change Label Color


Swing button changes label color to red.

Q4 Set 4 (b) Multilevel Inheritance


Class A → B → C demonstration.

Q4 Set 4 (c) Package Example


Explains creating and accessing packages.

Q5 Set 4 (a) Structure of Java Program


Package, imports, class, members, main().

Q5 Set 4 (b) Dialog Boxes


Message, Confirm, and Input dialogs.

You might also like