标签: eventhandler

另一个类中的axon事件处理程序

我正在使用axon 2.3.1,我有一个聚合类

public class MyAggregate extends AbstractAnnotatedAggregateRoot<MBAggregate>   {


@AggregateIdentifier
private MyId Id;
private Circle circle;
EventDispatcher a=new EventDispatcher();

public MyAggregate() {
}

@CommandHandler
public MyAggregate(NewCommand command ) {
    apply(new SmallEvent(command.getId(), command.getCircle()));
}

@CommandHandler
public MyAggregate( StoreDestinationsCommand command ) {
    apply(new BigEvent(command.getId(), command.getCircle()));
}
//And some event handlers like

   @EventHandler                                                                                                                             
   public void onSmallEvent(SmallEvent event)    
   {
    //Some logic here
   }
   @EventHandler                                                                                                                             
   public void onBigEvent(BigEvent event)    
   {
    //Some logic here
   }
Run Code Online (Sandbox Code Playgroud)

现在我希望这些事件处理程序包含在其他类中,并在触发该事件时调用

public class EventContainer {


private static final long serialVersionUID = -6640657879730853388L; …
Run Code Online (Sandbox Code Playgroud)

axon eventhandler

2
推荐指数
1
解决办法
2739
查看次数

持有两次Windows Phone 8.1的事件

我有一个举办活动ListBoxItem.因此,当我持有一个项目时,它会在函数中向右输入,但它会在它被触发两次时出现.

private async void OutersAndContactInTel_Holding(object sender, HoldingRoutedEventArgs e)
{
    try
    {
        FrameworkElement element = (FrameworkElement)e.OriginalSource;
        if (element.DataContext != null && element.DataContext is Contact)
        {
            Contact selectedContact = (ImOutContact)element.DataContext;
            if (selectedContact.IsOuter)
            {
                MessageDialog msgToAddContact = new MessageDialog("Voulez-vous vraiment suivre " + selectedContact.Pseudo + " ?");
                msgToAddContact.Commands.Add(new UICommand("Oui", (UICommandInvokedHandler) =>
                {
                    AddContactProcess(selectedContact);
                }));
                msgToAddContact.Commands.Add(new UICommand("Non"));

                this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => msgToAddContact.ShowAsync());
            }
            else
            {
                MessageDialog msgToInviteContact = new MessageDialog("Envoyez une invitation à  l'utilisation de l'application par sms à " + selectedContact.NomPrenom + …
Run Code Online (Sandbox Code Playgroud)

c# ui-thread messagedialog eventhandler

2
推荐指数
1
解决办法
876
查看次数

jQuery:如何在所有输入上检测模糊事件

我一直在尝试这样的事情

$(':input').blur(doStuff());
Run Code Online (Sandbox Code Playgroud)

$('*').bind('blur', doStuff());
Run Code Online (Sandbox Code Playgroud)

但似乎没有任何东西正确触发.最好的方法是什么?

jquery blur eventhandler

1
推荐指数
1
解决办法
1359
查看次数

如何向按钮单击事件处理程序添加附加参数?

在 C# 中,向按钮事件调用添加附加属性的最佳方法是什么?

这是代码EventHandler

button.Click += new EventHandler(button_Click);
Run Code Online (Sandbox Code Playgroud)

这是代码button_Click

private void button_Click(object sender, EventArgs e)
{

}
Run Code Online (Sandbox Code Playgroud)

如果我想PropertyGridbutton_Click函数参数中添加一个参数,最好的方法是什么?

我想这样做,因为button.Click代码位于具有PropertyGrid参数的button_Click函数中,并且在该函数中,我需要设置PropertyGrid所选对象。这仅在button.Click单击按钮时设置。

如果我将按钮的标签设置为一个PropertyGrid对象,如何在button_Click代码中检索这个标签对象?

button_Click事件是从一个对象调用的,发送方是对象,而不是按钮。

我可以请一些代码的帮助吗?

c# eventhandler

1
推荐指数
1
解决办法
4288
查看次数

如何在FXML(Javafx项目)中设置图像的侦听器?

如何为 fxml 内的图像设置事件处理程序。我已经编写了以下内容,其中有 3 个图像,我想单击它们,它们调用我已经在控制器类中创建的函数。我已经尝试过 onMouseClick 和 onAction 它们都不起作用。

   <ImageView fitHeight="31.0" fitWidth="29.0"  pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" GridPane.rowIndex="0" >
            <image >
       <Image url="@/views/add.png" />
        </image>
        </ImageView>
     <ImageView fitHeight="31.0" fitWidth="29.0"  pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" GridPane.rowIndex="1">
            <image>
       <Image url="@/views/remove.png" />
        </image>
        </ImageView>
     <ImageView fitHeight="31.0" fitWidth="29.0"  pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" GridPane.rowIndex="2">
            <image>
       <Image url="@/views/edit.png" />
        </image>
        </ImageView>
Run Code Online (Sandbox Code Playgroud)

我也查看了其他帖子,但他们都说当图像被实用地定义时如何做到这一点。任何建议表示赞赏。

javafx image eventhandler

1
推荐指数
1
解决办法
1485
查看次数

EventHandler <T>和EventHandler

我想问之间的不同EventHandlerEventHandler<T>.

以前我EventHandler用一个自定义的EventArgs 实现了一个可以从用户控件传递到父页面的事件.

我认为我需要申请EventHandler< T >,但它可以通过使用来实现EventHandler.(事实上​​,当我尝试应用时出现奇怪的错误EventHandler<T>,程序运行但是IDE中显示的错误是我无法解决的[ C#Custom EventHandler ])

因此,我想知道我需要申请什么情况EventHandler < T >

public event EventHandler AppendProcess;
public event EventHandler<MyEventArg> AppendProcess;
Run Code Online (Sandbox Code Playgroud)

---更新---这是我在用户控件中调用事件的方式(正如我所说,我可以通过这样做将对象传递给父页面(尽管我不知道这样做是否正确)

if (AppendProcess == null) { }
else
    AppendProcess(this, new Common.WinLose_ProgressStage(Common.WinLose_SP_Parameter.upper, displayLevel + 1, 
                                                            (int)Common.WinLose_Level.lvChild4, thename, refundratio, 
                                                            selfproportion, -1, -1, loadlevel, isPlayer, betsource, gamecategory, false));
Run Code Online (Sandbox Code Playgroud)

c# asp.net eventhandler

1
推荐指数
1
解决办法
3920
查看次数

在 JavaFX 和 MVC 中处理控制器中的事件(不是 FXML)

我现在正在学习 JavaFx 和 MVC,我正在尝试通过控制器将按钮连接到模型。我尝试了很多使用方法,button.setOnActive(EventHandler e); 但它在视图类之外不起作用,那么正确的方法是什么?

这是我的视图类

public class View extends Application{


private TextField num1;
private Label addLabel;
private TextField num2;;
public Button calcB;
private TextField sol;

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Calculator");

    num1 = new TextField();
    addLabel = new Label("+");
    num2 = new TextField();

    calcB = new Button("Calculate");


    **// I'm trying to use this in the Controller
    calcB.setOnAction(event -> System.exit(0));**

    sol = new TextField();

    FlowPane flowPane = new FlowPane();
    flowPane.getChildren().addAll(num1, addLabel, num2, calcB, sol);

    Scene scene = …
Run Code Online (Sandbox Code Playgroud)

java model-view-controller javafx event-handling eventhandler

1
推荐指数
1
解决办法
9345
查看次数

将EventHandler添加到Label中包含的ImageView

我最近开始探索Java FX,并希望创建一个自定义标签,里面有一个ImageView.

这是我的自定义标签的代码.

Image image = new Image(getClass().getResourceAsStream("/img/remove.png"), 20, 20, true, true);
ImageView removeImageView = new ImageView(image);

Label customLabel = new Label(labelText, removeImageView);
customLabel.setFont(Font.font("Arial", FontWeight.BOLD, 20));
Run Code Online (Sandbox Code Playgroud)

这就是我的自定义标签的外观.

在此输入图像描述

现在我想将鼠标单击EventHandler添加到ImageView.这是我处理鼠标点击的代码.

removeImageView.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
      @Override
      public void handle(MouseEvent event) {
        System.out.println("Imageview Clicked");
      }
    });
Run Code Online (Sandbox Code Playgroud)

但是当我点击cross图像时,事件没有被捕获.

我试验了一下,并尝试将一个EventHandler添加到customLabel.标签能够捕获鼠标点击.

在我看来,我正面临这个问题,因为ImageView包含在Label中.我想知道的是,这是对JFX的限制还是有任何替代方法来实现此功能.谢谢.

java javafx mouseclick-event imageview eventhandler

1
推荐指数
1
解决办法
338
查看次数

如何在JavaFX上使用setOnAction事件

我想验证文本字段是否为空或不使用javafx。

我对事件处理程序感到困惑。我想确认一下:-是否有很多方法可以使用setOnAction:

submit.setOnAction((new EventHandler<MouseEvent>() { 
     public void handle(MouseEvent event) { 
        System.out.println("Hello World"); 
     } 
    }));
Run Code Online (Sandbox Code Playgroud)

要么

submit.setOnAction(e -> handle(e));
Run Code Online (Sandbox Code Playgroud)

这两个选择有什么区别?

  • 第二个选择是否不能使用ActionEvent Submit.setOnAction(e-> handle()); 但是定义e的目的是什么?

我想验证我的应用程序中的文本字段。

public class AppGUI extends Application{

public static void main(String[] args)
{
    launch();
}


public void start(Stage topView)
{
    createUI(topView);
}

private void createUI(Stage topView)
{
    TextField name = TextField();
    Button submit = new Button("Submit");
    submit.setOnAction(e -> validate());
}
private boolean validate()
{
   // if textfield is empty, return false. else, return true. 
}
Run Code Online (Sandbox Code Playgroud)

我在这里迷路了。如果setOnAction中的e未在validate中使用,可以吗?如何将textfield的值传递给validate()?使文本字段私有变量是唯一的方法吗?(因为我有这么多文本字段,所以我想知道它是否是一个不错的选择)。在createUI方法中,我怎么说是否validate()返回false,显示错误消息,如果是,则执行其他操作?谢谢你,很抱歉打扰

javafx eventhandler

1
推荐指数
1
解决办法
120
查看次数

为什么JSLint说"匿名函数并不总是为事件处理程序返回值"?

当我JSLint这段代码时:

$(document).keydown(function(e){ 
    if ($("#chaptersFunctionality").length !== 0) {
        if (e.keyCode == '13')
            return false;
        if ($("#kelvin").val() === "" && $("#caleb").attr("title") === "Show all steps") {
            switch(e.which){
            case 39:    if ((parseInt(currentAnchor)+1) < parseInt(maxi))
                expandMe(++currentAnchor);
                break;
            case 37:    if (currentAnchor > 0)
                expandMe(currentAnchor-1);
                break;
            }
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

...我得到了很多警告,其中大部分都是我嘲笑的,但这个让我难过:" 匿名函数并不总是返回值 "

为什么这么说呢?事件处理程序不是匿名函数,是吗?并且它无论如何都没有返回任何价值,是吗?那么这意味着什么,以及[moll,pac]如果是什么呢?

jquery jslint anonymous-function eventhandler

0
推荐指数
1
解决办法
790
查看次数

网格上的 C# WPF MouseEnter 和 MouseLeave

我制作了 2 个 MouseEvents,它们可以工作,但问题是它们的工作方式与我预期的不一样。当我的鼠标指针在网格空间中时,我需要这 2 个事件处于活动状态,但现在它们仅在指针位于任何行上时才起作用。

我的代码:

            // Grid 3 Rows.
        Grid grid_Edit = new Grid();
        Grid.SetRow(grid_Edit, 0);
        Grid.SetColumn(grid_Edit, 1);
        RowDefinition rowDef1 = new RowDefinition();
        RowDefinition rowDef2 = new RowDefinition();
        RowDefinition rowDef3 = new RowDefinition();
        grid_Edit.RowDefinitions.Add(rowDef1);
        grid_Edit.RowDefinitions.Add(rowDef2);
        grid_Edit.RowDefinitions.Add(rowDef3);
        grid_Edit.RowDefinitions[0].Height = new GridLength(1, GridUnitType.Star);
        grid_Edit.RowDefinitions[1].Height = new GridLength(1, GridUnitType.Star);
        grid_Edit.RowDefinitions[2].Height = new GridLength(1, GridUnitType.Star);
        grid_Edit.MouseEnter += new MouseEventHandler(gridEdit_MouseEnter);
        grid_Edit.MouseLeave += new MouseEventHandler(gridEdit_MouseLeave);
        mainWindow_ref.Children.Add(grid_Edit);

        // 3 lines
        line1.Stroke = Brushes.White;
        line1.X1 = 1;
        line1.Stretch = Stretch.Fill;
        Grid.SetRow(line1, 0);
        line1.VerticalAlignment = VerticalAlignment.Center;

        line2.Stroke …
Run Code Online (Sandbox Code Playgroud)

c# wpf grid mouseevent eventhandler

0
推荐指数
1
解决办法
1100
查看次数

uwp页面根本不触发keydown事件

在我的uwp应用程序中,我只是添加了一个新页面并导航到该页面,并且该页面上没有任何内容仅是默认网格。但是我试图接收没有任何按键触发的按键事件。我还把keydown放到了xaml的网格上,并放到了后面代码中的页面上,但是我仍然没有断点,但仍然没有激活。

a

<Grid KeyDown="VideoPageKeyDown">

</Grid>
Run Code Online (Sandbox Code Playgroud)

背后的代码

public sealed partial class VideoPlay : Page
{
    public VideoPlay()
    {
        this.InitializeComponent();
        KeyDown += VideoPageKeyDown;
    }

    private void VideoPageKeyDown(object sender, KeyRoutedEventArgs e)
    {
        if (e.Key == Windows.System.VirtualKey.GamepadDPadDown || e.Key == Windows.System.VirtualKey.GamepadLeftThumbstickDown)
        {
            //VideoMenuGrid.Visibility = Visibility.Visible;
            //await VideoMenuGrid.Offset(200f, 0f, 1000, 0).StartAsync();
        }
        else if (e.Key == Windows.System.VirtualKey.GamepadDPadUp || e.Key == Windows.System.VirtualKey.GamepadLeftThumbstickUp)
        {
            //await VideoMenuGrid.Offset(0f, 0f, 1000, 0).StartAsync();
            //VideoMenuGrid.Visibility = Visibility.Collapsed;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# xaml keydown eventhandler uwp

0
推荐指数
1
解决办法
966
查看次数