javax.swing.JButton.getActionListeners()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(197)

本文整理了Java中javax.swing.JButton.getActionListeners()方法的一些代码示例,展示了JButton.getActionListeners()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JButton.getActionListeners()方法的具体详情如下:
包路径:javax.swing.JButton
类名称:JButton
方法名:getActionListeners

JButton.getActionListeners介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

for( JButton currentButton: button ) {
  for( ActionListener al : currentButton.getActionListeners() ) {
    currentButton.removeActionListener( al );
  }
}

代码示例来源:origin: magefree/mage

public void cleanUp() {
  for (ActionListener al : btnGenerate.getActionListeners()) {
    btnGenerate.removeActionListener(al);
  }
  for (ActionListener al : btnCancel.getActionListeners()) {
    btnCancel.removeActionListener(al);
  }
  for (ActionListener al : btnReset.getActionListeners()) {
    btnReset.removeActionListener(al);
  }
  for (ItemListener il : cAdvanced.getItemListeners()) {
    cAdvanced.removeItemListener(il);
  }
}

代码示例来源:origin: magefree/mage

public void CleanUp() {
  battlefieldPanel.cleanUp();
  playerPanel.cleanUp();
  for (ActionListener al : btnCheat.getActionListeners()) {
    btnCheat.removeActionListener(al);
  }
  // Taken form : https://community.oracle.com/thread/2183145
  // removed the internal focus of a popupMenu data to allow GC before another popup menu is selected
  for (ChangeListener listener : MenuSelectionManager.defaultManager().getChangeListeners()) {
    if (listener.getClass().getName().contains("MenuKeyboardHelper")) {
      try {
        Field field = listener.getClass().getDeclaredField("menuInputMap");
        field.setAccessible(true);
        field.set(listener, null);
      } catch (Exception e) {
        // ignored
      }
      break;
    }
  }
  for (MouseListener ml : battlefieldPanel.getMainPanel().getMouseListeners()) {
    battlefieldPanel.getMainPanel().removeMouseListener(ml);
  }
  popupMenu.getUI().uninstallUI(this);
}

代码示例来源:origin: magefree/mage

public void cleanUp() {
  if (dayNightButton != null) {
    for (ActionListener al : dayNightButton.getActionListeners()) {
      dayNightButton.removeActionListener(al);
    }
  }
  for (MouseListener ml : this.getMouseListeners()) {
    this.removeMouseListener(ml);
  }
  for (MouseMotionListener ml : this.getMouseMotionListeners()) {
    this.removeMouseMotionListener(ml);
  }
  for (MouseWheelListener ml : this.getMouseWheelListeners()) {
    this.removeMouseWheelListener(ml);
  }
  // this holds reference to ActionCallback forever so set it to null to prevent
  this.callback = null;
  this.data = null;
}

代码示例来源:origin: magefree/mage

for (ActionListener al : this.btnPlay.getActionListeners()) {
  this.btnPlay.removeActionListener(al);
for (ActionListener al : this.btnStopReplay.getActionListeners()) {
  this.btnStopReplay.removeActionListener(al);
for (ActionListener al : this.btnNextPlay.getActionListeners()) {
  this.btnNextPlay.removeActionListener(al);
for (ActionListener al : this.btnNextPlay.getActionListeners()) {
  this.btnNextPlay.removeActionListener(al);
for (ActionListener al : this.btnPreviousPlay.getActionListeners()) {
  this.btnPreviousPlay.removeActionListener(al);
for (ActionListener al : this.btnSkipForward.getActionListeners()) {
  this.btnSkipForward.removeActionListener(al);
final BasicSplitPaneDivider divider = myUi.getDivider();
final JButton upArrowButton = (JButton) divider.getComponent(0);
for (ActionListener al : upArrowButton.getActionListeners()) {
  upArrowButton.removeActionListener(al);
for (ActionListener al : downArrowButton.getActionListeners()) {
  downArrowButton.removeActionListener(al);

代码示例来源:origin: orbisgis/orbisgis

@Override
public Component getComponent() {
    // Add the listener if it is not already added
    if(!Arrays.asList(browseFolders.getActionListeners())
        .contains(browseButtonAction)) {
        browseFolders.addActionListener(browseButtonAction);                        
    }
    return mainComponent;
}
/**

代码示例来源:origin: org.gdl-lang.gdl-tools/cds-gui-swing

private static void setEnableActionListeners(boolean enable, JButton button) {
  for (ActionListener actionListener : button.getActionListeners()) {
    if (actionListener instanceof SelectCodeActionListener) {
      ((SelectCodeActionListener) actionListener).setEnable(enable);
    }
  }
}

代码示例来源:origin: stackoverflow.com

public static void changeAction(JButton button, ActionListener al) {
  for (ActionListener listener: button.getActionListeners()) {
    button.removeActionListener(listener);
  }
  button.addActionListener(al);
}

代码示例来源:origin: stackoverflow.com

public class MyClass {
 private ActionListener fListener = new MyListener();
 private JButton fComponent = new JButton("Test");

 public MyClass() {
   fComponent.addActionListener(fListener);
 }
 public void setListener() {
  if (fComponent.getActionListeners().length == 0) {
    fComponent.addActionListener(fListener);
   }
 }

 public void removeListener() {
  if (fComponent.getActionListeners().length !=0) {
   fComponent.removeActionListener(fListener);
  }
 }
}

代码示例来源:origin: zhuzhengquan/pc5s

@Override
public void actionPerformed(ActionEvent e) {
  String resultText = restInvoker.get("/client/cache/removeall", String.class);
  Map<String,Object> map = JsonUtil.unserializeFromJson(resultText, Map.class);
   if(!((String)map.get("result")).equals("success")){
     JOptionPane.showMessageDialog(null, map.get("message"), "清空失败",JOptionPane.ERROR_MESSAGE);
   }
   jbView.getActionListeners()[0].actionPerformed(null);
}

代码示例来源:origin: MegaMek/mekhq

public void changeBuyBtnToSelectBtn () {
  for (ActionListener actionListener : btnBuy.getActionListeners()) {
    btnBuy.removeActionListener(actionListener);
  }
  ResourceBundle resourceMap = ResourceBundle.getBundle("UnitSelectorDialog", new EncodeControl()); //$NON-NLS-1$
  btnBuy.setText(resourceMap.getString("btnBuy.textSelect")); // NOI18N
  btnBuy.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
      btnBuySelectActionPerformed(evt);
    }
  });
}

代码示例来源:origin: stackoverflow.com

public static void toggle(JSplitPane sp, boolean collapse) {
   try {
     BasicSplitPaneDivider bspd = ((BasicSplitPaneUI) sp.getUI()).getDivider();
     Field buttonField = BasicSplitPaneDivider.class.
         getDeclaredField(collapse ? "rightButton" : "leftButton");
     buttonField.setAccessible(true);
     JButton button = (JButton) buttonField.get(((BasicSplitPaneUI) sp.getUI()).getDivider());
     button.getActionListeners()[0].actionPerformed(new ActionEvent(bspd, MouseEvent.MOUSE_CLICKED,
         "bum"));
   } catch (Exception e) {
     e.printStackTrace();
   }
 }

代码示例来源:origin: jsettlers/settlers-remake

private void setStartButtonActionListener(ActionListener actionListener) {
  ActionListener[] actionListeners = startGameButton.getActionListeners();
  J8Arrays.stream(actionListeners).forEach(startGameButton::removeActionListener);
  startGameButton.addActionListener(actionListener);
}

代码示例来源:origin: jsettlers/settlers-remake

private void setCancelButtonActionListener(ActionListener actionListener) {
  ActionListener[] actionListeners = cancelButton.getActionListeners();
  J8Arrays.stream(actionListeners).forEach(cancelButton::removeActionListener);
  cancelButton.addActionListener(actionListener);
}

代码示例来源:origin: opendatakit/briefcase

private void click(JButton button) {
  invokeLater(() -> Arrays.asList(button.getActionListeners()).forEach(al -> al.actionPerformed(new ActionEvent(button, 1, ""))));
 }
}

代码示例来源:origin: opendatakit/briefcase

private void click(JButton button) {
  GuiActionRunner.execute(() -> Arrays.asList(button.getActionListeners()).forEach(al -> al.actionPerformed(new ActionEvent(button, 1, ""))));
 }
}

代码示例来源:origin: opendatakit/briefcase

private void click(JButton button) {
 GuiActionRunner.execute(() -> Arrays.asList(button.getActionListeners()).forEach(al -> al.actionPerformed(new ActionEvent(button, 1, ""))));
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/toniclf

protected Component createPreviousButton()
{
  Component tmpButton= super.createPreviousButton();
  if (tmpButton instanceof JButton)
  {
    JButton result= new ArrowButton(SwingConstants.SOUTH);
    ActionListener al[]= ((JButton) tmpButton).getActionListeners();
    for (int i= 0; i < al.length; i++)
      result.addActionListener(al[i]);
    MouseListener ml[]= ((JButton) tmpButton).getMouseListeners();
    for (int i= 0; i < ml.length; i++)
      result.addMouseListener(ml[i]);
    return result;
  }
  else
    return tmpButton;
}

代码示例来源:origin: Microsoft/azure-devops-intellij

@Test
public void testAddActionListener() {
  ActionListener mockListener = mock(ActionListener.class);
  resolveConflictsForm.addActionListener(mockListener);
  assertEquals(mockListener, resolveConflictsForm.myAcceptYoursButton.getActionListeners()[0]);
  assertEquals(mockListener, resolveConflictsForm.myAcceptTheirsButton.getActionListeners()[0]);
  assertEquals(mockListener, resolveConflictsForm.myMergeButton.getActionListeners()[0]);
}

代码示例来源:origin: triplea-game/triplea

@Test
void checkActionListener() {
 // button action will be to add one to our integer, we'll fire the button action and verify we get the +1
 final AtomicInteger integer = new AtomicInteger(0);
 final JButton button = JButtonBuilder.builder()
   .title("title")
   .actionListener(integer::incrementAndGet)
   .toolTip("toolTip")
   .build();
 Arrays.stream(button.getActionListeners())
   .forEach(listener -> listener.actionPerformed(new ActionEvent(new Object(), 0, "")));
 assertThat(integer.get(), is(1));
 assertThat(button.getToolTipText(), is("toolTip"));
}

相关文章

JButton类方法