Events & Listeners

Hi, I'm trying toget a handle on events and listeners and am studying the following classes for this purpose. I'm pretty comfortable with understanding regular applets, but am confused by a couple of things in the following.
1.) How is the Dots class able to instantiate a Point object if the Dots program does not import a Point class?
My guess here is that the Point class is a sub class of the MouseEvent class, which is made available to the program via the java.awt.event.* import statement. If this is correct, is this an example of the inheritance concept?
2.) How is the Dots class able to instantiate a DotsMouseListener object (in the init() method) if the Dots program doesn't import the DotsMouseListener class?
My guess here is that since the constructor in the DotsMouseListener class takes as its parameter the Dots applet, the Dots class is somehow able to instantiate DotsMouseListener objects. If this is true, though, I don't get it.
Thanks for your help . . .
DOTS.JAVA
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Dots extends Applet
   private final int APPLET_WIDTH = 200;
   private final int APPLET_HEIGHT = 100;
   private final int RADIUS = 6;
   private Point clickPoint = null;
   //  Creates a listener for mouse events for this applet.
   public void init()
      DotsMouseListener listener = new DotsMouseListener(this);
      addMouseListener(listener);
      setBackground (Color.black);
      setSize (APPLET_WIDTH, APPLET_HEIGHT);
   //  Draws the dot at the appropriate location.
   public void paint (Graphics page)
      page.setColor (Color.green);
      if (clickPoint != null)
         page.fillOval (clickPoint.x - RADIUS, clickPoint.y - RADIUS,
                        RADIUS * 2, RADIUS * 2);
   //  Sets the point at which to draw the next dot.
   public void setPoint (Point point)
      clickPoint = point;
DOTSMOUSELISTENER.JAVA
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
class DotsMouseListener implements MouseListener
   private Dots applet;
   //  Stores a reference to the applet.
   public DotsMouseListener (Dots applet)
      this.applet = applet;
   //  Determines the point at which the mouse is clicked, sets the
   //  point in the applet, then forces the applet to repaint.
   public void mouseClicked (MouseEvent event)
      Point clickPoint = event.getPoint();
      applet.setPoint (clickPoint);
      applet.repaint();
   //  Provide empty definitions for unused event methods.
   public void mousePressed (MouseEvent event) {}
   public void mouseReleased (MouseEvent event) {}
   public void mouseEntered (MouseEvent event) {}
   public void mouseExited (MouseEvent event) {}
}

>
1.) How is the Dots class able to instantiate a Point
object if the Dots program does not import a Point
class?It imports java.awt.*, which contains Point
The * implies that you are importing all classes in the java.awt package.
My guess here is that the Point class is a sub class
of the MouseEvent class, which is made available to
the program via the java.awt.event.* import statement.
If this is correct, is this an example of the
inheritance concept?This is not an example of inheritance, it is Composition. A basic explanation used very often is is a and has a
Is a = Inheritance
Has a = Composition
eg. Man is a Mammal. So, you can say that Man inherits from the base class Mammal.
On the other hand,
Man has a Dog
Dog also inherits from Mammal. But as related to Man, it is Composition.
2.) How is the Dots class able to instantiate a
DotsMouseListener object (in the init() method) if the
Dots program doesn't import the DotsMouseListener
class?You need to import a class/package only if the class is in a different package(directory) than the class in which it is being used.
i.e., If Dots and DotListener are in the same directory, say C:\java\code then you do not need to import DotListener.
The reason you need to import the API classes is that they are not in the same directory as your code.
Hope This Helps

Similar Messages

  • How to block execution of event listeners

    Hi all,
    JDev version : 11.1.1.6
    My requirement is that I want to block all event listeners like ActionListeners, SelectionListeners, DisclosureListeners, RowDisclosure listeners when the screen is opened in readonly mode.
    I could block ActionListeners by disabling command links and command buttons etc.
    But there's no way to block SelectionListeners, DisclosureListeners, RowDisclosure listeners.
    So Is there any common code which can block all listeners?
    Or is there any EventController or something like that which will allow me to control event execution?

    I would have if it was just one screen.
    There are hundreds of screens.
    Anyways, can't I use any javascript to do this? There are some interfaces like EventListeners , classes like EventConsumer etc. Do none of them provide feature to block event listeners?

  • Help me I'm trying to create event listeners

    I am trying to create event listeners
    Whenever any keyboard event occurs the string s gets appended by a,c
    or p.At the end of the program its supposed to print value of s
    But s always happens to null.Please tell me how to correct it....so
    that detection is possible for any case
    import java.io.*;
    import java.awt.event.*;
    public class trial {
    int x;
    public static String s;
    //OutputStream f1=new FileOutputStream("file2.txt");
    public static void keyReleased(KeyEvent e)
    s=s+"a";
    public static void keyPressed(KeyEvent e)
    s=s+"c";
    public static void keyTyped(KeyEvent e)
    s=s+"p";
    public static void main(String args[])
    throws IOException
    char c;
    BufferedReader br =new BufferedReader(new
    InputStreamReader(System.in));
    System.out.println("Entercharactes,'q' to quit.");
    do
    c=(char)br.read();
    System.out.println(c);
    while(c!='q');
    // for(int i=0;i<s.length();++i)
    System.out.println(s);

    I suggest looking at the java tutorial. Your code completely misses the mark and you need to see examples.

  • Using Multiple Event Listeners

    Hi,
    I have a movielcip (A) class in which I have used a Tween class effect on a child movieclip (B) scrollRect. The (B) Movieclip in turn has several movieclips whose have tween class effect being executed on thier child movieclips.
    the tweens are all unique to each movieclip
    and the event listeners are taken off once completed.
    This works all well and good in FLASH IDE...
    My problem arises when I try to view this in a browser on a Windows XP
    it doesnt work in
    Opera Version 9.63
    Firefox 2.0
    and Google Chrome 2.0
    The only browser it works fluently in is
    Internet Explorer 7.0.5
    What is happening in most cases it that the animation appears to "stick" but i think what may be happening is the listening or removal of the event listeners. The animations are left incompleted.
    Is there any rule of thumb when using multiple event listeners?
    here is a snippet of some of my code
    on click event from movieclip (A)
    private function scrollToSlidePrev(e:MouseEvent) {
                   if (((slideIndex - 1) >= 0)) {
                        nextButton.mouseEnabled = nextButton.enabled = previousButton.enabled = previousButton.mouseEnabled = false;
                        var position:Number = 0-SLIDEAREA.width;
                        var slide1:TileListSlide = slides[slideIndex] as TileListSlide;
                        var slide2:TileListSlide = slides[--slideIndex] as TileListSlide;
                        scrollSlide(position,slide1,slide2);
    tween animation in movieclip (A) on (B)
    private function scrollSlide(pos:int,slide1:TileListSlide,slide2:TileListSlide) {
                   slide1.resizeSlideTo(0.6); // execute tween on child movie clips in B
                   slide2.resizeSlideTo(1); // same as above;
                   var rect:Rectangle = sliderMc.scrollRect;
                   var tween1:Tween = new Tween(rect,"x",Regular.easeOut,rect.x,rect.x + pos,3,true);
                   tween1.addEventListener(TweenEvent.MOTION_CHANGE,setSliderScroll,false,4);
                   tween1.addEventListener(TweenEvent.MOTION_FINISH,toggleButtonEnabled,false,3);
    tween animation in movieclip (B) children
    public function resizeSlideTo(sc) {
                   var m:Matrix = tileList.transform.matrix as Matrix;
                   var p:Point = new Point (m.a, 0);
                   var tween2:Tween = new Tween(p,"x",Regular.easeOut,p.x,sc,3,true);
                   if (numericStepper != null) {
                        if (sc != 1) {
                             numericStepper.visible = false;
                             tween2.removeEventListener(TweenEvent.MOTION_FINISH,showStepper);
                        if (sc === 1) {
                             tween2.addEventListener(TweenEvent.MOTION_FINISH,showStepper,false,2);
                   tween2.addEventListener(TweenEvent.MOTION_CHANGE,setScaleOnScroll,false,3);
    here is the link
    http://visual_admin.web.aplus.net/ticker/ticker_widget.html
    the effect disables and re-enables the buttons when its done.... then the listeners are removed.
    each one with the exception cretes its own unique tween (obviously this is a custom class built as each clip)
    i really don't know what to make of it guys         

    apparantly making the tween a property of the class rather than a random variable in a function worked.....go figure

  • [JS] Basic question about event listeners and event handlers

    I am very new to the whole topic of event listeners and event handlers.  I'd run the test for the following problem myself, but I don't know where to start, and I just want to know if it's impossible -- that is, if I'm misunderstanding what event listeners and event handlers do.
    Say I have an InDesign document with a text frame that is linked to an InCopy story.  Can I use an "afterImport" event listener on the text frame to perform some action any time the link to the InCopy story gets updated?  And will the event handler have access to both the story that is imported, and the pathname of the InCopy file?
    Thanks.

    Thank you, Kasyan.
    Both of those are good solutions.
    We are currently using InDesign CS4 and InCopy CS5.  I'm hoping to get them to purchase the whole CS5 suite soon, since I'd like to start writing scripts for InDesign CS5 as soon as possible, as long as I'm going to have to be doing it in the not too distant future anyway.  The greater variety of event handlers sounds like it might be something that is crucial to the project I'm working on, so that adds to the argument for getting CS5.
    Thanks again.  You have no idea how helpful this is.  I made some promises to my boss yesterday that I later realized were  based on assumptions of mine about the InDesign/InCopy system that didn't make any sense, and I was going  to have to retract my promises.  But after reading your response I think I can still deliver, in a slightly different way that I had been thinking before.
    Richard

  • Documentation for custom event listeners

    Hi,
    I am searching in portal 8.1 documents for using custom events, coding and registering event listeners, and using them in jsp pages. So far my search has been unsuccessful.
    Can some one let me know where i find this info?
    -thanks

    Hi J, 
    Thanks for your reply.
    I didn’t find the custom work item Web Access control Official documents, but you can refer to the information in these articles(it’s same in TFS 2013):
    http://blogs.msdn.com/b/serkani/archive/2012/06/22/work-item-custom-control-development-in-tf-web-access-2012-development.aspx
    http://blogs.msdn.com/b/serkani/archive/2012/06/22/work-item-custom-control-development-in-tf-web-access-2012-deployment.aspx
    For how to debug TFS Web Access Extensions, please refer to:
    http://www.alexandervanwynsberghe.be/debugging-tfs-web-access-customizations/.
    For the custom work item Web Access control Official documents, you can
    submit it to User Voice site at: http://visualstudio.uservoice.com/forums/121579-visual-studio. Microsoft engineers will evaluate them seriously.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Event Listeners VS Event Functions

    I'm working on a new project at work where there's lots of
    custom objects with lots and lots of event listeners. I keep
    finding myself saying, "why didn't they just use the built in
    objects with built in event handling?". However, from what I can
    see it seems like AS3 leans heavily towards using Event Listeners
    as opposed to putting event responsibility on the object itself
    (E.G. XML.onload). Is there an advantage to this (other than making
    it more Java like?) I've always favoured keeping the responsibility
    on the object itself because it seems like one less object to keep
    track of and also makes things feel more self contained. If I have
    10 objects that fire 10 different events, I have to create 10
    different event handlers (or 10 different case statements within
    the same event handler), whereas with self event handling, I just
    code in the event function.
    Anyways, I wanted to open discussion to which method of event
    handling you prefer and why, and also what you believe the
    advantages to this. I was searching google for previous discussions
    on this but I couldn't seem to find anything, so I thought I'd get
    the ball rolling! Looking forward to reading these, try not to be
    too elitist in your posts!!

    I tried to change getFileOperation to getFileOperation2 in one of the functions as follows but same problem appeared.
    function f3 (event:MouseEvent):void
    trace("f3 triggered");
    getFileOperation2.addEventListener(ResultEvent.RESULT, f4);
    Do you have an idea how I can avoid the same function from triggering twice?? thanks a lot

  • Loading/Unloading a .swf that adds event listeners to the Stage

    Hi all,
    Disclaimer
    Apologies if I suck so bad at using forum search that the answer to this is on page 1 somewhere; I tried...
    Question
    I am loading and unloading a .swf to which I do not have source code access. This .swf places several event listeners on the stage, as far as I can tell. When the .swf is unloaded, the event listeners placed upon the stage still seem to be in effect. Using unloadAndStop doesn't seem to do it, and I have to target Flash Player 9, anyway, so can't really use it. Is there any other way I can keep this external .swf from holding onto my main movie's stage?
    Additional info
    All eventListeners and references being set by my code are removed.
    I've managed a little contact with the author of the .swf:
    I've requested he provide a dispose() method I can call to get all the listeners removed, and send an updated .swf.
    He's suggested that I should be able to avoid the problem by loading into a unique ApplicationDomain. I'm not terribly familiar with this, but have given it a try without much success. Is this a valid solution - can I really protect my 'stage' by properly using ApplicationDomains - or do I need to persist in trying to get a public dispose() method built in?
    Thanks in advance!
    Cheers, John

    thanks for reply sir
    sir actually, i have not any problem with loading any file but i need to go back to intro.swf file when i click on clsbtn of main.swf, i want unload the main.swf file and panel.swf file
    actually i did was, i have intro.swf file and there is button by clicking load main.swf file (where is timeline controling butons) and in the main file automatically load panel.swf file ( where is all animation)
    its all play gud , no problem
    but my problem is there is a clsbtn in main.swf file and when i click on that button everything should be unload and it should return on the previous position in intro.swf
    i hope u understand what i am trying to say

  • Add event listeners to dynamically loaded symbols?

    Hi,
    I'm trying to dynamically load different MovieClips based on user input. Several of those clips have embedded url link symbols. How can I add event listeners to the url links if the dynamically loaded MovieClip does not have an instance name? Seems like I can (right?) apply an instance name when the clip is loading, but the event listener doesn't compile because the name is not there yet, so that seems out.
    Am I on right track?

    Are you saying that you will instnatiate this symbol several times and each time url for this link is going to be different?
    There are at list two ways to deal with it.
    1. Inside symbol you can dispatch a custom event once it is clicked:
    myLink.addeventListener(MouseEvent.CLICK, onClick);
    function onClick(e:MouseEvent):void {
         dispatchEvent(new Event("linkClick"));
    Wherever you instantiate the symbol (perhaps on timeline):
    var symbolInstance:MySymbol = new MySymbol();
    symbolInstance.addEventListener("linkClick", onLinkClick);
    function onLinkClick(e:Event):void {
         // do whatever
    Second way would be to pass url value into symbol instance itself and deal with with it on a symbol level. I personally prefere way 1.

  • Spry event listeners with dynamic form elements

    Hi ,
    I am trying to implement spry event listeners with a form that has dynamic check boxes and text field name. I now i can get the elements in a var and loop through with a normal function but can this work for spry events listeners

    Short answer is yes. But I have a feeling that you need further assistance, in which case give us a URL to a page that you want to apply the event listener to.

  • [svn:osmf:] 15000: Fix for FM-447 : Adding CuePoint in TemporalFacet event listeners doesn't work

    Revision: 15000
    Revision: 15000
    Author:   [email protected]
    Date:     2010-03-24 14:01:02 -0700 (Wed, 24 Mar 2010)
    Log Message:
    Fix for FM-447 : Adding CuePoint in TemporalFacet event listeners doesn't work
    Ticket Links:
        http://bugs.adobe.com/jira/browse/FM-447
    Modified Paths:
        osmf/trunk/framework/OSMF/org/osmf/metadata/TimelineMetadata.as

  • [svn:osmf:] 14975: Fix for FM-447 : Adding CuePoint in TemporalFacet event listeners doesn't work

    Revision: 14975
    Revision: 14975
    Author:   [email protected]
    Date:     2010-03-23 17:04:43 -0700 (Tue, 23 Mar 2010)
    Log Message:
    Fix for FM-447 : Adding CuePoint in TemporalFacet event listeners doesn't work
    Ticket Links:
        http://bugs.adobe.com/jira/browse/FM-447
    Modified Paths:
        osmf/trunk/framework/OSMF/org/osmf/metadata/TimelineMetadata.as

  • All event listeners and models in one file?

    I have one java file for all my event listeners of a programm and one java file for all my models. Is this good?
    I create instances with new AllInOneHandler.MouseHandler() for example.
    Or should I have one file for each event and each model?

    Hi,
    you should have one file for each class or interface - this gives you best control and reusability. Also when you have javadoc-comments in it, big files with many classes in it will become hard to edit.
    When using one file for each class or interface you can import only the needed classes or interfaces instead of importing whole packages - so it is easier to see, what is exactly imported. As so a good structured application has many classes, where each of them is small (and in an own source file), you will have less problems during the evolution of your classes this way.
    If you want to group some classes, why not use sub-packages for this purpose?
    greetings Marsian

  • JSP have event listeners???

    Hi Would like to check if JSP have event listeners?? Eg.Like onblur that is used to activate javascript. Instead of calling a javascript function, can it call a JSP code or function.
    Do JSP has functions like javascript?
    Also does anyone know how if javabean is able to return a value and place it in a textfield on a JSP page??
    Please help me I am going more and more headache
    as mine deadline draws near....sign :(

    No.
    JSP can have Java code as scriptlets, but tag libraries are preferred. I don't put any scriptlet code in my JSPs.
    You can add a JavaBean to page, request, session, or application scope in a JSP page and access the properties that have getters. Then you can assign the values to a text field.
    I don't know how tight your deadline is, but the best approach in my view is to use Java Standard Tag Library (JSTL). Jakarta has a free implementation. I'd also recommend reading Shawn Bayern's "JSTL In Action" book. You'll be up to speed with JSTL very quickly. It will provide a solution to what you're asking, if your deadline will allow you time to learn it. The book is very well-written and technically excellent, IMO. - MOD

  • Remove Event Listeners (at the right time)

    I have a app which loads multiple flv's, I also have a timer
    (digial) which shows how long the movie has been played for. The
    problem is that whenever i load and new move (through the same
    "loadVideos()" function, the timer variables ("lagTime", "endTime")
    are not reset (even though the correct variables are being passed.
    I believe it has something to do with the event listeners which are
    being used to load the movies. How can i clear all the listerner
    before reloading the movies?
    Here is a code snippet:
    Thanks in advance

    Thanks, kglad
    Yes it traces 'endTime' but what happens is that when i play
    the first movie is will display for example ("40,40,40,40" etc...)
    until the video stops playing. If i load another movie it will then
    trace ("40, 20, 40, 20, 40" etc...) so i need to kill the
    listereners and reload the variables.
    Jake

  • Managing various event listeners in multi-frame movie

    I'm working on a gunslinger game. I have numerous frames
    which correspond to different stages of the game. The frame that
    corresponds to the actual gameplay has a really involved
    ENTER_FRAME function attached to particular item on the stage. When
    the game is over (or an error occurs, or the network connection
    fails) I want to leave the gameplay frame and move to some other
    frame. When this happens, I would like the ENTER_FRAME function on
    the gunslinger to be removed because the player may finish a game
    and then re-enter the gameplay frame later after selecting a new
    opponent.
    QUESTION: Can anyone recommend a good way to manage the
    keyboard event listeners, all the button event listeners, etc? As
    you might imagine, I have no reliable way to determine which frame
    might be entered after the gameplay frame because the frame change
    could be triggered by a variety of different reasons.

    I have tried using hasEventListener to check for an existing
    ENTER_FRAME function before adding the event listener again but it
    never seems to notice that there is an existing enterframe function
    running. Furthermore, when I leave the frame, the enterframe
    function (which is attached to a particular movie clip on frame 2)
    continues to run even though that movie clip doesn't exist on any
    other frame in the flash movie.
    The first frame in my movie just has a button that takes the
    movie to frame 2. frame 2 has a movie clip (myMovie) and a button
    (btnFrame1) which goes back to frame 1. It also has the attached
    actionscript.
    I start the movie.
    I click 'goto frame 2'
    the enterframe listener is added and starts to output trace
    statements of the current frame of myMovie (e.g., 1-2-3).
    i click 'goto frame 1' on the main movie
    although i am looking at frame 1 of my main movie which has
    no instance of myMovie, the enterframe function keeps tracing the
    current frame--interestingly, the frame of myMovie does not
    advance...it stays on 1, 2, or 3 and announces that frame over and
    over again.
    Repeating the visit to frame 1 and frame2 over and over again
    results in more listeners being added over and over again.
    I have uploaded a sample FLA here:
    http://jaith.net/questions/listenerExample.zip
    I hope that you might help me determine how to remove the
    listener upon exiting this frame. I don't want that enterframe
    function running (and referring to movieclips that don't exist)
    when I exit the frame where it is relevant. I'm wondering if I
    should try adding the event listener to the root movie
    instead.

Maybe you are looking for

  • IPod no longer recognisable

    Hello, I have recently repaired my installation of Windows XP SP2 and since then, my iPod is no longer detected by Windows and iTunes nor the iPod updater. I have tried - Resetting the iPod. - Un/Reinstalling iTunes. - Trying another USB drive. - Unp

  • Blue screen error on resume, Sandisk U3 suspected

    Hi all, I have a T61 running WinXP. I've noticed that whenever the machine goes into hibernation with my flash drive inserted it crashes with a blue screen error on resumption. The drive i a sandisk cruzer with u3. Wondering if anyone has experience

  • Trying to import from different csv files into multiple JTables

    This might seem like something that isn't commonly done, but I'll see if anyone has done this before anyways. I currently have a JTable (tab #1) and it successfully reads in the data from a CSV file to populate the cells. Now, I am looking into makin

  • Using command click to select file in lion causes them to open--why?

    Lately a lot of routine things have become (for lack of a better word) sensitive in Lion.  I send an email and in about one in three it sends a duplicate.  If I am trying to place edited text in an email or word document I cannot get the cursor place

  • IDOC's missing

    Hi, I have an error in support. please send me the answer. in ODS in it is showing red 0 from 0 recrods. but in status of this ODS it is telling that "No Idocs generated; file system". after that i went and also saw the short dump. it is telling ther