Event Dispatch Problem With Classes
I have a custom Timer class that pops up an inactivity alert
after 3 minutes. The user can then choose 'yes' if they are still
editing a record or 'no' if they are done. If they do not respond
within 2 minutes of the alert it assumes 'no'.
A 'yes' refreshes the timer and closes the alert.
A 'no' kicks them out of the edit state in the component that
the timer is called from.
The logic of the timer is working fine but it doesn't seem to
be sending the event to the component that called it so clicking
'no' (or remaining inactive) does nothing. I feel like I'm missing
something really simple or just misunderstanding the
eventDispatcher function. Advice please??
Code From LockTimer class:
public class LockTimer extends Sprite
private var threeMinuteTimer:Timer;
private var twoMinuteTimer:Timer;
public function LockTimer()
// creates a new threeMinute Timer
threeMinuteTimer = new Timer(1000, 180);
twoMinuteTimer = new Timer(1000, 120);
// designates listeners for the interval and completion
events
threeMinuteTimer.addEventListener(TimerEvent.TIMER, onTick);
threeMinuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE,
onTimerComplete);
twoMinuteTimer.addEventListener(TimerEvent.TIMER, onTick);
twoMinuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE,
onTimerCompleteB);
// starts the timer ticking
threeMinuteTimer.start();
public function refresh():void{
restart(threeMinuteTimer);
twoMinuteTimer.reset();
private function onTick(evt:TimerEvent):void{}
private function onTimerComplete(evt:TimerEvent):void{
//trace("first timer");
Alert.show('You have been inactive for several minutes. Are
you still editing this record?', 'Inactivity Alert',
Alert.YES|Alert.NO, null, alertListener,null, Alert.YES);
twoMinuteTimer.start();
private function onTimerCompleteB(evt:TimerEvent):void{
//trace('second timer');
//Alert.show('TIME UP', 'Inactivity Alert', Alert.OK);
dispatchEvent(new Event("timeUp",true));
private function restart(tim:Timer):void{
tim.reset();
tim.start();
private function alertListener(eventObj:CloseEvent):void{
// Check to see if the YES button was pressed.
if (eventObj.detail==Alert.YES) {
refresh();
}else{
//exit edit mode
//Alert.show('TIME UP', 'Inactivity Alert', Alert.OK);
dispatchEvent(new Event("timeUp",true));
Code From Component:
private var theTimer:LockTimer;
private function initializeHandler(event:Event):void{
addEventListener("timeUp",timeUpHandler);
private function timeUpHandler(event:Event):void{
Alert.show('TIME UP', 'Inactivity Alert', Alert.OK);
//editDone();
}
so here is what i had to do to make this work:
1. I had to attach the listener to theTimer rather than the
component
2. I had to initiate the LockTimer constructor outside of the
function
3. I had to call the handler initialization function from the
component MXML
below is the revised code (with excess cut out)
<?xml version="1.0" encoding="utf-8"?>
<mx:HDividedBox xmlns:mx="
http://www.adobe.com/2006/mxml"
width="780" height="515" liveDragging="true"
creationComplete="initializeHandler()">
<mx:Script>
<![CDATA[
import mx.controls.Text;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
import classes.LockTimer;
public static const millisecondsPerMinute:int = 1000 * 60;
public static const millisecondsPerHour:int = 1000 * 60 *
60;
public static const millisecondsPerDay:int = 1000 * 60 * 60
* 24;
//IMPORTANT!!!////////////////
private var theTimer:LockTimer=new LockTimer();
private function initializeHandler():void{
theTimer.addEventListener("timeUp",timeUpHandler);
private function timeUpHandler(event:Event):void{
editDone();
private function refreshLock(theLock:int):void{
var theTime:Date=new Date();
if(theLock==1){
theTimer.refresh();
theTime.setTime(theTime.getTime() +
(millisecondsPerMinute*5));
}else if(theLock==0){
theTime.setTime(theTime.getTime());
}else{
return;
form1.request.firmlockedTime=String(theTime.valueOf());
form1.request.firmisLocked=String(theLock);
private function editIt():void{
//see if it's being edited
if(checkLock()){
//if its being edited send a message
Alert.show('This record is currently being edited by another
user. Please try again later.', 'Record Locked',
mx.controls.Alert.OK);
}else{
theTimer.startMe();
refreshLock(1);
form1.send();
currentState="AdminEdit";
private function editDone():void{
refreshLock(0);
form1.send();
currentState="Admin";
]]>
</mx:Script>
</mx:HDividedBox>
Similar Messages
-
Calendar Event Modification Problem with 2.2
I don't seem to be able to modify a calendar event like I was able to with 2.1. When I select the event from the calendar it briefly flashes a screen (which happens so fast I can't really read it) and then dumps me into a screen that I can't open the event from. Anyone else out there having a similar problem?
johnpa wrote:
I don't seem to be able to modify a calendar event like I was able to with 2.1. When I select the event from the calendar it briefly flashes a screen (which happens so fast I can't really read it) and then dumps me into a screen that I can't open the event from. Anyone else out there having a similar problem?
the screen should say that you don't have any calendars. i had this problem after my update. it wiped all of my saved events. i think with 2.1 you could use a google calendar AND/OR a phone calendar and with 2.2 it looks like you can only use google calendars.
anyway, if it's there, select your google calendar and you can start adding events to it. it's a PITA to have to re-enter everything tho. -
Creating event dispatching in custom class
I have been trying to create an event dispatcher in a custom
data transfer object class. It's a simple class and I don't know
how to make it dispatch an event. I tried extending the
EventDispatcher class but that doesn't appear to work either. Any
help would be greatly appreciated.I have attached the code for the application and the custom
class. This should work from what I have read, but I can not get
the application to catch the event.
APPLICATION
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
creationComplete="initThis()" layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private var _tester:TestClass = new TestClass();
private function initThis():void{
addEventListener(TestClass.TEST_ACTION, onTestHandler);
private function onTestHandler(event:Event):void{
Alert.show("Event Dispatched");
]]>
</mx:Script>
<mx:Button x="312" y="150" label="Button"
click="{_tester.testEvents()}"/>
</mx:Application>
CLASS
package
import flash.events.EventDispatcher;
import flash.events.Event;
public class TestClass extends EventDispatcher
public static const TEST_ACTION:String = "test";
public function testEvents():void{
dispatchEvent(new Event(TestClass.TEST_ACTION));
} -
Adobe AIR Event Dispatcher Problem
I have created an AIR application, I have removed an component and again i added the same component. That time the event dispatcher of the removed component is been called again and again.How to resolve this problem. Urgent Reply ASAP......
The only idea that comes to mind is to keep the file on the dvd, then have your app install (copy) it on first launch.
Thanks for adding the bug. For others affected by this, please visit the bug and add your vote. All feedback is appreciated!
https://bugbase.adobe.com/index.cfm?event=bug&id=2938315
Chris -
Problem with Class and Classpath
Hello ME Windows Users, now before you place a wry smile on your face, I have a problem with path and classpath. Stop it, I can see you smiling!
By visiting the the last 10 pages of the forum and reading Sun installation notes, some tooldocs and by given some answers by some nice people, I have become an expert in turning off my computer, about 10 times/hr. I still am trying to make my first cup of java.
With the ME computer,
I'm unable to right click on the desktop and go to properties, advanced,
I'm unable to go go start, run, sysedit,
I'm unable to change the ms-dos window of autoexec.bat, it just shuts down.
Now before you tell me, I should of bought a different computer, the only place I can find to modify the path and classpath is in the environment which is in system configuration under tools. Here I have placed numerous configurations, like
C:\java>set path=%path%;c:\j2sdk1.4.2\bin
C:\java>set classpath=%classpath%;.;
;java_dir\bin where ;java_bin is c:\j2sdk1.4.2
.; java_dir\bin; %path% where ;java_bin is c:\j2sdk1.4.2 and the list goes on.
But, I know you are still smiling, the % signs comes up in a dialog box, saying too many, and will not convert the text to the environment to be saved when I close down for the tenth time in the last hour.
Can someone help me before I make a real cup of coffee and accidentally drop it on the ME box.
Have a laugh on me Mik.C:\java>set path=%path%;c:\j2sdk1.4.2\binGood
But it is no good because it has to many % and a dialog box appears, saying you have too many parameters.
Are you saying I have to shutdown again to answer your ?
From the HELP menu-
To confirm startup commands line by line
Click Start, and then click Shut down.
Click Restart, click OK, and then press and hold the CTRL key until the Windows Startup Menu appears.
Enter the number for Step-by-step confirmation, and then press ENTER.
For each command you want to run, press Y.
If the command runs successfully, you are prompted with the next command.
If the command does not run successfully, you receive an error message.
To skip a command, press N.
Mik -
[APPLET][Heritage] Problem with classes
Hi, I'm developping a simple JAVA Applet and I have a problem
I have a class called LUIweb which is the main class. Here is a part of it.
public class LUIweb extends JApplet implements Runnable {
public void run() {
DisplayMessage("JAVA rocks");
public void DisplayMessage(String message){
jtextArea.append(message);
middlePanel.removeAll();
middlePanel.add(textScrollPane, BorderLayout.CENTER);
middlePanel.validate();
middlePanel.repaint();
It displays the message "JAVA rocks" in my JTextArea. But when another class from the same package calls DisplayMessage, nothing is displayed in my JTextArea
public class Data_net extends LUIweb{
public void Test(){
DisplayMessage("NON");
Have you got any idea to fix that?
Thank you for you helpOK,
You are using a separate thread to update the gui. As swing is not multithread safe, this is not good. Anytime you want to change the gui, you must do it on the gui thread. This means without extra help, you should only change the gui from within a Listener, such as a MouseListener, KeyListener, etc, etc.
In your case, you are updating the not from the gui thread (not from a Listener), and so you must ask the gui thread to do the work for you when it has time.
This means you need to use SwingUtilities.invokeLater or SwingUtilities.invokeAndWait.
Since the sequencing is important to you in your code, you should probably use invokeAndWait, such as
public void run()
SwingUtilities.invokeAndWait( new Runnable()
public void run() { DisplayMessage(Language.CONNECT_DB); }
Data_net Donnee_net=new Data_net();
SwingUtilities.invokeAndWait( new Runnable()
public void run() { DisplayMessage("Connecting to "+Donnee_net.GetHost()+
" with user "+Donnee_net.GetUser()+"...\n");
Donnee_net.Test(); -
Problems with classes referencing each other...
I've got a problem....i have a program with two classes, and each class needs access to methods stored in the other class.
I've tried to create a reference (Classname name=new Classname();), but upon execution, i get a Exception in thread "main" java.lang.StackOverflowError, and a long list of locations, all pointing to the references i created at the top of each class.
What's wrong, and how do I fix this?You have infinite recursion. A method or constructor is calling itself, or is calling another method or constructor that eventually ends up calling the first one.
If you can't find it, post code. Use [code] and [/code] tags, which you can get with the code button, to make the code readable. -
A stange problem with class Random
I am doing with a simple test of class random as follow:
public class Test{
private static rand=new Random();
public static void main(String args[]){
int i=rand.nextInt(10);
System.out.println(i);
}When I compile the program using javac,error occurs.It says
Wrong number of arguments in method
private int i=rand.nextInt(10)
^
If I remove the arg "10" ,it works fine.So I have to rewrite it as below:
private int i=rand.nextInt(10) % 10;I am puzzled now.Why can't I use the int nextInt(int n) method of class Random?Thanks for your advice.
I have tried as what you have said ,and the codes seem like these:
import java.util.*;
public class test {
private static Random rand = new Random();
public static void main(String args[]){
int i=rand.nextInt(10);
System.out.println(i);
}and the file name is test.java of course.
But it cause the same error.
And when I compile the same code on another machine ,it wors fine!
(all the two machines are installed with win2k server and j2sdk1.4.1_01).
Why there exists problems and difference?
Did I have to set something else of the system? -
I have a panel with a button. The panel have a MouseMotionListener registered, but when the mouse is over the button the MouseEvent stop to go to the panel and go to the button. How can i let the panel understand to "keep the event also for me" ?
This solution seems not optimal ....
//my button class
protected void processMouseMotionEvent(MouseEvent ev)
MouseEvent trick=new MouseEvent((Component)ev.getSource(),ev.getID(),ev.getWhen(),ev.getModifiers(),this.getX()+ev.getX(),this.getY()+ev.getY(),ev.getClickCount(),true,ev.getButton());
this.getParent().dispatchEvent(trick);
super.processMouseMotionEvent(ev);
Suggestions?
Thanks in advance.
-Marco BagnaresiI'm no expert but I would have thought that the best way to do this would be to have your panel listening for mouse events on the button aswell.
-
Cairngorm events dispatch problem
Hi,
We are developing a Flex 3 AIR application on Cairngorm and
LCDS 2.6. The problem is some Cairngorm events don't get fired
which results in null reference errors. But when we put an Alert is
starts working. Can you suggest any solution and reason why its
happening.
Thanks,
OlegOne thing that will cause events to appear not to fire is
when you forget to instantiate your controller somewhere on your
mxml file. The events will dispatch, but the command won't get
executed.
Another one - if you create custom events and override the
constructor, you have to to call super(MyController.EVENT_TYPE) or
else your event doesn't get bound to the command. -
Problems with class CL_GUI_FRONTEND_SERVICES
Hi.
I already searched for a solution in the forum, but haven't found anything yet.
I use the method to check if a directory exists and the one to list the files. The user can specify the directory on the Appl.-Server via SELECTION-SCREEN. First the code:
CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_EXIST
EXPORTING
DIRECTORY = l_unixpath
RECEIVING
RESULT = l_count_unixdir
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
WRONG_PARAMETER = 3
NOT_SUPPORTED_BY_GUI = 4
others = 5.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES
EXPORTING
DIRECTORY = l_unixpath
CHANGING
file_table = l_itab_unixdir
count = helpvar
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
WRONG_PARAMETER = 3
NOT_SUPPORTED_BY_GUI = 4
others = 5.
IF l_count_unixdir = 'X'.
WRITE: / 'Directory Exists'.
READ TABLE l_itab_unixdir INDEX 1 INTO l_unixdir.
WRITE:/ helpvar.
WRITE:/ l_unixdir.
WRITE
ELSE.
WRITE:/ 'Directory not found'.
ENDIF.
Now my problem:
l_unixpath is '/', the result is: Directory exists, but helpvar is 0, l_itab_unixdir is empty;
l_unixpath is '/usr/sap/', the result is: Directory not found <b>(but the directory exists!)</b>;
l_unixpath is 'c:/', the result is: Directory exists, helpvar is 47, l_unixdir is "Documents and Settings".
Why it's working with the Windows-Path but not with Unix? Thanks for your answers.Becose that class is for presentation server. You can't use it with application server.
Try FM F4_DXFILENAME_TOPRECURSION, may be helps.
Regards. -
Problem with Class.getResource()
I am trying to load a jar file dynamicaly like,
ClassLoader prevClassLoader = Thread.currentThread().getContextClassLoader();
URLClassLoader m_ClassLoader = new URLClassLoader(new URL[] {new URL(sV1JarPath)}, prevClassLoader);
But after doing this if I try to load a resource from the "prevClassLoader " like,
MyClass.class.getResource("path"); where MyClass is loaded by prevClassLoader, it is not working. It fails to load the resource.
Can anyone help me correct this issue?
Thanks
Unnitry "/path".I am giving it like
MyClass.class.getResource("images/" + name); where there is an images packages in side the package where MyClass resides.
But here the problem is as MyClass is in the prevClassLoader and it is not able to find it when we call Class.getResource() -
Problems with class MdmDimension
Hello, I've created some dimensions and cubes using cwm2 packages, in Oracle 9i.
Now I'm trying to use these objects in a j2ee aplication using olap api. My problem is: when I try to display the properties (display_name, plural_description, description, ...) of my dimensions (using MdmDimension class), the result is not the same of the same properties using ALL_OLAP2_DIMENSIONS view.
For example, the PR01 dimension has the next descriptions (using ALL_OLAP2_DIMENSIONS view):
plural_name: 'Prueba01 plural'
display_name: 'Prueba01 display'
short_description: "Prueba01 short'
description: 'Prueba01 description'.
And now, using the methods on MdmDimension class, I've got the next results:
getPluralDescription() --> 'Prueba01 plural' OK
getShortDescription() --> 'Prueba01 display' ????
getShortPluralDescription() --> 'Prueba01 plural' OK
getDescription() --> 'Prueba 01 short' ????
I need to display the description ('Prueba01 valen'), but I haven't found the way.
What is failing ? My database version is 9.2.0.6, and I'm using MdmDimension from package oracle.express.mdm. Thanks a lot by your help.Hi Edmund,
I'm having the same problem in the same upgrade scenario. Did you find a solution for this big issue?
Thanks.
Patricio. -
Hi everyone.
I am using a scroller class from kirupa, however i am having
a small problem. Everything works fine if i place it all on the
main time line. however when i want to package all the mc's used
for the scroller into a mc of it own the scroller will not update
for the new content. I am losing some hair trying to tackle this
one on my own and would love it if someone could help.
Here are the files:
EDITED: i have just added both the version of the scroller in
a container...and one that is not. The one that is not work
perfectly, the one that is in the container has the flaw that when
the new content is loaded in the scroll bar does not hide or change
height, it keeps the property of the initial mc loaded.
Hope that makes sense.
Zipped
Files
Thanks for all for taking time for this.
Very much appreciated,
Martha StewartThink it works (almost) properly now. This is the code for
the buttons (change the mc to attach...)
on(release){
Scroller.contentMain.unloadMovie;
Scroller.contentMain.attachMovie("historytxt","newcontent",1)
// Line of importance
setTimeout(Scroller.myscrollbar, "setScrollProps", 50);
Scroller.myscrollbar.backToTop();
Make one correction in the class:
public function backToTop():Void
dragger._y = top;
content._y = 0; // instead of 'top'
updateContentPos();
Now that last correction disables the easing effect when
clicking on a new topic, but there's something wrong in the class
and the 'new' values are not correct. I'll try to figure it
out. -
Problem with classes generated with .classgen
When I run the sample app from the "Using XML in Oracle Database Applications, Part 2" that generates classes, the syntax is:
java SampleMain -root MYMAIN myfile.dtd
All the elements in myfile.dtd get a class built for them, but they also reference MYMAIN as a class. That is, things like:
public MYMAIN getDocument()
return (MYMAIN)super.getCGDocument();
I would have expected that classgen would have made a class called MYMAIN, but it did not. I'm very confused. Please help.
Thanks,
-Peter
nullCheck if you have MYMAIN in your
DTD file:
<!ELEMENT MYMAIN ......
Maybe you are looking for
-
How can two users share the same iTunes library in 10.7
I am running Lion 10.7 and there are two users on the iMac. I would like full read/write access to our share music from either user account. Currently I have the iTunes Media folder in users/shared and on my account it looks like a regular iTunes and
-
hi.. i've got problem with my iphone 4s gsm factory unlocked it won't connect to a wifi. i tried to hold the power and home button even reset the network setting but ended with i am not even can turn the wifi on. does any body can helpme?
-
IMovie DVD audio stops in middle?
Imported a one hour video into iMovie 11 from our new JVC video camera then exported it to iDVD. It made the chapters into menu scenes as expected. However, in the last scene, the audio stops in the middle? I don't think there is a secret make the au
-
Can Ppro CS3 projects be imported by Media Encoder CS4
Hello: I have Ppro CS3. I also have the Design Suite CS4. I would like to render out Ppro CS3 sequences or projects into F4V files in Media Encoder CS4. Does anyone know if this is possible? When I select "add Premiere sequence" in Media Encoder CS
-
Hp deskjet 1050a j410 install\driver problem
Hey! i've recently bought a scanner\printer which i intend to use with my laptop, no hassle. but installing this thing is a bloody nightmare and i get errors and what not, how the heck am i supposed to do this? i am a fairly tech savvy person, but yo