0% found this document useful (0 votes)
19 views

Java Microproject

java last year micorporjct

Uploaded by

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

Java Microproject

java last year micorporjct

Uploaded by

sachinpd1008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Karmaveer Shankarrao Kale Education Society’s

GAUTAM POLYTECHNIC INSTITUTE GAUTAMNAGAR

PROJECT REPORT ON
“Chat Application Over The Network”

SUBMITTED BY

Ms.Narode Bhagyashri Tanaji

Ms.ShindeIshwari Sudhakar

Ms.PawarSanskruti Laxman

Ms.Kakad Rohini Suresh

UNDER THE GUIDENCE OF

MR.Bharati.M.B

DEPARTMENT OF COMPUTER ENGINEERING


YEAR 2024-25
ACKNOWLEDGEMENT

We would like to express our deep sense of gratitude and special thanks
to our guide MR.Bharati.M.B who not only took a great interest in the project
but also was always ready to help us as and when needed.

We are also grateful to Prof. Mr.Bharati.M.B(Head of computer


Department) and all staff members of computer Department for their kind co-
operation.

Finally we are thankful to all our friends who have helped for presenting
& preparation of our project
INDEX

Sr. No Content Page No

1.0 Rationale 1

2.0 Aims /Benefits of the Micro- 2


Project

3.0 Couse outcome 8

4.0 Methodology 9

5.0 14
Implementation

6.0 Conclusion 15

7.0 Reference 16

Micro–Project Report
Chat Application Over The Network

1.0 Rationale

This chat application is to provide practical experience in Java networking by developing a


real-time communication tool. It allows students or developers to understand how client-server
architecture works using sockets, managing multiple connections simultaneously. This project
serves as a foundational step toward more complex applications like WhatsApp or Slack by
teaching essential concepts such as data transmission, concurrency, and basic error handling.
Additionally, it offers room for expanding into advanced features such as encryption, user
authentication, and GUI development, making it both a learning and practical tool for real-
world applications.

2.0 Aims/Benefits of Micro-Project

1) Enable instant text-based messaging between users.


2) To create a real-time communication.
3) Facilitate sharing of text message.
4) To acquire the Knowledge about Networking.

3.0 Course Outcomes Achieved


a. Develop a program using GUI framework (AWT & swing).
b. Handle event of AWT and swing component.
c. Develop programs to handle events in java programming.
d. Develop java program using networking concepts.

4.0 Actual Methodology Followed

4.1 Data Collected


• Focused on the selection of an appropriate topic for the micro-project.
• Select the topic i.e. based on the networking.
• Brief study on our topic.
• Gather all information based on the topic of the microproject.

Layout Managers:

Swing uses layout managers to control how components are arranged within a container.

AWT:

AWT (Abstract Window Toolkit) components are part of Java's original platform-independent
windowing, graphics, and user-interface toolkit. These components provide a way to create
Graphical User Interfaces (GUI) for Java applications. AWT is part of the java.awt package
and includes various classes and interfaces for building basic GUI elements.
Swing:

Swing is a part of Java's Java Foundation Classes (JFC) used for building Graphical User Interfaces
(GUIs). It provides a more flexible and powerful set of GUI components than the original AWT
(Abstract Window Toolkit). Unlike AWT, Swing components are written entirely in Java and are
platform-independent, making them lightweight and consistent across different operating systems.

Swing Components:
• JFrame: The main window container where all other components (buttons, text fields, etc.)
are added.
• JButton: A button that can trigger an action when clicked
• JTextField: A single-line text field for user input.

• JPanel: It is a lightweight container in Swing used to organize and group components within a
GUI.
• JScrollBar: It is Swing is a component that enables vertical or horizontal scrolling through
content or a range of values.

Page | 5
Event handling:

Event handling in Java is the mechanism that manages the interaction between the user and GUI
components, allowing components to respond to user actions like clicks, key presses, and mouse
movements. This is done through event listeners that are attached to components and trigger actions
when specific events occur.

Action Event: Action Event in Java is a type of event that occurs when a user performs an action on a
component, such as clicking a button, selecting a menu item, or pressing the "Enter" key in a text
field. This event is handled by implementing the ActionListener interface

• Action Listener: The interface that responds to the action, typically by overriding the
actionPerformed() method.

Networking:

Networking related to servers involves various concepts and components that facilitate communication
and data exchange between servers and clients over a network. Here are some key aspects:

• Client-Server Architecture: A fundamental networking model where clients request services


and servers provide them, enabling distributed computing.
• Sockets: Interfaces that allow communication between two machines over a network, with
ServerSocket specifically enabling servers to listen for client connections.
• IP Addressing: Unique identifiers assigned to each device on a network, enabling servers to
route data to specific clients.
• Port Numbers: Identifiers used by networking protocols to specify particular processes or
services on a server, allowing multiple applications to run simultaneously.
• Data Transmission: The process of sending and receiving data packets over the network,
which may involve considerations of bandwidth, latency, and packet loss

Classes:

• Calendar class:
The Calendar class, part of the java.util package, is used for manipulating dates and times in a
locale-sensitive manner, which is essential for networking applications like logging events and
scheduling tasks.
▪ getTime() : Returns a Date object representing the time value of this Calendar object.
▪ setTime(Date date) : Sets the calendar's time with the given Date object.
▪ set(int year, int month, int date) : Sets the calendar fields YEAR, MONTH, and
DAY_OF_MONTH to the specified values.
▪ clear() : Clears all the calendar fields.

• SimpleDateFormat:
The SimpleDateFormat class in Java, part of the java.text package, is used to format and parse
dates in a locale-sensitive manner. It allows for the conversion between Date objects and their
string representations.
▪ SimpleDateFormat formatter = new SimpleDateFormat(String pattern);

• DataOutputStream:
The DataOutputStream class in Java is used to write primitive data types to an output stream
in a portable (machine-independent) way. It provides methods for writing data such as int,
long, float, double, boolean, and UTF-8 encoded strings. This class ensures that the data can
be read consistently, regardless of the underlying machine architecture, by using a standard
format.
▪ DataOutputStream(OutputStream out)

Page | 6
▪ writeUTF(String s) : Writes a string encoded in UTF-8 format.

Page | 7
For the network-based chat application project, the data collected can include:

1. Client Connection Data:


• IP addresses and port numbers of connected clients.
• Connection timestamps: The time each client connects and disconnects.
• Purpose: Used to manage and monitor active connections and network health.

2. User Inputs and Messages:


• Text-based chat messages: Sent and received messages between clients.
• Purpose: To facilitate real-time communication between users..

4.2 Implementation/Coding

• Server site program:

package project;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.text.*;
import java.net.*;
import java.io.*;

public class Server implements ActionListener

{ JTextField text;
JPanel a1;
static Box vertical = Box.createVerticalBox();
static JFrame f = new JFrame();
static DataOutputStream dout;
Server() {

f.setLayout(null);

JPanel p1 = new JPanel();


p1.setBackground(new Color(7, 94, 84));
p1.setBounds(0, 0, 450, 70);
p1.setLayout(null);
f.add(p1);

JLabel name = new JLabel("Person 1");


name.setBounds(110, 15, 100, 18);
name.setForeground(Color.WHITE);
name.setFont(new Font("SAN_SERIF", Font.BOLD, 18));
p1.add(name);

JLabel status = new JLabel("Active Now");


status.setBounds(110, 35, 100, 18);
status.setForeground(Color.WHITE);
status.setFont(new Font("SAN_SERIF", Font.BOLD, 14));

Page | 8
p1.add(status);

a1 = new JPanel();
a1.setBounds(5, 75, 440, 570);
f.add(a1);

text = new JTextField();


text.setBounds(5, 655, 310, 40);
text.setFont(new Font("SAN_SERIF", Font.PLAIN, 16));
f.add(text);

JButton send = new JButton("Send");


send.setBounds(320, 655, 123, 40);
send.setBackground(new Color(7, 94, 84));
send.setForeground(Color.WHITE);
send.addActionListener(this);
send.setFont(new Font("SAN_SERIF", Font.PLAIN, 16));
f.add(send);

f.setSize(450, 700);
f.setLocation(200, 50);
f.setUndecorated(true);
f.getContentPane().setBackground(Color.WHITE);

f.setVisible(true);
}

public void actionPerformed(ActionEvent ae) {


try {
String out = text.getText();

JPanel p2 = formatLabel(out);

a1.setLayout(new BorderLayout());

JPanel right = new JPanel(new BorderLayout());


right.add(p2, BorderLayout.LINE_END);
vertical.add(right);
vertical.add(Box.createVerticalStrut(15));

a1.add(vertical, BorderLayout.PAGE_START);

dout.writeUTF(out);

text.setText("");

f.repaint();
f.invalidate();
f.validate();
} catch (Exception e) {
e.printStackTrace();
}
}

public static JPanel formatLabel(String out)


{ JPanel panel = new JPanel();
Page | 9
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

JLabel output = new JLabel("<html><p style=\"width: 150px\">" + out + "</p></html>");


output.setFont(new Font("Tahoma", Font.PLAIN, 16));
output.setBackground(new Color(37, 211, 102));
output.setOpaque(true);
output.setBorder(new EmptyBorder(15, 15, 15, 50));

panel.add(output);

Calendar cal = Calendar.getInstance();


SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");

JLabel time = new JLabel();


time.setText(sdf.format(cal.getTime()));

panel.add(time);

return panel;
}

public static void main(String[] args) {


new Server();

try {
ServerSocket skt = new ServerSocket(2005);
while(true)
{
Socket s = skt.accept();
DataInputStream din = new DataInputStream(s.getInputStream());
dout = new DataOutputStream(s.getOutputStream());

while(true)
{
String msg = din.readUTF();
JPanel panel = formatLabel(msg);

JPanel left = new JPanel(new BorderLayout());


left.add(panel, BorderLayout.LINE_START);
vertical.add(left);
f.validate();
}
}

} catch (Exception e)
{
e.printStackTrace();
}
}
}

Page | 10
• Client side program:

package project;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.text.*;
import java.net.*;
import java.io.*;

public class client implements ActionListener {

JTextField text;
static JPanel a1;
static Box vertical = Box.createVerticalBox();

static JFrame f = new JFrame();

static DataOutputStream dout;

client() {

f.setLayout(null);

JPanel p1 = new JPanel();


p1.setBackground(new Color(7, 94, 84));
p1.setBounds(0, 0, 450, 70);
p1.setLayout(null);
f.add(p1);

JLabel name = new JLabel("Mahi");


name.setBounds(110, 15, 100, 18);
name.setForeground(Color.WHITE);
name.setFont(new Font("SAN_SERIF", Font.BOLD, 18));
p1.add(name);

JLabel status = new JLabel("Active Now");


status.setBounds(110, 35, 100, 18);
status.setForeground(Color.WHITE);
status.setFont(new Font("SAN_SERIF", Font.BOLD, 14));
p1.add(status);

a1 = new JPanel();
a1.setBounds(5, 75, 440, 570);
f.add(a1);

text = new JTextField();


text.setBounds(5, 655, 310, 40);
text.setFont(new Font("SAN_SERIF", Font.PLAIN, 16));
f.add(text);
JButton send = new JButton("Send");
send.setBounds(320, 655, 123, 40);
send.setBackground(new Color(7, 94, 84));
send.setForeground(Color.WHITE);
Page | 11
send.addActionListener(this);
send.setFont(new Font("SAN_SERIF", Font.PLAIN, 16));
f.add(send);

f.setSize(450, 700);
f.setLocation(800, 50);
f.setUndecorated(true);
f.getContentPane().setBackground(Color.WHITE);

f.setVisible(true);
}

public void actionPerformed(ActionEvent ae) {


try {
String out = text.getText();

JPanel p2 = formatLabel(out);

a1.setLayout(new BorderLayout());

JPanel right = new JPanel(new BorderLayout());


right.add(p2, BorderLayout.LINE_END);
vertical.add(right);
vertical.add(Box.createVerticalStrut(15));

a1.add(vertical, BorderLayout.PAGE_START);

dout.writeUTF(out);

text.setText("");

f.repaint();
f.invalidate();
f.validate();
} catch (Exception e) {
e.printStackTrace();
}
}
public static JPanel formatLabel(String out)
{ JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

JLabel output = new JLabel("<html><p style=\"width: 150px\">" + out + "</p></html>");


output.setFont(new Font("Tahoma", Font.PLAIN, 16));
output.setBackground(new Color(37, 211, 102));
output.setOpaque(true);
output.setBorder(new EmptyBorder(15, 15, 15, 50));
panel.add(output);

Calendar cal = Calendar.getInstance();


SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");

JLabel time = new JLabel();


time.setText(sdf.format(cal.getTime()));
panel.add(time);

Page | 12
return panel;
}

public static void main(String[] args) {


new client();

try {
Socket s = new Socket("127.0.0.1",1000);
DataInputStream din = new DataInputStream(s.getInputStream());
dout = new DataOutputStream(s.getOutputStream());

while(true) {
a1.setLayout(new BorderLayout());
String msg = din.readUTF();
JPanel panel = formatLabel(msg);

JPanel left = new JPanel(new BorderLayout());


left.add(panel, BorderLayout.LINE_START);
vertical.add(left);

vertical.add(Box.createVerticalStrut(15));
a1.add(vertical, BorderLayout.PAGE_START);

f.validate();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
4.3 Result & Analysis
We have successfully learned about a Develop a project using server and ServerSockets. The code
provides a basic demonstration of AWT and Swing, Event handling for the Chat Application over
the network.

5.0 Actual Resources Used

Sr. Name of Resource


No. /Material Specifications Qty. Remarks
1 Computer System 512 GB, 16 GB RAM 1 Used

2 Operating System Windows 11 1 Used


3 Microsoft Office Word 2023 1 Used
4 Software Eclipse IDE 1 Used
5 Printer LaserJet 1 Used

Page | 13
6.0 Output of Micro-Projects

7.0 Skill Developed/Learning outcome of this Micro-Project

1. In this project we can learned many more things about networking.


2. We learned how to work as team.
3. We learnt how develop a code using Server and ServerSocket.
4. In this project we developed a planning skill.
5. In this project we have developed a problem solving and debugging skill.

8.0 Application of Micro-Project


1. Instant Messaging:
2. Customer Support
3. Group Collaboration
4. Learning Platforms

*********************

Page | 14
Conclusion

The purpose of a test case is to determine if different features within a system


are performing as expected and to confirm that the system satisfies all related
standard, guidelines and customer requirement. The process of writing a test cases
can also help reveal error or defects within the system

Page | 15
Page | 16
Reference

https://www.google.com/search?q=different+types+of+test+cases+with+examples&rlz=1C1VDKB_e
nIN1016IN1016&oq=&aqs=chrome.4.35i39i362l8.697296039j0j15&sourceid=chrome&ie=UTF-8
https://www.valamis.com/hub/learning-outcomes

Page | 17

You might also like