Professional Documents
Culture Documents
Ajp Main
Ajp Main
Certificate
This is to certify that Saurab Bagul, Jitesh Barhate, Lokesh Dhangar Roll No.5,6,42
of 5th Semester of Diploma in Computer Engineering of Government Polytechnic,
Jalgaon (Code:0018) has completed the Micro Project satisfactorily in the subject
Advance Java Programming (22517) for the Academic Year 2023-2024 as prescribed
in the curriculum.
Seal of institution
GOVTERNMENT POLYTECHNIC JALGAON
-SUBMISSION
We are Saurabh Bagul , Jitesh Barhate, Lokesh Dhangar student’s of 5th Semester of
the Programme Computer Engineering humbly submit that we have completed
from time to time the Micro-Project work as described in this report by y our own
skills and study in academic year 2023-2024 as per instructions and guidance Prof.
Amol Chaudhari Sir that following students were associated with me for this work,
however, quantum of my contribution has been approved by the Lecturer. And that
I have not copied the report on its any appreciable part from any other literature in
contravention of the academic ethics.
4 Collection of Data
5 Collection of Data
Second
6 Week Discussion and outline of Content
7 Formulation of Content
11 Viva voce
1. Introduction
3. Code.
4. Code summary
5. Output.
6. Conclusion.
Introduction:
An event handling project in advanced Java is a dynamic and interactive application
that focuses on capturing and responding to various user interactions and system
events. These events can range from mouse clicks and keyboard input to window
resizing and network communication. Such projects are essential for creating
responsive and user-friendly applications, making them a fundamental aspect of
modern software development.
The primary goal of this project is to create a comprehensive event handling system
that efficiently manages and processes events, providing seamless user interaction.
This involves designing a graphical user interface (GUI), defining event listeners,
and implementing event-driven programming logic to respond to these events
effectively.
Throughout this project, we will delve into various aspects of event handling,
including event registration, propagation, handling multiple types of events, and
dealing with user interface components like buttons, sliders, and text fields.
Additionally, we will explore advanced topics like multi-threading for concurrent
event handling, and custom event creation for specific application needs.
Ultimately, by the end of this event handling project, you will gain valuable
experience and insights into the world of advanced Java development, equipping you
with the skills to create robust, interactive, and user-friendly applications that cater to
a wide range of user inputs and system events.
What is Event Handling ?
Event handling is a fundamental concept in computer programming and software
development. It refers to the process of capturing, processing, and responding to
events, which are occurrences or incidents that happen during the execution of a
computer program.
Here are some key aspects of event handling:
1. Event Sources: Events can originate from different sources, including user
interfaces (GUI components like buttons, checkboxes, and text fields), system
notifications, hardware devices, and other software components.
2. Event Types: Events come in various types, such as mouse events (click, move,
drag), keyboard events (key presses, key releases), action events (button clicks),
window events (resizing, closing), and custom events (created by developers to suit
specific needs).
3. Event Listeners: In event-driven programming, developers define event listeners
or handlers to "listen" for specific events. These listeners are responsible for
executing code when the associated event occurs.
4. Event Propagation: Events can propagate through an event hierarchy or a
component hierarchy. For example, if a button is clicked in a GUI, the event may
first be handled by the button itself and then propagate up to its parent containers.
5. Event Processing: Event handlers contain code that responds to events. This code
can perform a wide range of actions, from updating the user interface to executing
specific business logic.
6. Callbacks: Event handling often involves callback functions or methods, where
specific code is executed when an event occurs. This allows for the decoupling of
event sources and event listeners, promoting modularity and maintainability.
7. Event Driven Architecture: Event handling is a core principle in event-driven
architecture, where programs respond to events asynchronously, allowing them to
be more responsive and interactive.
Event handling is commonly used in a variety of applications, including graphical
user interfaces (GUIs), web development, video games, and real-time systems.
Different programming languages and frameworks offer their own mechanisms for
event handling, but the fundamental concept remains the same: capturing and
responding to events to create dynamic and interactive software.
Code
/*Online Java Paper Test*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class OnlineTest extends JFrame implements ActionListener
{
JLabel l;
JRadioButton jb[]=new JRadioButton[5];
JButton b1,b2;
ButtonGroup bg;
int count=0,current=0,x=1,y=1,now=0;
int m[]=new int[10];
OnlineTest(String s)
{
super(s);
l=new JLabel();
add(l);
bg=new ButtonGroup();
for(int i=0;i<5;i++)
{
jb[i]=new JRadioButton();
add(jb[i]);
bg.add(jb[i]);
}
b1=new JButton("Next");
b2=new JButton("Bookmark");
b1.addActionListener(this);
b2.addActionListener(this);
add(b1);add(b2);
set();
l.setBounds(30,40,450,20);
jb[0].setBounds(50,80,100,20);
jb[1].setBounds(50,110,100,20);
jb[2].setBounds(50,140,100,20);
jb[3].setBounds(50,170,100,20);
b1.setBounds(100,240,100,30);
b2.setBounds(270,240,100,30);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
setLocation(250,100);
setVisible(true);
setSize(600,350);}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
if(check())
count=count+1;
current++;
set();
if(current==9)
{
b1.setEnabled(false);
b2.setText("Result");
}
}
if(e.getActionCommand().equals("Bookmark"))
{
JButton bk=new JButton("Bookmark"+x);
bk.setBounds(480,20+30*x,100,30);
add(bk);
bk.addActionListener(this);
m[x]=current;
x++;
current++;
set();
if(current==9)
b2.setText("Result");
setVisible(false);
setVisible(true);
}
for(int i=0,y=1;i<x;i++,y++)
{
if(e.getActionCommand().equals("Bookmark"+y))
{
if(check())
count=count+1;
now=current;
current=m[y];
set();
((JButton)e.getSource()).setEnabled(false);
current=now;
}
}
if(e.getActionCommand().equals("Result"))
{
if(check())
count=count+1;
current++;
//System.out.println("correct ans="+count);
JOptionPane.showMessageDialog(this,"correct
ans="+count);
System.exit(0);
}
}
void set()
{
jb[4].setSelected(true);
if(current==0)
{
l.setText("Que1: Which one among these is not a
datatype");
jb[0].setText("int");jb[1].setText("Float");jb[2].setText("boolean");jb
[3].setText("char");
}
if(current==1)
{
l.setText("Que2: Which class is available to all the class
automatically");
jb[0].setText("Swing");jb[1].setText("Applet");jb[2].setText("Object"
);jb[3].setText("ActionEvent");
}
if(current==2)
{
l.setText("Que3: Which package is directly available to
our class without importing it");
jb[0].setText("swing");jb[1].setText("applet");jb[2].setText("net");jb[
3].setText("lang");
}
if(current==3)
{
l.setText("Que4: String class is defined in which
package");
jb[0].setText("lang");jb[1].setText("Swing");jb[2].setText("Applet");j
b[3].setText("awt");
}
if(current==4)
{
l.setText("Que5: Which institute is best for java
coaching");
jb[0].setText("Utek");jb[1].setText("Aptech");jb[2].setText("SSS
IT");jb[3].setText("jtek");
}
if(current==5)
{
l.setText("Que6: Which one among these is not a
keyword");
jb[0].setText("class");jb[1].setText("int");jb[2].setText("get");jb[3].se
tText("if");
}
if(current==6)
{
l.setText("Que7: Which one among these is not a class
");
jb[0].setText("Swing");jb[1].setText("Actionperformed");jb[2].setText
("ActionEvent");jb[3].setText("Button");
}
if(current==7)
{
l.setText("Que8: which one among these is not a function
of Object class");
jb[0].setText("toString");jb[1].setText("finalize");jb[2].setText("equal
s");jb[3].setText("getDocumentBase");
}
if(current==8)
{
l.setText("Que9: which function is not present in Applet
class");
jb[0].setText("init");jb[1].setText("main");jb[2].setText("start");jb[3]
.setText("destroy");
}
if(current==9)
{
l.setText("Que10: Which one among these is not a valid
component");
jb[0].setText("JButton");jb[1].setText("JList");jb[2].setText("JButton
Group");jb[3].setText("JTextArea");
}
l.setBounds(30,40,450,20);
for(int i=0,j=0;i<=90;i+=30,j++)
jb[j].setBounds(50,80+i,200,20); }
boolean check() {
if(current==0)
return(jb[1].isSelected());
if(current==1)
return(jb[2].isSelected());
if(current==2)
return(jb[3].isSelected());
if(current==3)
return(jb[0].isSelected());
if(current==4)
return(jb[2].isSelected());
if(current==5)
return(jb[2].isSelected());
if(current==6)
return(jb[1].isSelected());
if(current==7)
return(jb[3].isSelected());
if(current==8)
return(jb[1].isSelected());
if(current==9)
return(jb[2].isSelected());
return false; }
public static void main(String s[]) {
new OnlineTest("Online Test Of Java"); }
}
Code Summary
In the given Java code for an online test application, event handling is used to
respond to user interactions, such as clicking on buttons and radio buttons. The
ActionListener interface is implemented to handle these events. Here's how
event handling is used in this code:
Various GUI components like labels, radio buttons, and buttons are created and
added to the frame.
The frame and the "Next" and "Bookmark" buttons are registered for mouse
events using addMouseListener and addMouseListener methods, respectively.
Inside the mouseClicked method, you can determine the source of the mouse
event using e.getSource(), and then you can take actions accordingly. Here's
how mouse events are used for specific components:
If the "Next" button is clicked (e.getSource() == b1), you can handle the mouse
click on the "Next" button.
If the "Bookmark" button is clicked (e.getSource() == b2), you can handle the
mouse click on the "Bookmark" button.
For other mouse clicks, you can handle them, for example, by performing
actions when the user clicks on the frame itself.
This allows you to respond to mouse interactions with the frame and buttons in
the application. You can customize the behavior in the mouseClicked method to
perform actions based on the specific mouse events and components involved.
Output
Conclusion :
In Java, event handling is a fundamental aspect of programming, especially in GUI
(Graphical User Interface) applications. Event handling allows developers to respond
to user interactions and system events, making applications interactive and
responsive. Here are some key conclusions about event handling in Java:
Event Sources and Listeners: In Java, event sources are objects that generate events
(e.g., buttons, text fields), and event listeners are objects that respond to those events.
Event listeners are registered with event sources to handle specific events.
Event Listener Interfaces: Java provides a set of predefined event listener interfaces,
such as ActionListener, MouseListener, and KeyListener, to handle common types of
events. Developers can implement these interfaces and override their methods to
define event handling behavior.
Event Dispatch Thread (EDT): GUI events in Java must be processed on the Event
Dispatch Thread to ensure thread safety. This is essential to prevent concurrent
access issues in GUI components.
Custom Events: Developers can create custom events and listeners for specific
application needs. This allows for the creation of more complex and customized
event handling systems.
Swing and AWT: Java provides two primary libraries for GUI development—Swing
and AWT. Swing is an extension of AWT and offers a more powerful and flexible
set of components for building GUI applications.
Testing and Debugging: Event-driven code can be challenging to test and debug, as
events may occur at unexpected times. Tools and techniques for event-driven
debugging are valuable in ensuring the reliability of the application.