Why JSlider event listener no response?

Thanks,
hi, the JSlider does exist, but when it slides, data is unchanged.
Please help.
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.util.Hashtable;
import java.awt.event.*;
import javax.swing.event.*;
// import AppletAndApplicationExample.AppQuitter;
public class Combox extends JApplet
    private LayoutManager Layout;
    private Container Panel;
    private Drawing drawing;
  ..    private String energyId[];
    private int numberofCells;
    private int numberofsets;
    private int id; //PlotEnergyId
    private double lineWidth;
    private int min = 1, max = 16, inc = 5;
    double scale = 1.0;
    private String currentPattern;
    private JSlider dJSlider;
      public void init() {
         Layout = new BorderLayout ();
         getDrawingData();                               
                dJSlider = new JSlider(min, max, 6);
                drawing = new Drawing();
        Panel = getContentPane();
        Panel.setLayout (Layout);
        Panel.add (drawing, "Center");
        JPanel sliderPanel = new JPanel();
        sliderPanel.setLayout(new BoxLayout(sliderPanel,
                               BoxLayout.PAGE_AXIS));
                        dJSlider.setAlignmentX(Component.LEFT_ALIGNMENT);
        sliderPanel.add(dJSlider);
        dJSlider.setMajorTickSpacing(5);
        dJSlider.setMinorTickSpacing(1);
        dJSlider.setSnapToTicks(true);
        dJSlider.setLabelTable(getLabelTable(min, max, inc));
        dJSlider.setPaintTicks(true);
        dJSlider.setPaintLabels(true);
        dJSlider.addChangeListener(
                new ChangeListener() // anonymous inner class
                // handle change in slider value
                    public void stateChanged(ChangeEvent e)
                       int value = ((JSlider)e.getSource()).getValue();
                       scale = (value+4)/10.0;
                    Panel.add(sliderPanel,BorderLayout.NORTH); // ADD Slider
                    scaleData(); // use JSlider to obtain new data
                    System.out.println(scale);// found unchaged data,scale =1,why???
     private Hashtable getLabelTable(int min, int max, int inc) {
        Hashtable<Integer, JLabel> table = new Hashtable<Integer, JLabel>();
        for(int j = min; j <= max; j+=inc) {
            String s = String.format("%.1f", (j+4)/10.0);
            table.put(Integer.valueOf(j), new JLabel(s));
        return table;
    public void getDrawingData()
    public void scaleData()
        for(int i = 0; i < numberofCells; i++)
              for(int j = 0; j<cellsPointsNumber; j++)
xCells[i][j] = (xCells[i][j])*scale+TRANSITION;
yCells[i][j] = (yCells[i][j])*scale+TRANSITION;
public static void main(String[] args) {
/* Set up the frame that holds the applet. */
JFrame appletFrame = new JFrame("My Applet");
Applet theApplet = new Combox();
appletFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
appletFrame.setSize(800,800);
appletFrame.add(theApplet, "Center"); // applet fills
// frame
/* Now start invoking applet methods. */
theApplet.init();
// applet
appletFrame.show(); // bring frame and initialized
// applet on screen
theApplet.start();
theApplet.stop();
theApplet.destroy();
} // end class 

System.out.println(scale);// [b]found unchaged data,scale =1,why???[/b]scale is 1 because you set it to 1.0 initially and you never changed it. Notice that this line is executed just once in the init() method. It is not part of the change listener.

Similar Messages

  • Keyboard Event Listener doesn't work in Browser

    Is there a reason why a keyboard event listener would not work if the flash is embedded in an HTML? The rest of my game is running fine in the background, but I can't launch the movieClip "nextCar." My code is below, if that makes any difference...
    function goNow (event:KeyboardEvent): void {
        thisOtherKey = event.keyCode;
        if (thisOtherKey == 32) {
            nextCar.gotoAndPlay(2);
            parkingQue.play();
            tries++;
    stage.addEventListener(KeyboardEvent.KEY_DOWN, goNow);

    This may be a silly question, but have you tryed clicking on your swf after it opens up in the browser, and then trying the keyboard controls?
    I don't know of any issues that cause event listeners to workwhen debugging, but not in a browser.  So, I'm thinking maybe your just not focused on the swf.

  • BeforeSave event listener reverting doc to unsaved [AS, CS5]

    Hi,
    I've got an AppleScript, which is triggered by a beforeSave event listener.  This script makes some modifications to the active document, and then the save proceeds.  The problem I'm encountering is that, after the save, the document appears as saved momentarily, but then immediately reverts back to unsaved.  This is evident by an asterisk disappearing and reappearing next to the document name in the document window's title bar.  If I comment out the document modification code, the save works as expected. 
    It seems like maybe the save is continuing while the script is still in progress, and this is why the document reverts to unsaved.  However, shouldn't the beforeSave event take place before the save occurs, and not proceed until the script has finished executing?
    Things I've checked and/or tried…
    * I've checked to see if somehow my script is being triggered a second time after the save is complete.  It is not.
    * I've tried having my script save the document on completion, but this fails because the database is busy.
    * I've tested with beforeSaveAs, and it encounters the same problem.
    * I've tested on multiple machines.  What's weird is that it occurs on some, and not on others.  So, it's not consistent.
    * I have seen the problem in Mac OS X 10.5.x and 10.6.x.  I have not tested it in 10.7.x yet.
    * I have seen the problem with CS5, but have not yet encountered it with 5.5.
    Anyone have any thoughts or suggestions?
    Thanks,
    -Ben

    Thanks for the ideas regarding beforeInvoke, Ben.  I will try to check that out.  In my situation, here's essentially how my script is working...
    BeforeSave is invoked.
    Script makes a change to the document, which should be captured in the saved file.
    Document saves.
    Document appears saved for a moment, and then appears unsaved (asterisk in the document title).
    My biggest problem is that this behavior isn't consistent.  I have dozens of users, all running the same script, and the problem only occurs with certain users and at random times. I can move a problematic document from a user's machine to a different machine, and the problem doesn't occur there.  It's very difficult to troubleshoot because I can't reproduce it consistently.

  • Event Listener dispatcher giving an ClassCast Exception in C++ 3.6.1

    Hi,
    I have attached a Event listener to underlying NamedCache and when I update the cache entry I didn't get any alerts. But When I checked the
    coherence log I found following Exception available. But I'm not doing any sort of Casting as mentioned below.
    2012-01-17 11:12:55.793/0.320 Oracle Coherence for C++ RTC 3.6.1.0 <Info> (thread=main): Connected Socket to 169.52.37.237/169.52.37.237:9099
    2012-01-17 11:13:04.859/9.386 Oracle Coherence for C++ RTC 3.6.1.0 <Error> (thread=ExtendTcpCacheService:coherence::component::util::TcpInitiator:coherence::component::util::Service::EventDispatcher): An exception occurred while dispatching the following event:
    coherence::component::util::RunnableCacheEvent: coherence::util::MapListenerSupport::FilterEvent{coherence::component::net::extend::RemoteNamedCache::BinaryCache[source=coherence::component::net::extend::RemoteNamedCache::BinaryCache@0x69f090c4] updated: key=Binary(length=19), old value=Binary(length=713), new value=Binary(length=713), filters=[NULL]}
    2012-01-17 11:13:04.860/9.387 Oracle Coherence for C++ RTC 3.6.1.0 <Error> (thread=ExtendTcpCacheService:coherence::component::util::TcpInitiator:coherence::component::util::Service::EventDispatcher): The following exception was caught by the event dispatcher:
    2012-01-17 11:13:04.860/9.387 Oracle Coherence for C++ RTC 3.6.1.0 <Error> (thread=ExtendTcpCacheService:coherence::component::util::TcpInitiator:coherence::component::util::Service::EventDispatcher): NULL
    coherence::lang::ClassCastException: attempt to cast from a "gce::coherence::CoherenceEventHandler" to a "coherence::util::MapListener" at void coherence::lang::coh_throw_class_cast(const std::type_info&, const std::type_info&)(ClassCastException.cpp:27)
    at coherence::lang::coh_throw_class_cast(std::type_info const&, std::type_info const&)
    at coherence::lang::TypedHandle<coherence::util::MapListener> coherence::lang::cast<coherence::lang::TypedHandle<coherence::util::MapListener>, coherence::lang::Object>(coherence::lang::TypedHandle<coherence::lang::Object> const&, bool)
    at coherence::lang::TypedHandle<coherence::util::MapListener> coherence::lang::cast<coherence::lang::TypedHandle<coherence::util::MapListener>, coherence::lang::Object>(coherence::lang::TypedHolder<coherence::lang::Object> const&, bool)
    at coherence::lang::TypedHandle<coherence::util::MapListener> coherence::lang::cast<coherence::lang::TypedHandle<coherence::util::MapListener>, coherence::lang::Object>(coherence::lang::MemberHolder<coherence::lang::Object> const&, bool)
    When I wrote a sample application It works without any problem. Only difference of above exception coming program is this c++ library is loaded true JNI and relevant event listener is added during a JNI method call. Please explain me why this exception is coming. I have attached the relevant code as well.
    CoherenceEventListener.hpp
    * File: CoherenceEventHandler.hpp
    * Author: srathna1
    * Created on 05 January 2012, 10:15
    #ifndef COHERENCEEVENTHANDLER_HPP
    #define     COHERENCEEVENTHANDLER_HPP
    #include "coherence/util/MapEvent.hpp"
    #include "coherence/util/MapListener.hpp"
    #include <iostream>
    //#include <map>
    #include "coherence/lang.ns"
    #include "mihelper.hpp"
    #include "MiCoherence.hpp"
    #include <string>
    #include "MICoherenceDataObject.hpp"
    using coherence::util::MapEvent;
    using coherence::util::MapListener;
    using namespace coherence::lang;
    * A MapListener implementation that prints each event as it receives
    * them.
    namespace gce {
    namespace coherence {
    class CoherenceEventHandler
    : public class_spec<CoherenceEventHandler,
    extends<Object>,
    implements<MapListener> > {
    friend class factory<CoherenceEventHandler>;
    public:
    CoherenceEventHandler(CMiCoherence * miCoh) : mi(miCoh), msgSeqNo(1) {
    virtual void entryInserted(MapEvent::View vEvent) {
    Object::View vKey = vEvent->getKey();
    String::View key = cast<String::View > (vKey);
    Object::View vValue = vEvent->getNewValue();
    char topic[100];
    strcpy(topic, key->getCString());
    Managed<gce::coherence::MICoherenceDataObject>::View pos = cast<Managed<gce::coherence::MICoherenceDataObject>::View > (vValue);
    std::cout << key << " = " << pos << std::endl;
    virtual void entryUpdated(MapEvent::View vEvent) {
    Object::View vKey = vEvent->getKey();
    String::View key = cast<String::View > (vKey);
    Object::View vValue = vEvent->getNewValue();
    char topic[100];
    strcpy(topic, key->getCString());
    Managed<gce::coherence::MICoherenceDataObject>::View pos = cast<Managed<gce::coherence::MICoherenceDataObject>::View > (vValue);
    std::cout << key << " = " << pos << std::endl;
    gce::coherence::MICoherenceDataObject msg = *pos;
    virtual void entryDeleted(MapEvent::View vEvent) {
    private:
    CMiCoherence * mi;
    int msgSeqNo;
    #endif     /* COHERENCEEVENTHANDLER_HPP */
    Event Registration code
    NamedCache::Handle miCoherenceCache = NULL;
    try {
    String::View cacheName = szConnect;
    miCoherenceCache = CacheFactory::getCache(cacheName);
    } catch (const std::exception& e) {
    LOGERR("initializing coherence middleware cache error: %s", e.what());
    return MI_ERR_BADSTATE;
    nConnectState = miCoherenceCache->getCacheService()->isRunning() == true ? 1 : 0;
    miCoherenceCache->addFilterListener(gce::coherence::CoherenceEventHandler::create(this));
    Please give me a clue why Cohrence Internal Event Dispatcher giving exception.....
    Thanks and regards,
    Sura

    Hi,
    Even when I try to to test the MemberListener while closing the Coherene Java Cache Cluster I can see following Exception. Something similar to EventListener.
    2012-01-18 20:06:18.868/44.346 Oracle Coherence for C++ RTC 3.6.1.0 <Error> (thread=ExtendTcpCacheService:coherence::component::util::TcpInitiator:coherence::component::util::Service::EventDispatcher): The following exception was caught by the event dispatcher:
    2012-01-18 20:06:18.868/44.346 Oracle Coherence for C++ RTC 3.6.1.0 <Error> (thread=ExtendTcpCacheService:coherence::component::util::TcpInitiator:coherence::component::util::Service::EventDispatcher): NULL
    coherence::lang::ClassCastException: attempt to cast from a "gce::coherence::CoherenceMemberListener" to a "coherence::net::MemberListener"
    at void coherence::lang::coh_throw_class_cast(const std::type_info&, const std::type_info&)(ClassCastException.cpp:27)
    at coherence::lang::coh_throw_class_cast(std::type_info const&, std::type_info const&)
    at coherence::lang::TypedHandle<coherence::net::MemberListener> coherence::lang::cast<coherence::lang::TypedHandle<coherence::net::MemberListener>, coherence::lang::Object>(coherence::lang::TypedHandle<coherence::lang::Object> const&, bool)
    at coherence::lang::TypedHandle<coherence::net::MemberListener> coherence::lang::cast<coherence::lang::TypedHandle<coherence::net::MemberListener>, coherence::lang::Object>(coherence::lang::TypedHolder<coherence::lang::Object> const&, bool)
    at coherence::lang::TypedHandle<coherence::net::MemberListener> coherence::lang::cast<coherence::lang::TypedHandle<coherence::net::MemberListener>, coherence::lang::Object>(coherence::lang::MemberHolder<coherence::lang::Object> const&, bool)
    at coherence::net::MemberEvent::dispatch(coherence::lang::TypedHandle<coherence::util::Listeners const>) const
    at coherence::component::util::ListenerCallback::translateMemberEvent(coherence::lang::TypedHandle<coherence::net::MemberEvent const>)
    at coherence::component::util::ListenerCallback::memberLeaving(coherence::lang::TypedHandle<coherence::net::MemberEvent const>)
    at coherence::net::MemberEvent::dispatch(coherence::lang::TypedHandle<coherence::util::Listeners const>) const
    at coherence::component::net::extend::RemoteService::dispatchMemberEvent(coherence::net::MemberEvent::Id)
    at coherence::component::net::extend::RemoteService::connectionError(coherence::lang::TypedHandle<coherence::net::messaging::ConnectionEvent const>)
    at coherence::component::net::extend::RemoteCacheService::connectionError(coherence::lang::TypedHandle<coherence::net::messaging::ConnectionEvent const>)
    at coherence::net::messaging::ConnectionEvent::dispatch(coherence::lang::TypedHandle<coherence::util::Listeners const>) const
    at coherence::component::util::Peer::DispatchEvent::run()
    at coherence::component::util::Service::EventDispatcher::onNotify()
    at coherence::component::util::Daemon::run()
    at coherence::lang::Thread::run()
    on thread "ExtendTcpCacheService:coherence::component::util::TcpInitiator:coherence::component::util::Service::EventDispatcher"
    Seems to be like loading with JNI will giving some exceptions.
    Please help me on this...
    Thanks and regards,
    Sura

  • Why does Event.ENTER_FRAME cause this code to stop working? Is there a better alternative?

    I programmed the following code so that an array of buttons
    can be dragged across the screen when either on :
    var buttons:Array=[button1, button2, button3];
    for (var i:uint=0; i<buttons.length; i++)
    buttons[i].addEventListener(MouseEvent.CLICK, alignButtons )
    function alignButtons (e:Event)
         for (var i2:uint=0; i2<buttons.length; i2++)
          if(buttons[i2]!=e.target){buttons[i2].x=e.target.x;}
         for (var i3:uint=0; i3<buttons.length; i3++)
         buttons[i3].addEventListener(MouseEvent.MOUSE_DOWN, buttonDrag);
         function buttonDrag (e:Event)
        e.target.startDrag();
        e.target.addEventListener(MouseEvent.MOUSE_UP, buttonDrop);
        function buttonDrop(e:Event)
              e.target.stopDrag();    
    It works pretty much how I'd like it to work, except for the fact that I have to click the mouse to update the screen. However, when I change the first event listener from "MouseEvent.CLICK" to "Event.ENTER_FRAME" the code goes haywire. Is there another event listener I should be using here?

    Due to what appears to be an incomplete set of curly braces, it is hard to tell how much nesting you have there, but there should be none.  Each listener and event handler function should be able to stand on its own.  You should not have to put any functions inside a loop.
    Having the CLICK event listener is redundant if you have a MOUSE_DOWN and a MOUSE_UP because a MOUSE_DOWN followed by a MOUSE_UP is a CLICK. 
    If your goal is to have the buttons all follow each other around x-wise, then what you can do is assign a MOUSE_MOVE event listener at the same time you execute the startDrag and use its event handler for adjust button positions.  When you stopDrag, you also remove the MOUSE_MOVE listener.
    As far as why things go haywire when you change to using an ENTER_FRAME, you should show the code when it is in that form so that whatever error is evident.

  • Which object in hierarchy should add event listener?

    Hello all,
    I'm quite new to the whole OOP thing, and one of the things I keep wondering about is this:
    Which class should listen for events if the choice is between a contained class or a containing class?
    For example:
    An instance of Game holds an instance of Board which holds an array of instances of fields.
    This might be a scenario for a simple board game, I guess (In my case I am working on Reversi).
    A player should click a field to place a piece on it. I could let the Field class listen for the click event,
    but when a player places a piece, other pieces might have to flip, so an object at a higher level should handle this (board / game / maybe another object).
    So in order to make sure this happens, I could let the field object listen for the event and than tell the higher-level-object to do his thing, or I could
    let the higher-level-object add an event listener on the field object, and than both flip the nescesary pieces as well as tell the field to add a piece on itself.
    Could anyone explain which and why either solution (or maybe a third on) is better?
    Thanks for your time!

    qdudu wrote:
    Hello all,
    I'm quite new to the whole OOP thing, and one of the things I keep wondering about is this:
    Which class should listen for events if the choice is between a contained class or a containing class?The class that can respond to the events should implement the Listener.
    For example:
    An instance of Game holds an instance of Board which holds an array of instances of fields.
    This might be a scenario for a simple board game, I guess (In my case I am working on Reversi).
    A player should click a field to place a piece on it. I could let the Field class listen for the click event,
    but when a player places a piece, other pieces might have to flip, so an object at a higher level should handle this (board / game / maybe another object).Sounds like Board would be a good choice, then.
    So in order to make sure this happens, I could let the field object listen for the event and than tell the higher-level-object to do his thing, or I could
    let the higher-level-object add an event listener on the field object, and than both flip the nescesary pieces as well as tell the field to add a piece on itself.Sounds like the field object can't do much except forward the event to the real handler. In that case I'd vote for the higher-level-object as the listener.
    Could anyone explain which and why either solution (or maybe a third on) is better?In this case it could be either one. Try both and see. But based on the little you've posted here I'd vote for the higher-level-object, the Board.
    %

  • When calling webservice Session event listener threw exception

    Hi All,
    I have Schdule the process to call webservice for 1 hour.
    When it accessed It is throwing Exception But data send to Server and received response as true from webservice.
    Exception details found in log file.
    2007-12-04 01:00:36 StandardManager[npbpqa] Session event listener threw exception
    java.lang.IllegalStateException: getAttribute: Session already invalidated
         at org.apache.catalina.session.StandardSession.getAttribute(StandardSession.java:925)
         at org.apache.catalina.session.StandardSessionFacade.getAttribute(StandardSessionFacade.java:124)
         at org.apache.axis.transport.http.AxisHTTPSessionListener.destroySession(AxisHTTPSessionListener.java:43)
         at org.apache.axis.transport.http.AxisHTTPSessionListener.sessionDestroyed(AxisHTTPSessionListener.java:72)
         at org.apache.catalina.session.StandardSession.expire(StandardSession.java:623)
         at org.apache.catalina.session.StandardSession.expire(StandardSession.java:572)
         at org.apache.catalina.session.StandardManager.processExpires(StandardManager.java:746)
         at org.apache.catalina.session.StandardManager.run(StandardManager.java:823)
         at java.lang.Thread.run(Thread.java:534)
    Can any one help me urgently.
    Thanks in advance.
    Venkat K
    Edited by: venkat2007 on Dec 4, 2007 2:44 PM

    The service is working fine from a web page that my coworker did.  I have not installed soap UI yet, but I used it at my last job.  Since I posted this I have a new computer, have installed BizTalk Server 2013 R2 and Visual Studio 2013 Premium.
     This is what I've done...
    Created a new Host called BizTalkServerApplication64 with the '32-Bit only' unchecked.
    Created a new host instance using the new host.
    Created a new Send Handler for both Adapters 'WCF-BasicHttp' and 'WCF-Custom' using the new host.
     configured both Send Ports (WCF-BasicHttp and WCF-Custom) to use the new send handler.
    Have tried binding the logical port to both basic and the custom ports.
    Now I get a different error which is:
    Error Description: System.ServiceModel.CommunicationException: An error occurred while receiving the HTTP response to http://lbenson/MDSVC2/Service1.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due
    to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. --->
    System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host...
    Any suggestions for this error?  I'm not sure if this means I'm closer to getting it work or further.
    Thanks for your help!
    Jean
    jRenae.s

  • Why KEY-COMMIT didn't response??????????

    why KEY-COMMIT didn't response??????????
    my Program Units is LYH:
    LYH(Package Spec):
    PACKAGE LYH IS
    PROCEDURE EVENT(EVT in VARCHAR2);
    END;
    LYH(Package Body):
    PACKAGE BODY LYH IS
    procedure EVENT(EVT in VARCHAR2) is
    TYPE Array1 IS TABLE OF VARCHAR2(100) INDEX BY BINARY_INTEGER;
    arr_department_code Array1;
    j2 number:=1;
    BEGIN
    --if EVT='POST-CHANGE' then     
    if EVT='KEY-COMMIT' then
              -- insert into XCT_EQ_PRODUCTIONS
         -- ITEM_NAME)
    --     VALUES
         -- :XCT_EQ_PRODUCTIONS.ITEM_NAME);
         --'lllllllllllllll');
         -- commit;
         FND_MESSAGE.DEBUG('AAAA');     
         go_block('XCT_EQ_PRODUCTIONS');
    first_record;
    j2:=1;
    loop
         arr_department_code(j2):=:XCT_EQ_PRODUCTIONS.DEPARTMENT_CODE;
    exit when :system.last_record='TRUE';
         next_record;     
         j2:=j2+1;
    end loop;     
    for ii in 1..arr_department_code.last loop
              if arr_department_code(ii)=arr_department_code(ii+1) then
                   FND_MESSAGE.DEBUG('two same department');
              --     exit ;
                   RAISE FORM_TRIGGER_FAILURE;
              end if;
    end loop;
    END IF;
    END EVENT;     
    END LYH;
    I call LYH in KEY-COMMIT trigger(Data Blocks)
    LYH.EVENT('KEY-COMMIT');
    why din't show message'two same department is forbidden' when i typed two same department name 'EP4100' i running the form

    yes,
    Oracle E-Business Suite 11i,
    Now Generate the form file ......
    Compile Successful !!!
    i upload the file XWPF539L.fmb ,then run,my code have FND_MESSAGE.DEBUG('two same department is forbidden');
    but din't show message'two same department is forbidden' when i typed two same department name 'EP4100'

  • Actionscript 3 - Multiple variables for event listener.

    Ok, I have a question (of course that is the reason why I am here).  I have been focusing on PHP a lot lately and just had a client that requires an MP3 player playing multiple songs so I had to whip out my rusty actionscript skills.  I have the player completed and it is working as desired.  The down side is it has multiple songs.  I am using separate functions for each song and separate event listeners.  My main question is there a way to combine these funtions into one and just use the event listener to pass another variable to the functions?  Below is a sample of one of the code for Song1.  I would like to make it so anywhere there is Song1 in the code, I can make it a variable so I can put in for example (Song2, Song3, Song4, etc.)  This way, I can have one or two functions handle all the songs instead of having to copy, paste and then find and replace.
    Thanks for the help!
    // Song 1
    var Song1:Sound = new Sound();
    pbSong1.source = Song1;
    //pbSong1.visible = false;
    var Song1Loaded:Boolean = false;
    pbSong1.addEventListener(Event.COMPLETE, Song1LoadComplete);
    btnSong1Play.addEventListener(MouseEvent.CLICK, Song1Play);
    btnSong1Stop.addEventListener(MouseEvent.CLICK, Stop);
    function Song1Play(event:MouseEvent) {
         if (Song1Loaded == true) {
              sndchnlMain.stop();
              sndchnlMain = Song1.play();
         } else {
              pbSong1.visible = true;
              Song1.load(new URLRequest("media/music/Song1.mp3"));
    function Song1LoadComplete(event:Event) {
         trace("Size of file: " + Song1.bytesTotal);
         Song1.close();
         Song1Loaded = true;
         if(sndchnlMain) {
              sndchnlMain.stop();
         sndchnlMain = Song1.play();
         pbSong1.visible = false;

    But if I reset the bolean to false, if the visitor goes to replay that song, it will try to load the song again.  I did find away around having to the use the boolean value though and accomplish the same thing (I am loving this).  I am using:
    this["Song"+SongNum].bytesTotal
    If there are bytes, then the song is loaded OR loading.  In order to check if the song is completely loaded before it plays, I am using this:
    this["Song"+SongNum].bytesTotal == this["Song"+SongNum].bytesLoaded
    This elimates the need for the Boolean I was using.  Also instead of for each song defining:
    pbSong1.source = Song1;
    I am using the main function to do it for me:
    this["pbSong"+SongNum].source = this["Song"+SongNum];
    The reason why I asked about the Sound variable, I was currious if I could do the same with it as I did with the Progress Bar Source as shown above?  Instead of defining this first:
    var Song1:Sound = new Sound();
    Can I do this in the function:
    var this["Song"+SongNum]:Sound = new Sound();
    I tried it once but I got an error.
    Here is the new FULL updated code:
    import fl.controls.ProgressBar;
    import flash.events.ProgressEvent;
    import flash.events.IOErrorEvent;
    import flash.net.URLRequest;
    import flash.media.SoundChannel;
    import flash.media.Sound;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.display.MovieClip;
    var sndchnlMain:SoundChannel;
    ClearNowPlaying();
      Song 1 Definitions
    var Song1:Sound = new Sound();
    pbSong1.addEventListener(Event.COMPLETE, LoadComplete);
    btnSong1Play.addEventListener(MouseEvent.CLICK, PlaySong);
    btnSong1Stop.addEventListener(MouseEvent.CLICK, Stop);
      Song 2 Definitions
    var Song2:Sound = new Sound();
    pbSong2.addEventListener(Event.COMPLETE, LoadComplete);
    btnSong2Play.addEventListener(MouseEvent.CLICK, PlaySong);
    btnSong2Stop.addEventListener(MouseEvent.CLICK, Stop);
      Song 3 Definitions
    var Song3:Sound = new Sound();
    pbSong3.addEventListener(Event.COMPLETE, LoadComplete);
    btnSong3Play.addEventListener(MouseEvent.CLICK, PlaySong);
    btnSong3Stop.addEventListener(MouseEvent.CLICK, Stop);
      Song 4 Definitions
    var Song4:Sound = new Sound();
    pbSong4.addEventListener(Event.COMPLETE, LoadComplete);
    btnSong4Play.addEventListener(MouseEvent.CLICK, PlaySong);
    btnSong4Stop.addEventListener(MouseEvent.CLICK, Stop);
      Song 5 Definitions
    var Song5:Sound = new Sound();
    pbSong5.addEventListener(Event.COMPLETE, LoadComplete);
    btnSong5Play.addEventListener(MouseEvent.CLICK, PlaySong);
    btnSong5Stop.addEventListener(MouseEvent.CLICK, Stop);
      Universal Functions
    function Stop(event:MouseEvent) {
         sndchnlMain.stop();
         ClearNowPlaying();
    function PlaySong(event:MouseEvent) {
         var SongNum:int = Number(event.currentTarget.name.split("btnSong").join("").split("Play").join(""));
         if (this["Song"+SongNum].bytesTotal) {
              if (this["Song"+SongNum].bytesTotal == this["Song"+SongNum].bytesLoaded) {
                   sndchnlMain.stop();
                   ClearNowPlaying();
                   this["NowPlayingSong"+SongNum].visible = true;
                   sndchnlMain = this["Song"+SongNum].play();
         } else {
              this["pbSong"+SongNum].source = this["Song"+SongNum];
              this["pbSong"+SongNum].visible = true;
              this["Song"+SongNum].load(new URLRequest("media/music/Song"+SongNum+".mp3"));
    function LoadComplete(event:Event) {
         var SongNum:int = Number(event.currentTarget.name.split("pbSong").join(""));
         trace("Size of file: " + this["Song"+SongNum].bytesTotal);
         this["Song"+SongNum].close();
         this["Song"+SongNum+"Loaded"] = true;
         if(sndchnlMain) {
              sndchnlMain.stop();
         ClearNowPlaying();
         this["NowPlayingSong"+SongNum].visible = true;
         sndchnlMain = this["Song"+SongNum].play();
         this["pbSong"+SongNum].visible = false;
    function ClearNowPlaying() {
         NowPlayingSong1.visible = false;
         NowPlayingSong2.visible = false;
         NowPlayingSong3.visible = false;
         NowPlayingSong4.visible = false;
         NowPlayingSong5.visible = false;

  • Stage event listener in actionscript won't wait in captivate

    I have an SWF file that is done in AS3. It works fine both in Flash and published as an SWF.
    Problem shows up when I bring it into captivate.
    I need the the event listener attached to the stage because it's an if/else statement that has the student click either one specific button or get an error message if there's a click ANYWHERE else. The problem is "stage" is not restricted to the area of the flash animation. It uses the whole screen in captivate to mean stage. As soon as captivate displays the animation, it acts as if moving into the slide was a click and shows the error message before the user has done anything. I suspect this has something to do with Captivates using its stage which becomes the parent stage but I'm not sure how to fix it. Any ideas?
    Please don't ask me to build the interactives directly in Captivate 5. We tried that and after the 4th one in the module, feedback captions lag so long they are completely useless for learning. Yes, I broke out the module into smaller sections and tried publishing as chapters. It made no difference. Any interactive after the 4th one, when built in captivate, would not change the response rate of feedback captions even when it was a slide alone in its own swf file.

    well I have a sort-of-work-around if anyone else is running into this.
    I extended the timeline by about 10 frames in my Flash file and placed the actions keyframe at the 10th with a stop(); in the first line.
    When I brought the published swf into captivate 5 I put it on the stage alone with another text button for moving to the next slide so the slide will pause until the learner wishes to move on. I made the timeline about 5 seconds long and placed the button in the center of its layer with the swf above going the duration of the slide. Placing the pauser in the center allows the movie to display fully and the interactions in the animation now wait patiently for the user to do something. I'm sure there a code based solution, but there's only so much time in the world.

  • 1 event listener, many events source

    i have 3 different classes. 2 listens for read() from RS232, while 1 listens for read() from a socket
    When any of the 3 registers a read, i will need to fire a thread with inputs from the event that processes my business logic
    Most probably i will need a listener that reacts to any of the 3 events after which, spunning a thread to handle the inputs from the event and
    then in a forever loop to continue to wait for new events
    From what i've read, it seems that i will need a EventListener that listens to the 2 RS232 events and 1 Socket event
    I am pretty new to the whole event listener concept, is there any reference code that i can take a peek at?
    Many Thanks

    There's no reason why the same EventListener can't be added to serveral event sources. (That's why there's a getSource() in the EventObject class).

  • Invoking event listener

    I'm new to reflection api and would like to know whether it's possible or not using Method class to invoke event listener without using awt or swing? And if it's possible some sample code would be nice.

    I mean I don't want to use gui components. In fact
    I'm writing console program. I just want to use event
    listener to implement keyboard listener(pressing
    buttons).Oh. That won't work. To capture events from the console, you'll be needing to dabble with native code. AWT events are generated by AWT components, in response to events from the underlying windowing system

  • Newbe: Redirect from an event listener

    We are using WLP 10.
    I have created an event listener and I want to redirect the user when the attached event is triggered. I see that the handleEvent function receives a parameter of type Event, which has the session_id as a string parameter. But how do I actually make the redirection using that Event object? Or is there any way to retrieve the request?
    I have looked through the documentation and searched for examples but without any luck...
    Many thanks,
    Dan

    Having a look at the Interaction documentation for WLP 10, apparently this should be possible. And it should also be possible to have real-time response from the listeners:
    Understanding When to Create a Custom Event Listener
    http://edocs.bea.com/wlp/docs100/interaction/interaction.html#wp1010357
    Extact:
    Create a custom event listener if you want to execute functionality not provided by the Campaign listener or the Behavior Tracking listener. For example, if you want to perform your own event data persistence, modify a User Profile, redirect the user to another part of a Page Flow, or provide any other type of real-time response to the event, create a custom event listener that provides the functionality you want.

  • Flash player on the new mac sarafi can't use keyboard and event listener

    flash player on the new mac sarafi can't use keyboard and event listener
    cn:英文有些差不好意思,附上中文说明:在flash player web 开发时,我在最新版本的sarafi上,目前出现不能响应键盘事件bug,为了验证是不是我本地问题,我也用在多款别的网页游戏上进行测试,全有这个bug,另外,有时还有那个fp弹出本地 缓存提示设置窗口也点不了“允许或拒绝“那些按钮

    Now after 5 weeks, you have always not resolved this very important and urgent issue. It seems that Adobe has realy abandonned the actionscript / flash player projects. Why not simply discontinue flash player on desktops too ? Or even better remove or block "automaticaly" all flash players with the final update. That could create a serious issue on the Internet for few weeks but at least that will be honorable end like a Samurai's Seppuku...

  • Adding an event listener to combo box

    I am working on a mortgage calculator and I cannot figure out how to add an event listener to a combo box.
    I want to get the mortgage term and interest rate to calucate the mortgage using the combo cox. Here is my program.
    Modify the mortgage program to allow the user to input the amount of a mortgage
    and then select from a menu of mortgage loans: 7 year at 5.35%, 15 year at 5.50%, and
    30 year at 5.75%. Use an array for the different loans. Display the mortgage payment
    amount. Then, list the loan balance and interest paid for each payment over the term
    of the loan. Allow the user to loop back and enter a new amount and make a new
    selection, with resulting new values. Allow user to exit if running as an application
    (can't do that for an applet though).
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.text.NumberFormat;
    import java.util.Locale;
    //creates class MortgageCalculator
    public class MortgageCalculator extends JFrame implements ActionListener {
    //creates title for calculator
         JPanel row = new JPanel();
         JLabel mortgageCalculator = new JLabel("MORTGAGE CALCULATOR", JLabel.CENTER);
    //creates labels and text fields for amount entered          
         JPanel firstRow = new JPanel(new GridLayout(3,1,1,1));
         JLabel mortgageLabel = new JLabel("Mortgage Payment $", JLabel.LEFT);
         JTextField mortgageAmount = new JTextField(10);
         JPanel secondRow = new JPanel();
         JLabel termLabel = new JLabel("Mortgage Term/Interest Rate", JLabel.LEFT);
         String[] term = {"7", "15", "30"};
         JComboBox mortgageTerm = new JComboBox(term);
         JPanel thirdRow = new JPanel();
         JLabel interestLabel = new JLabel("Interest Rate (%)", JLabel.LEFT);
         String[] interest = {"5.35", "5.50", "5.75"};
         JComboBox interestRate = new JComboBox(interest);
         JPanel fourthRow = new JPanel(new GridLayout(3, 2, 10, 10));
         JLabel paymentLabel = new JLabel("Monthly Payment $", JLabel.LEFT);
         JTextField monthlyPayment = new JTextField(10);
    //create buttons to calculate payment and clear fields
         JPanel fifthRow = new JPanel(new GridLayout(3, 2, 1, 1));
         JButton calculateButton = new JButton("CALCULATE PAYMENT");
         JButton clearButton = new JButton("CLEAR");
         JButton exitButton = new JButton("EXIT");
    //Display area
         JPanel sixthRow = new JPanel(new GridLayout(2, 2, 10, 10));
         JLabel displayArea = new JLabel(" ", JLabel.LEFT);
         JTextArea textarea = new JTextArea(" ", 8, 50);
    public MortgageCalculator() {
         super("Mortgage Calculator");                     //title of frame
         setSize(550, 350);                                             //size of frame
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         Container pane = getContentPane();
         GridLayout grid = new GridLayout(7, 3, 10, 10);
         pane.setLayout(grid);
         pane.add(row);
         pane.add(mortgageCalculator);
         pane.add(firstRow);
         pane.add(mortgageLabel);
         pane.add(mortgageAmount);
         pane.add(secondRow);
         pane.add(termLabel);
         pane.add(mortgageTerm);
         pane.add(thirdRow);
         pane.add(interestLabel);
         pane.add(interestRate);
         pane.add(fourthRow);
         pane.add(paymentLabel);
         pane.add(monthlyPayment);
         monthlyPayment.setEnabled(false);
         pane.add(fifthRow);
         pane.add(calculateButton);
         pane.add(clearButton);
         pane.add(exitButton);
         pane.add(sixthRow);
         pane.add(textarea); //adds texaarea to frame
         pane.add(displayArea);
         setContentPane(pane);
         setVisible(true);
         //Adds Listener to buttons
         calculateButton.addActionListener(this);
         clearButton.addActionListener(this);
         exitButton.addActionListener(this);
         mortgageTerm.addActionListener(this);
         interestRate.addActionListener(this);
    public void actionPerformed(ActionEvent event) { 
         Object command = event.getSource();
         JComboBox mortgageTerm = (JComboBox)event.getSource();
         String termYear = (String)mortgageTerm.getSelectedItem();
    if (command == calculateButton) //calculates mortgage payment
         int year = Integer.parseInt(mortgageTerm.getText());
         double rate = new Double(interestRate.getText()).doubleValue();
         double mortgage = new Double(mortgageAmount.getText()).doubleValue();
         double interest = rate /100.0 / 12.0;
         double monthly = mortgage *(interest/(1-Math.pow(interest+1,-12.0 * year)));
                   NumberFormat myCurrencyFormatter;
                   myCurrencyFormatter = NumberFormat.getCurrencyInstance(Locale.US);
                   monthlyPayment.setText(myCurrencyFormatter.format(monthly));
         if(command == clearButton) //clears all text fields
                   mortgageAmount.setText(null);
                   //mortgageTerm.setText(null);
                   //interestRate.setText(null);
                   monthlyPayment.setText(null);
              if(command == exitButton) //sets exit button
                        System.exit(0);
         public static void main(String[] arguments) {
              MortgageCalculator mor = new MortgageCalculator();

    The OP already did this to both JComboBoxes.
    mochatay, here is a new actionPerformed method for you to use.
    I've improved a few things here and there...
    1) You can't just cast the ActionEvent's source into a JComboBox!
    What if it was a JButton that fired the event? Then you would get ClassCastExceptions (I'm sure you did)
    So check for all options, what the source of the ActionEvent actually was...
    2) You can't assume the user will always type in valid data.
    So enclose the Integer and Double parse methods in try-catch brakcets.
    Then you can do something when you know that the user has entered invalid input
    (like tell him/her what a clumsy idiot they are !)
    3) As soon as user presses an item in any JComboBox, just re-calculate.
    I did this here by programmatically clicking the 'Calculate' button.
    Alternatively, you could have a 'calculate' method, which does everything inside the
    if(command==calculateButton) if-block.
    This will be called when:
    a)calculateButton is pressed
    b)when either of the JComboBoxes are pressed.
    public void actionPerformed (ActionEvent event)
            Object command = event.getSource ();
            if (command == calculateButton) //calculates mortgage payment
                int year = 0;
                double rate = 0;
                double mortgage = 0;
                double interest = 0;
                /* If user has input invalid data, tell him so
                and return (Exit from this method back to where we were before */
                try
                    year = Integer.parseInt (mortgageTerm.getSelectedItem ().toString ());
                    rate = new Double (interestRate.getSelectedItem ().toString ()).doubleValue ();
                    mortgage = new Double (mortgageAmount.getText ()).doubleValue ();
                    interest = rate / 100.0 / 12.0;
                catch (NumberFormatException nfe)
                    /* Display a message Dialogue box with a message */
                    JOptionPane.showMessageDialog (this, "Error! Invalid input!");
                    return;
                double monthly = mortgage * (interest / (1 - Math.pow (interest + 1, -12.0 * year)));
                NumberFormat myCurrencyFormatter;
                myCurrencyFormatter = NumberFormat.getCurrencyInstance (Locale.US);
                monthlyPayment.setText (myCurrencyFormatter.format (monthly));
            else if (command == clearButton) //clears all text fields
                /* Better than setting it to null (I think) */
                mortgageAmount.setText ("");
                //mortgageTerm.setText(null);
                //interestRate.setText(null);
                monthlyPayment.setText ("");
            else if (command == exitButton) //sets exit button
                System.exit (0);
            else if (command == mortgageTerm)
                /* Programmatically 'clicks' the button,
                As is user had clicked it */
                calculateButton.doClick ();
            else if (command == interestRate)
                calculateButton.doClick ();
            //JComboBox mortgageTerm = (JComboBox) event.getSource ();
            //String termYear = (String) mortgageTerm.getSelectedItem ();
        }Hope this solves your problems.
    I also hope you'll be able to learn from what I've indicated, so you can use similar things yourself
    in future!
    Regards,
    lutha

Maybe you are looking for

  • 2 Node VCF(Vartas cluster on sun 5.9)

    Hi, I have to upgrade from 9.2.0.6 to 9.2.0.8 on VCF 2 Node os cluster. Here I would like to know the steps how the patchset 9.2.0.8 will be installed on both server which is active/passive? Please share your views or give me some docs if it is avail

  • Can I upgrade my hard-drive in my iMac 7,1

    Hello, I have the mid 2007 released intel based imac. I am about to change my 1GB memory to 4GB memory per the info I found on the Apple support site (upgrading memory on mid 2007 imacs or later). I also want to upgrade my hard-drive to 1TB as I need

  • FI Business Flow related to BW/ BI

    Hi SDN, I need some information regarding the FI Business Flow related to BW/ BI. Any case studies or scenarios would be highly appreciated. Thanks in Anticipation, Ankit

  • PO Out Put Determination for one time vendor

    Dear all; For one time vendor master record from where the system will pickup the vendor specific data ,esp. fro whichj table and which field .Kindly reply in details . Thanking you; Regards; Joydeep Mukherjee

  • HT2490 Where can I change the date to the international format yyyy-mm-dd to become the default

    I prefer to have the international date format as default for as many applications as possibe I use. Is there a preference/tweak to implement that?