Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Have Programming Question? Ask it here!

1 Answer(s)      5 years and 11 months ago
Posted in : Java Beginners

View Answers

October 13, 2008 at 1:01 PM

Hi friend,

Code for Window listener :

import java.awt.event.WindowListener;
import java.awt.event.*;
import javax.swing.JFrame;

public class WindowListenerExample {
public static void main(String args[]) {
JFrame jf = new JFrame("Window Listener");
WindowListener wl = new WindowAdapter() {
public void windowClosing(WindowEvent w) {
jf.setSize(300, 300);;

Code for Component Listener :

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

public class ComponentListenerExample {
public static void main(String args[]) {
JFrame jf = new JFrame();
Container container = jf.getContentPane();

ComponentListener cl = new ComponentListener() {
public void clonentHidden(ComponentEvent e) {
dump("Hidden", e);

public void clonentMoved(ComponentEvent e) {
dump("Moved", e);

public void clonentResized(ComponentEvent e) {
dump("Resized", e);

public void clonentShown(ComponentEvent e) {
dump("Shown", e);

private void dump(String type, ComponentEvent e) {
System.out.println(e.getComponent().getName() + " : " + type);

JButton jbl = new JButton("Left");

final JButton jbr = new JButton("Right");

ActionListener al = new ActionListener() {
public void alPerformed(ActionEvent e) {

JSplitPane jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true,
jbl, jbr);

container.add(jsp, BorderLayout.CENTER);

jf.setSize(300, 200);;

For more information on Listener visit to :


Related Tutorials/Questions & Answers:
Event Listeners
Event Listeners  I want to learn the Event Listeners in Java. Any... is the good tutorial and example of Event Listeners in Java. Please check the tutorial Java - Event Listeners Example in Java Applet. Thanks
Action Listeners
Action Listeners  Please, could someone help me with how to use action listeners I am creating a gui with four buttons. I will like to know how to apply the action listener to these four buttons.   Hello Friend, Try
Mouse Listeners
Java NotesMouse Listeners There are several styles for using the mouse listeners.   They are usually added to a graphics panel... a panel and want the listeners outside it because it is more convenient
Event listeners in mxml
Event listeners in mxml  hi.. just tell me about How do you add event listeners in mxml components. Now AS3 components? Please give an example in both MXML and AS3 Thanks  Ans: There are some function
adding mouse listeners to drop target
adding mouse listeners to drop target  import java.awt.*; import java.awt.dnd.DnDConstants; import java.awt.dnd.DragGestureRecognizer; import... with adding mouse listeners to "table" which is drop target, to accept drop
listeners: Named Inner Class Listeners are one of the most common ways... with several components. Anonymous Inner Class Listeners are sometimes... class listeners. Top-level Listeners (this) are commonly
Anonymous Listeners
Java NotesAnonymous Listeners   Using anonymous inner class listeners - a common idiom   In this example you will learn how to use anonymous inner class listeners.   We have also given the complete code example so
Top-level Listeners
Java Notes Top-level Listeners   This is an example of top-level Listeners in Java.   In this example you will learn how to create top level-listeners in swing applications.   Using this as a listener  
Inner-class Listeners
Java NotesInner-class Listeners Named inner class Defining an inner class... by the listener class. Because simple program listeners typically get or set... an inner class. Reuse. Unlike anonymous inner class listeners, it's easy
Java - Event Listeners Example in Java Applet
Java - Event Listeners Example in Java Applet       Introduction The event... for helping in implementing event listeners are present in the java.awt.event.
Flex KeyboardEvent Listener
listeners. In the example when certain specific keys are pressed the function... are created using conditional statements and with these listeners when ever
Action and AbstractAction
Java NotesAction, AbstractAction The javax.swing.Action interface, and the corresponding class, javax.swing.AbstractAction, provide a useful mechanism to implement action listeners that can be shared and coordinated. Actions can
TriggerListeners and JobListeners
;    To perform any action you create Listeners objects... listeners are registered with the scheduler, and must be given a name. Listeners can be registered as either "global" or "non-global". Global listeners
Action Event Listener
;       Action Listeners can be implemented... event listeners. 1. Using "actionListener" attribute of the component... listeners. processAction method signature: public void
Event Adapters
Event Adapters       There are some event listeners that have multiple methods to implement. That is some of the listener interfaces contain more than one method. For instance
This file defines an applet.
Java NotesExample - Generic Applet This file defines an applet. This template is a reasonable way to start an applet, where GenericPanel is a subclass of JPanel and it contains the code to build a GUI with the appropriate listeners
Flex Add Event Listener example
on it. Event listeners are the methods or functions in which events are added on the flex components or it can be said as event listeners handles the event
This file defines a class with a main method.
with the appropriate listeners.   This example shows how to write generic
Value Change Event Listener
more than one listeners. 1. Using "valueChangeListener" attribute... listeners. processValueChange method signature: public void
Enhancing the Test Plan
Enhancing the Test Plan       As you have seen we have added some basic elements to the Test Plan like Sampler and some listeners. Similarly you can add many other elements
Flex Examples
application, how can you handle the event and listeners and many more that you can
hibernate  what is hibernate listeners
Java AWT
Java AWT  What interface is extended by AWT event listeners
validate jtextfield in two different class use keylistener
validate jtextfield in two different class use keylistener  validate jtextfield in java swing will use two class, design part in one class and method calling in one class will use Keylisteners or change listeners
Swings/awt - Swing AWT
Swings/awt  Hi, how to write action listeners to the Buttons in RichTextEditor tool bar.. thanks in's Urgent... i am very much new to Swings
Flex event
: In the targeting phase, Flex invokes the event dispatcher?s listeners. No other nodes on the display list are examined for event listeners. 3. Bubbling phase: In the bubbling phase, Flex examines an event?s ancestors for event listeners. Flex
JSF Related
JSF Related  In what way JSF makes the difference between Applets?? After reading this article I understood instead of using Request and response, we are directly dealing with the Listeners... If soo... we can develop the frames
sdf  In what way JSF makes the difference between Applets?? After reading this article I understood instead of using Request and response, we are directly dealing with the Listeners... If soo... we can develop the frames
JSF  In what way JSF makes the difference between Applets?? After reading this article I understood instead of using Request and response, we are directly dealing with the Listeners... If soo... we can develop the frames
Java Ivent Handler - Swing AWT
Java Ivent Handler  Is it possible to make two listeners work simultaneously?I used a keyboard listener to detect key press and also a mouse listener to detect different events generated by mouse.But when the mouse is moving
Action Listener Review
ways to implement action listeners follow. 1. One shared action listener... } } ); Convenient. Often mixes listeners into other code. (bad) Can't share listeners. 3. Named inner class listener (better) ActionListener
Summary: Classes, Interfaces
import java.awt.event.* // for events and listeners import javax.swing.*; // for more GUI components import javax.swing.event.*; // more listeners footer("1999
Same email-massage is sending twice in online server(tomcat) but working fine in my local server(Tomcat)..
Same email-massage is sending twice in online server(tomcat) but working fine in my local server(Tomcat)..  Sir, I created one project in jsp for a software company. I am using listeners and timer for sending automatic
Flex event
Flex event  Hi... please give me the answer with example What is event Bubbling? Thanks in advance  Event Bubbling: In the bubbling phase, Flex examines an event?s ancestors for event listeners. Flex starts
java - Java Beginners
java  hi all, In Java swings, I created a array of JPanel and added listeners to it to move. These panel has null layout. When i run the application for the first time panel are in fixed position as i given..if i move
javascript event handling examples
event listeners. document.attachEvent('onclick', handleClick); } else
Flex ArrayCollection
. Listeners can be added to listen the event. // Creates
The Mouse
listeners. The most useful... - Handles moves and drags. Mouse Listeners - How and where to write mouse listeners
Flex event phase detection example
the event, triggering and then re-detecting listeners in reverse order for handling the event again. Event listeners are the functions or the methods that we create in our applications and inside event listeners, we create event associated
Java: Interfaces
is for listeners. A listener is an object from a class that implements the required methods for that interface. You can create anonymous inner listeners... graphics and responds to the mouse to implement its own mouse listeners
Java: Basic GUI
interface. This first example has no listeners, so it does nothing. Main.... // GUI Organization - Pure presentation - no listeners, model, etc. // Fred Swartz
listener; boolean b; //--- Buttons always have action listeners... for all of the button's listeners. It is passed an ActionEvent, which
Model-View-Controller (MVC) Structure
(listeners) may be required. Main program The main program initializes everything... methods for registering a Controller's listeners. Other organizations are possible (eg, the Controller's listeners are non-private variables that can be referenced
Event Handling In Java
: Mouse KeyEvent : Keyboard   Event Listeners : Event Listeners.... Listeners listens the event generated by a component. In Java almost all
JSF Training
is of right type.    Action Events Listener Action Listeners... more than one event listeners.    Value Change Event Listener... way permits you to include more than one listeners.    Phase
java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener
org.apache.catalina.core.StandardContext listenerStart SEVERE: Skipped installing application listeners
Using a variable filename - Java Beginners
first you add action listeners with your buttons.Now in the method actionPerformed