event-handling

Serial Data Event Listener Java

三世轮回 提交于 2019-12-11 19:31:29
问题 I would be really grateful if someone could point me in the right direction How would i go about triggering an event that is called when no data is received from the serial communication example below? Thank you, Maria. public void connect(String portName) throws Exception { CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName); if (portIdentifier.isCurrentlyOwned()) { System.out.println("Error: Port is currently in use"); } else { CommPort commPort =

Java - Actionlistener: Get components from parent

可紊 提交于 2019-12-11 19:05:26
问题 The only way I found so far to get other components' info when an actionevent is activated is by doing the following: ((Swing Component)ActionEvent.getSource()).getParent().getComponent(---).method(); and while it work it's not that practical or readable, not to mention would most likely stop working properly if I moved around the components in the parent component. So what is the best way to go about this? Should I even use an actionlistener to begin with or are there better classes/design

How to send a message to the class that created the object

白昼怎懂夜的黑 提交于 2019-12-11 19:05:15
问题 I would like to send back data to class that create this object. It's game related. The enemy objects have a threaded function and move on their own in the scene. It generates lots of errors if you include the header file from the class that creates to the objects into the object itself ... to pass pointers. Enemy Class: Class Enemy { private: void (*iChange)(DWORD &); }: Enemy::Enemy(void (*iChangeHandler)(DWORD &) ) : iChange(0) { this->iChange = iChangeHandler; } void Enemy::Draw

Visual Basic - Handle events for class within a list

落爺英雄遲暮 提交于 2019-12-11 18:29:06
问题 Public Class EquipmentCollection { Public Property EquipmentList As List(Of Equipment) } Public Class Equipment { Public Event CalculateFired Public Sub Calculate RaiseEvent CalculateFired End Sub } How can I handle the CalculateFired event on the Equipment class within the EquipmentCollection class? .NET 3.5, VB 回答1: This worked for me. Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim ec As New EquipmentCollection Dim eq As New Equipment Dim

How to handle events from ResourceDictionary without using ResourceDictionary Code-Behind?

会有一股神秘感。 提交于 2019-12-11 18:13:42
问题 I would like help regarding how to handle events from controls in a ResourceDictionary (e.g. Styles.xaml) without using ResourceDictionary Code-Behind (e.g. Styles.xaml.cs), mainly because I want the Styles.xaml to just be there for styling. My scenario is, I have a Custom Page which uses a ResourceDictionary for DataTemplate styles (I am using a TemplateSelector). However, the problem I am currently having is for handling events. For example: I have this in my Styles.xaml : . . <Button Click

KeyEventArgs in C#

一笑奈何 提交于 2019-12-11 18:09:51
问题 I have a problem to how to catch which key is pressed. This is my code, but i cant get what key was pressed. I'm using KeyEventArgs for declaration of new variable and then comparing it. private void textBox2_TextChanged(object sender, EventArgs e) { KeyEventArgs k = null; if (e is KeyEventArgs) { k = (KeyEventArgs)e; } if (k.KeyCode == Keys.Enter) { // do something here } } 回答1: You need to add: [component_name].KeyDown += new System.Windows.Forms.KeyEventHandler(this.Key_Pressed_Method);

Catch the control (button click) who raised the leave event on a textbox

筅森魡賤 提交于 2019-12-11 18:08:59
问题 I have a TextBox with Leave event. In the TextBox.Leave sub, I would like to show a confirmation MsgBox to ask user for saving changes but, if I show a MsgBox , the Button.Click event isn't fired (after TextBox.Leave event: see my previous question Here) So I thought to insert (in the TextBox.Leave Sub) a code for catching the name (or another rif) of the button that was clicked and fired TextBox.Leave event. Having the button name, I'll be able to raise the click event: DirectCast(Me

Removing event.preventDefault on click doesn't work

回眸只為那壹抹淺笑 提交于 2019-12-11 17:27:32
问题 I have this code which prevents default behavior on all elements: $('body *').click(function(e){ e.stopPropagation(); e.preventDefault(); }); Now I would like to programmatically click a certain link in the page but first I have to remove the e.preventDefault(); so I used unbind : $('a')[0].unbind('click'); $('a')[0].click(); This doesn't work for me. What am I doing wrong? 回答1: You can't do $('a')[0].unbind('click') use .eq() to get the first element and then unbind .eq(0).unbind('click') 来源

XamlParseException when adding event handler in XAML

泪湿孤枕 提交于 2019-12-11 16:47:54
问题 I am having trouble adding event handlers to an AutoCompleteBox in XAML for windows phone 8. It worked before, but since I moved things around it doesn't anymore. The following is an extract from my MainPage.xaml: <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <Grid Margin="0,0,0,407"> <Grid.RowDefinitions> <RowDefinition Height="50"/> <RowDefinition Height="70"/> <RowDefinition Height="50"/> <RowDefinition Height="70"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions>

How to handle Android SimpleExpandableListAdapter entry selection

前提是你 提交于 2019-12-11 16:35:16
问题 I have created an expandable list in my Android application using the SimpleExpandableListAdapter type. But I'm at a complete loss as to how I detect events when one of the child entries has been selected/clicked. I've tried all the usual OnClickListener/OnChildClickListener etc, but can't seem to find (by experimentation, or half an hour googling) what the correct handler routines should be. Any help greatfully appreciated. 回答1: It should be: list.setOnChildClickListener(new