JAVA Programming : Topic JAVA Programming Swing

navyadeepu7 46 views 15 slides Apr 30, 2024
Slide 1
Slide 1 of 15
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15

About This Presentation

JAVA Programming : Topic JAVA Programming Swing


Slide Content

JAVA Programming - SWING Prof. Navya Francis Asst. Professor Kristu Jayanti College

Swing Java Swing is a popular and powerful Graphical User Interface (GUI) toolkit that is used for developing desktop applications . It is a part of the Java Foundation Classes (JFC) and provides a rich set of components and layout managers for creating a variety of GUIs. Java Swing is platform-independent and can be used on any operating system that supports Java.

Swing It provides a set of lightweight components that are not only easy to use but also customizable. Some of the commonly used components in Swing are buttons, text fields, labels, menus, and many more . It also provides a robust event-handling mechanism that allows developers to handle events generated by the graphical components. Some of the commonly used layout managers in Java Swing are BorderLayout , FlowLayout , GridLayout , CardLayout , and BoxLayout .

Features of Java Swing Platform Independence: Platform independence is one of Java Swing’s most remarkable features. It can run on any platform that supports Java. Thus, Swing-based applications can run on Windows, Mac, Linux, or any other Java-compatible operating system. Lightweight Components : Java Swing provides a set of lightweight components that are easy to use and customizable. These components are designed to consume less memory and use less processing power, making Swing-based applications run efficiently.

Features of Java Swing Layout Managers: Java Swing provides a set of layout managers that can be used to organize the graphical components in a GUI. These layout managers enable developers to create flexible and responsive GUIs that adapt to different screen sizes and resolutions. Robust Event Handling Mechanism : Java Swing provides a robust event handling mechanism that allows developers to handle events generated by the graphical components. Developers can register event listeners to detect and respond to user interactions with the GUI.

Features of Java Swing Pluggable Look and Feel: Java Swing provides a pluggable look and feels that allows developers to customize the appearance of the GUI according to the user’s preferences. Developers can choose from several pre-built looks and feel themes or create their own custom themes.

The Model-View-Controller Architecture Swing uses the  model-view-controller architecture  (MVC) as the fundamental design behind each of its components. Essentially, MVC breaks GUI components into three elements. Each of these elements plays a crucial role in how the component behaves.

The MVC pattern architecture consists of three layers: Model:  It represents the business layer of application. It is an object to carry the data that can also contain the logic to update controller if data is changed. View:  It represents the presentation layer of application. It is used to visualize the data that the model contains. Controller:  It works on both the model and view. It is used to manage the flow of application, i.e. data flow in the model object and to update the view whenever data is changed.

The advantages of MVC architecture are as follows: MVC has the feature of scalability that in turn helps the growth of application. The components are easy to maintain because there is less dependency. A model can be reused by multiple views that provides reusability of code. The developers can work with the three layers (Model, View, and Controller) simultaneously. Using MVC, the application becomes more understandable. Using MVC, each layer is maintained separately therefore we do not require to deal with massive code. The extending and testing of application is easier. Advantages of MVC Architecture

Swing Applets So far, we have created the applets based on  AWT (Abstract Window Toolkit) by extending the  Applet  class of the  awt  package. We can even create applets based on the  Swing  package. In order to create such applets, we must extend  JApplet  class of the  swing  package

JApplet JApplet is a top-level container class and you should never draw on it directly, instead you should draw on the component class like JPanel and then add this JPanel to the JApplet

Creating a swing applet In the upcoming code, first, we have created a swing applet by extending  JApplet  class and we have added a  JPanel  to it. Next, we have created a class B, which has extended JPanel class of Swing package and have also implemented  ActionListener   interace to listen to the button click event generated when buttons added to  JPanel  are clicked.
Tags