尝试向 JButton 添加事件侦听器,以便我可以向用户大声朗读按钮的标签

问题描述 投票:0回答:0

基本上我想使用 FreeTTS Java 库向用户读出他们的鼠标移过的按钮的名称。

''' cutButton.addMouseListener(新鼠标适配器(){

  public void mouseEntered(MouseEvent e) {
      // Read the button name out loud when the mouse enters the button
      JOptionPane.showMessageDialog(null, cutButton.getText());
  }
  public void mouseExited(MouseEvent e) {
      // Do nothing when the mouse exits the button
  }
  // Other methods of the MouseListener interface that are not needed can be left empty
  public void mouseClicked(MouseEvent e) {
      return;
  }
  public void mousePressed(MouseEvent e) {
      return;
  }
  public void mouseReleased(MouseEvent e) {
      return;
  }

}); '''

目前我只是想在鼠标进入按钮区域时弹出一个带有按钮名称的对话框。但是我一直遇到错误,例如“令牌“addMouseListener”的语法错误,无效的 AnnotationName”,这导致代码无法正常工作。任何帮助都会很棒!!!谢谢

java swing jbutton
© www.soinside.com 2019 - 2024. All rights reserved.