event-handling

access to variable within inner class in java

孤者浪人 提交于 2019-11-27 03:12:26
问题 I'm trying to create an array of JLabels, all of them should go invisible when clicked. The problem comes when trying to set up the mouse listener through an inner class that needs access to the iteration variable of the loop used to declare the labels. Code is self-explanatory: for(int i=1; i<label.length; i++) { label[i] = new JLabel("label " + i); label[i].addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { label[i].setVisible(false); // compilation error here }

Jquery Remove All Event Handlers Inside Element

左心房为你撑大大i 提交于 2019-11-27 03:04:50
问题 I have a div element with several elements inside it like buttons and so forth which have event handlers attached to them. I know its possible to go: $("#button1").off() To remove the handler for a button but I would like to do something like this if possible: $("#div1").removeChildHandlers(); Is there a native function in JQuery to do this or would I have to loop them all the elements and remove 1 by 1? 回答1: jQuery will do the looping for you for just the direct children: $("#div1").children

Multiple id's in a single JavaScript click event

瘦欲@ 提交于 2019-11-27 02:16:28
问题 In JavaScript I am using click event to change chart data. Below is a method for click event. $('#pro1').click(function () { chart.series[0].update({ data: pro1 }); }); $('#pro2').click(function () { chart.series[0].update({ data: pro2 }); }); $('#pro3').click(function () { chart.series[0].update({ data: pro3 }); }); I need to minify these three click events in one event, means I want to write one click event which handle the id's. some thing like below code. $('#pro'+i).click(function () {

asp.net dynamically button with event handler

限于喜欢 提交于 2019-11-27 02:09:36
I have here a small problem with a dynamically generated buttons and their event handler in asp.net. I generate a flexible table with additional Buttons for special users. The buttons will generate dynamically, which works fine. But I can’t get the event handler to work. Here are some pieces from my code: Build the button (In an own function). … Button ButtonChange = new Button(); ButtonChange.Text = "Change"; ButtonChange.ID = "change_" + i.ToString(); ButtonChange.Font.Size = FontUnit.Point(7); ButtonChange.ControlStyle.CssClass = "button"; ButtonChange.Click += new EventHandler(test); … And

.NET: Problem with raising and handling events using AppDomains

99封情书 提交于 2019-11-27 02:03:37
问题 Here is the basic gist of my problem: My main Window class instantiates Class A. Class A instantiates Class B in a secondary AppDomain . Class B raises an event and Class A handles the event successfully. Class A raises an event of its own. Problem: In step 4, when Class A raises its own event from the event handler method that caught Class B's event, the event is raised; however, the subscribing handler in the Window class is never called. There are no exceptions being thrown. If I remove

Are Click, Tapped, and PointerPressed synonymous in WinRT-XAML?

孤街醉人 提交于 2019-11-27 01:55:53
Does it matter whether I create event handlers for PointerPressed, Click, or Tapped?IOW, is there any functional difference between the following: <Button x:Name="BackButton" PointerPressed="BackButton_Click"/> <Button x:Name="BackButton" Click="BackButton_Click"/> <Button x:Name="BackButton" Tapped="BackButton_Click"/> ? Click is there for backwards compatibility, and is essentially the same as Tapped. Tapped is a "high level gesture" that will translate automatically to a click, tap, pen press, etc. and is what I would recommend to use. PointerPressed is not what you want. Here's why: if I

Javascript add events cross-browser function implementation: use attachEvent/addEventListener vs inline events

半腔热情 提交于 2019-11-27 01:53:18
In order to add events we could use this simple 1st solution : function AddEvent(html_element, event_name, event_function) { if(html_element.attachEvent) //Internet Explorer html_element.attachEvent("on" + event_name, function() {event_function.call(html_element);}); else if(html_element.addEventListener) //Firefox & company html_element.addEventListener(event_name, event_function, false); //don't need the 'call' trick because in FF everything already works in the right way } or this 2nd solution (that adds inline events): function AddEvent(html_element, event_name, event_function) { var old

How to pass an event to a method?

空扰寡人 提交于 2019-11-27 01:49:16
I would like to create a method that takes an event as an argument and adds eventHandler to it to handle it properly. Like this: I have two events: public event EventHandler Click; public event EventHandler Click2; Now I would like to pass a particular event to my method like this (pseudocode): public AttachToHandleEvent(EventHandler MyEvent) { MyEvent += Item_Click; } private void Item_Click(object sender, EventArgs e) { MessageBox.Show("lalala"); } ToolStripMenuItem tool = new ToolStripMenuItem(); AttachToHandleEvent(tool.Click); Is it possible? I've noticed that this code worked fine, and

jQuery event handler .on() not working

限于喜欢 提交于 2019-11-27 01:46:12
问题 I want to attach a event to dynamically created element class.So i used live function but it was not triggered. So checked live function reference ,there i red below notes As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live(). so decide to use on function,But it still not working.The text field is already attached with jquery ui datpicker.On another element select i disabled

Can using lambdas as event handlers cause a memory leak?

牧云@^-^@ 提交于 2019-11-27 01:35:20
问题 Say we have the following method: private MyObject foo = new MyObject(); // and later in the class public void PotentialMemoryLeaker(){ int firedCount = 0; foo.AnEvent += (o,e) => { firedCount++;Console.Write(firedCount);}; foo.MethodThatFiresAnEvent(); } If the class with this method is instantiated and the PotentialMemoryLeaker method is called multiple times, do we leak memory? Is there any way to unhook that lambda event handler after we're done calling MethodThatFiresAnEvent ? 回答1: Yes,