0% found this document useful (0 votes)
2 views1 page

Java Swing Basics

The document outlines exercises related to Java Swing, covering GUI definitions, differences between AWT and Swing, and the role of JFrame. It also includes tasks to explain various components, event handling, ActionListener functionality, layout managers, and a practical exercise to create a simple calculator application. Solutions are to be submitted by October 17, 2025.

Uploaded by

Michelle Muchima
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)
2 views1 page

Java Swing Basics

The document outlines exercises related to Java Swing, covering GUI definitions, differences between AWT and Swing, and the role of JFrame. It also includes tasks to explain various components, event handling, ActionListener functionality, layout managers, and a practical exercise to create a simple calculator application. Solutions are to be submitted by October 17, 2025.

Uploaded by

Michelle Muchima
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

Java Swing Basics

Exercise 1:

1.​ Define GUI and explain its purpose in software applications.​

2.​ Differentiate between AWT and Swing in Java.​

3.​ What is the role of a JFrame in a Java Swing application?​

4.​ Explain the function of each of the following components and provide at least 2 functions
for each:​
a) JButton​
b) JLabel​
c) JTextField​

5.​ Describe the difference between a container and a component in Swing.​

6.​ What is an event in Swing? Give two examples.​

7.​ Briefly explain what an ActionListener does in a Swing application.​

8.​ What is the purpose of a layout manager?​

9.​ Compare FlowLayout, BorderLayout, and GridLayout where would each be most
suitable?​

10.​Why is it important to call setVisible(true) in your Swing application?

Exercise 2:
Use Java Swing to create a simple calculator that performs basic arithmetic operations, addition,
subtraction, multiplication, and division using GridLayout. Your program should include:

●​ A main window (JFrame) titled “Simple Calculator”


●​ Two input fields for numbers (JTextField)
●​ Four buttons: +, −, ×, ÷
●​ A label to display the result

Instructions:
Solutions should be written on a piece of paper and submitted to the class rep who will submit to
the lecture by or on the 17th of October 2025.

You might also like