Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
30 views

Java Notes Unit 4

SYBscIt mumbai unviresity

Uploaded by

kobawag832
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Java Notes Unit 4

SYBscIt mumbai unviresity

Uploaded by

kobawag832
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

SYIT SEM IV

Course Name: Java Programming


___________________________________________________________________________

UNIT 4
1) What are the key features of the Java Foundation Classes (JFC)?
The Java Foundation Classes (JFC) encompass a set of APIs and libraries that provide
developers with tools to create graphical user interfaces (GUIs) and handle multimedia and
networking tasks in Java applications. Some key features of the Java Foundation Classes (JFC)
include:

1) Swing GUI Toolkit:


 Swing is a lightweight and platform-independent GUI toolkit that allows developers
to create sophisticated and responsive user interfaces for Java applications.
 It provides a wide range of components such as buttons, text fields, menus, dialogs,
and tables, which can be customized and combined to create rich GUIs.
 Swing supports pluggable look-and-feel, allowing developers to change the
appearance of their applications easily.
2) AWT Integration:
 The Abstract Window Toolkit (AWT) is integrated with Swing to provide low-level
access to native platform GUI components.
 AWT components can be used alongside Swing components, providing flexibility and
compatibility with existing AWT-based applications.
3) Java 2D Graphics API:
 The Java 2D API enables developers to create and manipulate two-dimensional
graphics in Java applications.
 It supports drawing shapes, text, images, and other graphical elements, as well as
applying transformations, gradients, and transparency effects.
4) Java Accessibility API:
 The Java Accessibility API enhances the accessibility of Java applications for users with
disabilities.
 It allows developers to create accessible user interfaces by providing support for
assistive technologies such as screen readers and Braille displays.
5) Java Naming and Directory Interface (JNDI):
 JNDI provides a standard way for Java applications to access naming and directory
services, such as LDAP directories and DNS.
 It allows developers to look up and manipulate objects stored in naming and directory
services using a unified API.
6) Java Networking API:
 The Java Networking API provides classes and interfaces for network communication
in Java applications.
 It supports creating and managing network connections, sending and receiving data
over sockets, and implementing network protocols such as HTTP and FTP.

Overall, the Java Foundation Classes (JFC) offer a comprehensive set of tools and APIs for
developing feature-rich and cross-platform Java applications with advanced GUI, graphics,
multimedia, and networking capabilities.

Prof. Bhakti Chaudhari 1


SYIT SEM IV

Course Name: Java Programming


___________________________________________________________________________
2) Explain the difference between AWT and Swing.

Prof. Bhakti Chaudhari 2


SYIT SEM IV

Course Name: Java Programming


___________________________________________________________________________
3) Write short notes on: a. FlowLayout b. BorderLayout c. GridLAyout
a. FlowLayout
Purpose:

 The purpose of FlowLayout is to arrange components in a row, flowing from left to right, with
optional wrapping to the next row.
 It is useful for creating simple layouts where components are added one after another
horizontally, like buttons in a toolbar or labels in a panel.
 FlowLayout automatically resizes and positions components based on their preferred sizes and
the size of the container.

Constructor:

FlowLayout has two constructors:

 FlowLayout(): Creates a new FlowLayout with a left alignment and default horizontal and
vertical gaps of 5 pixels.
 FlowLayout(int align): Creates a new FlowLayout with the specified alignment. The
alignment can be one of FlowLayout.LEFT, FlowLayout.CENTER, FlowLayout.RIGHT,
FlowLayout.LEADING, or FlowLayout.TRAILING.

Example:

import javax.swing.*;
import java.awt.*;

public class FlowLayoutExample {


public static void main(String[] args) {
JFrame frame = new JFrame("FlowLayout Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel panel = new JPanel();


panel.setLayout(new FlowLayout());

for (int i = 1; i <= 5; i++) {


panel.add(new JButton("Button " + i));
}

frame.add(panel);
frame.pack();
frame.setVisible(true);
}
}

Prof. Bhakti Chaudhari 3


SYIT SEM IV

Course Name: Java Programming


___________________________________________________________________________

b. BorderLayout:

Purpose:
 The purpose of BorderLayout is to arrange components in five regions: north, south, east,
west, and center.
 It's suitable for creating layouts where components are positioned around the edges of a
container, with one component occupying the center.
 BorderLayout automatically resizes and positions components based on their preferred sizes
and the size of the container.
Constructor:
BorderLayout has two constructors:
 BorderLayout(): Creates a new BorderLayout with horizontal and vertical gaps of 0 pixels.
 BorderLayout(int hgap, int vgap): Creates a new BorderLayout with the specified horizontal
and vertical gaps between components.
When adding components to a BorderLayout, you specify the region using corresponding constants:
 BorderLayout.NORTH
 BorderLayout.SOUTH
 BorderLayout.EAST
 BorderLayout.WEST
 BorderLayout.CENTER
Example:

import javax.swing.*;
import java.awt.*;

public class BorderLayoutExample {


public static void main(String[] args) {
JFrame frame = new JFrame("BorderLayout Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel panel = new JPanel();


panel.setLayout(new BorderLayout());

panel.add(new JButton("North"), BorderLayout.NORTH);


panel.add(new JButton("South"), BorderLayout.SOUTH);
panel.add(new JButton("East"), BorderLayout.EAST);
panel.add(new JButton("West"), BorderLayout.WEST);
panel.add(new JButton("Center"), BorderLayout.CENTER);

frame.add(panel);
frame.pack();
frame.setVisible(true);
}
}

Prof. Bhakti Chaudhari 4


SYIT SEM IV

Course Name: Java Programming


___________________________________________________________________________
C. GridLayout

Purpose:

 The purpose of GridLayout is to arrange components in a grid-like fashion, where each


component occupies a cell in a rectangular grid.
 It is useful for creating uniform layouts where components are arranged in rows and
columns, such as organizing buttons in a calculator or arranging panels in a grid.
 GridLayout automatically resizes and positions components to fit evenly within the grid,
allocating equal space for each cell.

Constructor:

GridLayout has two constructors:

 GridLayout(int rows, int cols): Creates a new GridLayout with the specified number of rows
and columns. Components are arranged in a grid with the specified number of rows and
columns.
 GridLayout(int rows, int cols, int hgap, int vgap): Creates a new GridLayout with the specified
number of rows and columns, along with horizontal and vertical gaps between components.

import javax.swing.*;
import java.awt.*;

public class GridLayoutExample {


public static void main(String[] args) {
JFrame frame = new JFrame("GridLayout Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel panel = new JPanel();


panel.setLayout(new GridLayout(3, 2)); // 3 rows, 2 columns

for (int i = 1; i <= 6; i++) {


panel.add(new JButton("Button " + i));
}

frame.add(panel);
frame.pack();
frame.setVisible(true);
}
}

Prof. Bhakti Chaudhari 5


SYIT SEM IV

Course Name: Java Programming


___________________________________________________________________________
4) What is the Delegation Event Model in Swing, and how does it facilitate
event handling?
Event Delegation Model defines the standard mechanism to generate and handle the events.

Event Source:

 Think of the event source as something that can "trigger" events, like a button being clicked
or a key being pressed.
 For example, if you click a button on a webpage, that button is the event source.

Event Class:

 An event class is like a message that tells you what happened. It holds information about the
event, like which button was clicked or what key was pressed.
 For instance, if you click a button, the event class might say, "Button 'Submit' was clicked."

Event Listener:

 An event listener is like someone who's listening for a specific type of event to happen.
When that event occurs, the listener reacts to it.
 For instance, if you have a listener for button clicks, it will perform a specific action when a
button is clicked, like submitting a form or opening a new window.

In simple terms, the event delegation model works as below:

 The event source (like a button) notices when something happens (like a click).
 It creates an event class (like a message) that describes what happened (like "Button
'Submit' was clicked").
 Then, it tells the event listener (like a person listening) that the event occurred.
 The event listener reacts by performing a specific action, based on what happened.

This model helps keep code organized and makes it easy to create interactive programs, like

webpages with buttons that do things when clicked

---------------x-------------------

Prof. Bhakti Chaudhari 6

You might also like