我需要一种在 java 中仅使用 SWT 自动单击程序中按钮的方法

I need a method that automatically clicks a button in my program using only SWT in java

我需要一种方法,当我告诉它时按下程序中的特定按钮,但我只被允许使用 SWT。

Button btnred = createButton(parent, "");`

public Button createButton(Composite parent, String text)
{
    Button btn = new Button(parent, SWT.PUSH);
    btn.setText(text);
    btn.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    return btn;
}'

btnred.addMouseListener(new MouseListener()
{
    public void mouseDown(MouseEvent e)
    {
        btnred.setImage(redglow);
        rev.CheckChoice(one);
    }
    public void mouseUp(MouseEvent e)
    {
        btnred.setImage(red);
    }
    @Override
    public void mouseDoubleClick(MouseEvent e) {
        // TODO Auto-generated method stub

    }

});

您可以通过以下方式以编程方式调用 ButtonListener

button.notifyListeners(SWT.Selection, new Event());