Listeners

Ads

 
 
 

Share on Google+Share on Google+

tarun1
Listeners
1 Answer(s)      8 years ago
Posted in : Java Beginners
Ads
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) {
System.exit(0);
}
};
jf.addWindowListener(wl);
jf.setSize(300, 300);
jf.show();
}
}

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");
jbl.setName("Left");
jbl.addComponentListener(cl);

final JButton jbr = new JButton("Right");
jbr.setName("Right");
jbr.addComponentListener(cl);

ActionListener al = new ActionListener() {
public void alPerformed(ActionEvent e) {
jbr.setVisible(!jbr.isVisible());
}
};
jbl.addActionListener(al);

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

container.add(jsp, BorderLayout.CENTER);

jf.setSize(300, 200);
jf.show();
}
}

For more information on Listener visit to :

http://www.roseindia.net/java/example/java/swing/

Thanks

Ads









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
Advertisements
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
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
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
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
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
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 advance...it'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
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
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
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
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
Tutorials   
Java Spring Hibernate Struts Training java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java Java Example Codes and Tutorials in 2017 How do I read a large file quickly in Java? Is learning Java worthwhile?

Ads

 
Advertisement null

Ads