Support Me ��


SUBSCRIBE NOW

JAVA GUI 2


JAVA GUI 2

Event Handling

Any program that uses GUI (graphical user interface) such as Java application written for windows, is event driven. Event describes the change of state of any object. Example : Pressing a button, Entering a character in Textbox.

Components of Event Handling

Event handling has three main components,

1. Events : An event is a change of state of an object.

2. Events Source : Event source is an object that generates an event.

3. Listeners : A listener is an object that listens to the event. A listener gets notified when an event occurs.

How Events are handled ??

A source generates an Event and send it to one or more listeners registered with the source. Once event is received by the listener, they process the event and then return. Events are supported by a number of Java packages, like java.util, java.awt and java.awt.event.

Important Event Classe and Interface

Event Classe Description Listener Interface
ActionEventgenerated when button is pressed, menu-item is selected, list-item is double clicked.ActionListener
MouseEventgenerated when mouse is dragged, moved,clicked,pressed or released also when the enters or exit a component.MouseListener
KeyEventgenerated when input is received from keyboard.KeyListener
ItemEventgenerated when check-box or list item is clicked.ItemListener
TextEventgenerated when value of textarea or textfield is changed.TextListener
MouseWheelEventgenerated when mouse wheel is moved.MouseWheelListener
WindowEventgenerated when window is activated, deactivated, deiconified, iconified, opened or closed.WindowListener
ComponentEventgenerated when component is hidden, moved, resized or set visible.ComponentEventListener
ContainerEventgenerated when component is added or removed from container.ContainerListener
AdjustmentEventgenerated when scroll bar is manipulated.AdjustmentListener
FocusEventgenerated when component gains or loses keyboard focus.FocusListener

 

Example of Event Handling

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.*;

public class Test extends Applet implements KeyListener
{
String msg="";
public void init()
{
addKeyListener(this);
}
public void keyPressed(KeyEvent k)
{
showStatus("KeyPressed");
}
public void keyReleased(KeyEvent k)
{
showStatus("KeyRealesed");
}
public void keyTyped(KeyEvent k)
{
msg = msg+k.getKeyChar();
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg, 20, 40);
}
}

HTML code :
< applet code="Test" width=300, height=100 >

Dinesh Kumar S is a 23-year-old System Administrator who enjoys playing games, listening to music and learning new technology. He is friendly and generous, but can also be very lazy and crazy.

Share this

Backlinks

Website Design Company in Coimbatore
Website Design Company in Tamil nadu
Website Design Company in Karur
Website Design Company in Erode
Website Design Company in ooty
Website Design Company in theni
Website Design Company in thoothukudi
Website Design Company in Chennai
Website Design Company in Sathy
Website Design Company in Coimbatore Tamilnadu
Cheap Website Design Company in Coimbatore
Adsense Website Design Company in Coimbatore
ecommerce Website Design Company in Coimbatore
school Website Design Company in Coimbatore
Academy Website Design Company in Coimbatore
Test Website Design Company in Coimbatore
Best Website Design Company in Coimbatore
Adsense Website Design Company in Coimbatore
Adsense Website Design Company in Tamil nadu
Adsense Website Design Company in Karur
Adsense Website Design Company in Erode
Adsense Website Design Company in ooty
Adsense Website Design Company in theni
Adsense Website Design Company in thoothukudi
Adsense Website Design Company in Chennai
Adsense Website Design Company in Sathy
Free SEO Tools online
Free SEO Tools online Website
Free SEO Tools online Plagiarism
Free SEO Tools online article rewriter tool
Free SEO Tools online article reading and writing criticism
Free SEO Tools online seo backlink
Free SEO Tools online Free backlink maker
Free SEO Tools online seo backlink strategy
Free SEO Tools online content writting
360 help SEO Tools online Plagiarism checker
360 help SEO Tools online seo backlink
360 help SEO Tools online Free backlink maker
360 help SEO Tools online content writting
360 help SEO Tools online article rewriter tool
360 help SEO Tools
360 help SEO Tools India
360 help SEO Tools Tamil
360 help SEO Tools website