java.awt.event.ActionEvent.getSource()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(261)

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

ActionEvent.getSource介绍

暂无

代码示例

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

public void actionPerformed(ActionEvent e) {
  JComboBox box = (JComboBox) e.getSource();
  LogLevel level = (LogLevel) box.getSelectedItem();
  setLeastSevereDisplayedLogLevel(level);
 }
});

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

public class Calc extends JFrame implements ActionListener {

  private Button button1;

  public Calc()
  {
    super();
    this.setSize(100, 100);
    this.setVisible(true);

    this.button1 = new JButton("1");
    this.button1.addActionListener(this);
    this.add(button1);
  }

  public static void main(String[] args) {

    Calc calc = new Calc();
    calc.setVisible(true);
  }

  public void actionPerformed(ActionEvent e) {
    if(e.getSource() == button1)
  }  

}

代码示例来源:origin: RipMeApp/ripme

JButton yesButton = new JButton("YES");
    JButton noButton = new JButton("NO");
    yesButton.setPreferredSize(new Dimension(70, 30));
    noButton.setPreferredSize(new Dimension(70, 30));
});
configLogLevelCombobox.addActionListener(arg0 -> {
  String level = ((JComboBox) arg0.getSource()).getSelectedItem().toString();
  setLogLevel(level);
});
configSelectLangComboBox.addActionListener(arg0 -> {
  String level = ((JComboBox) arg0.getSource()).getSelectedItem().toString();
  rb = Utils.getResourceBundle(level);
  changeLocale();
  Utils.setConfigBoolean("clipboard.autorip", configClipboardAutorip.isSelected());
  ClipboardUtils.setClipboardAutoRip(configClipboardAutorip.isSelected());
  trayMenuAutorip.setState(configClipboardAutorip.isSelected());
  Utils.configureLogger();
});

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

@FXML
private void handleButtonAction(ActionEvent event) {
  System.out.println("You clicked me!");
  label.setText("Hello World!");
  //Here I want to swap the screen!

  Stage stageTheEventSourceNodeBelongs = (Stage) ((Node)event.getSource()).getScene().getWindow();
  // OR
  Stage stageTheLabelBelongs = (Stage) label.getScene().getWindow();
  // these two of them return the same stage
  // Swap screen
  stage.setScene(new Scene(new Pane()));
}

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

public class Dropdown implements ActionListener {

  public String selected;

  @Override
  public void actionPerformed(ActionEvent e) {
    JComboBox cb = (JComboBox) e.getSource();
    System.out.println(cb.getSelectedItem());
  }

  public Dropdown(String selected) {
    this.selected = selected;

  }
}

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

JButton take = new JButton("Take Please");
 button.add(take);
 take.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
   e.getSource();
   System.out.println("Here");
  }
 });

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

JButton okButton = new JButton("OK");  
   okButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
     JComboBox jComboBox1 = (JComboBox) e.getSource();
     Item item = (Item) jComboBox1.getSelectedItem();
     String code = (String) item.getValue();
     System.out.println(code);
    }          
  });

代码示例来源:origin: winterDroid/android-drawable-importer-intellij-plugin

@Override
  public void actionPerformed(ActionEvent actionEvent) {
    final JCheckBox source = (JCheckBox) actionEvent.getSource();
    final Resolution resolution = ((ResolutionButtonModel) source.getModel()).getResolution();
    controller.setExportResolution(resolution, source.isSelected());
  }
};

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

public void actionPerformed(ActionEvent e) {
  Port port = getPort();
  if (e.getSource() == labelField) {
    if (labelField.getText().equals(port.getDisplayLabel())) return;
    nodeAttributesDialog.setPortLabel(portName, labelField.getText());
  } else if (e.getSource() == descriptionField) {
    nodeAttributesDialog.setPortDescription(portName, descriptionField.getText());
  } else if (e.getSource() == widgetBox) {
    HumanizedObject newWidget = (HumanizedObject) widgetBox.getSelectedItem();
    if (port.getWidget() == newWidget.getObject()) return;
    nodeAttributesDialog.setPortWidget(portName, (Port.Widget) newWidget.getObject());
  } else if (e.getSource() == rangeBox) {
    HumanizedObject newRange = (HumanizedObject) rangeBox.getSelectedItem();
    if (port.getRange() == newRange.getObject()) return;
    nodeAttributesDialog.setPortRange(portName, (Port.Range) newRange.getObject());
  } else if (e.getSource() == valueField) {
    String newValue = valueField.getText();
    if (port.getValue() != null && port.getValue().toString().equals(newValue)) return;
  } else if (e.getSource() == minimumValueCheck) {
    if (minimumValueCheck.isSelected() && port.getMinimumValue() != null) return;
    nodeAttributesDialog.setPortMinimumValue(portName, minimumValueCheck.isSelected() ? (double) 0f : null);
  } else if (e.getSource() == minimumValueField) {
    try {
      float v = Float.parseFloat(minimumValueField.getText());
  } else if (e.getSource() == maximumValueCheck) {
    if (maximumValueCheck.isSelected() && port.getMaximumValue() != null) return;
    nodeAttributesDialog.setPortMaximumValue(portName, maximumValueCheck.isSelected() ? (double) 0f : null);
  } else if (e.getSource() == maximumValueField) {

代码示例来源:origin: ron190/jsql-injection

this.setLayout(borderLayoutPreferences);
final JButton buttonCheckIp = new JButton("Check your IP");
buttonCheckIp.addActionListener(new ActionCheckIP());
buttonCheckIp.setToolTipText(
this.checkboxIsTamperingBase64.setToolTipText(tooltipIsTamperingBase64);
this.checkboxIsTamperingBase64.setFocusable(false);
JButton labelIsTamperingBase64 = new JButton("Encode SQL expression to Base64");
labelIsTamperingBase64.setToolTipText(tooltipIsTamperingBase64);
labelIsTamperingBase64.addActionListener(actionEvent -> {
  this.checkboxIsTamperingBase64.setSelected(!this.checkboxIsTamperingBase64.isSelected());
  this.actionListenerSave.actionPerformed(null);
});
labelIsTamperingEqualToLike.setToolTipText(tooltipIsTamperingEqualToLike);
labelIsTamperingEqualToLike.addActionListener(actionEvent -> {
  this.checkboxIsTamperingEqualToLike.setSelected(!this.checkboxIsTamperingEqualToLike.isSelected());
  this.actionListenerSave.actionPerformed(null);
});
  if (actionEvent.getSource() != this.checkboxProcessCsrf) {
    this.checkboxProcessCsrf.setSelected(!this.checkboxProcessCsrf.isSelected());
  if (actionEvent.getSource() != this.checkboxIsCheckingAllParam) {
    this.checkboxIsCheckingAllParam.setSelected(!this.checkboxIsCheckingAllParam.isSelected());

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

@Override
 public void actionPerformed(ActionEvent ae) {
 if (ae.getSource() == this.button1) {
   System.out
     .println(((MatrixButton) ae.getSource()).getRow() + "," + ((MatrixButton) ae.getSource()).getCol());
 } else if (ae.getSource() == this.button2) {
   // TODO
 } else if (ae.getSource() == this.button3) {
   // TODO
 }
 }

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

String[] bookArray = {"a", "b", "c"};
JComboBox bookComboBox = new JComboBox(bookArray);
bookComboBox.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    JComboBox cb = (JComboBox) e.getSource();
    bookNameSelected = (String) cb.getSelectedItem();
    System.out.println("book name selected:" + bookNameSelected);
  }
});
bookComboBox.setSelectedIndex(0);

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

JButton newButton = new JButton("New Message");
newButton.addActionListener(this);
this.add(newButton);

public void newMessage() {
System.out.println(in.readObject().toString);
}

public void actionPerformed(ActionEvent ae) {
  if (ae.getSource().equals(newButton)) {
    newMessage();    
  }  
}

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

public void actionPerformed(ActionEvent e) {
  JComboBox box = (JComboBox) e.getSource();
  String font = (String) box.getSelectedItem();
  _table.setFont(new Font(font, Font.PLAIN, _fontSize));
  _fontName = font;
 }
}

代码示例来源:origin: winterDroid/android-drawable-importer-intellij-plugin

@Override
  public void actionPerformed(ActionEvent actionEvent) {
    final JCheckBox source = (JCheckBox) actionEvent.getSource();
    final Resolution resolution = ((ResolutionButtonModel) source.getModel()).getResolution();
    if (source.isSelected()) {
      controller.addTargetResolution(resolution);
    } else {
      controller.removeTargetResolution(resolution);
    }
  }
};

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

final JButton okay = new JButton("Ok");
     okay.addActionListener(new ActionListener() {
       @Override
       public void actionPerformed(ActionEvent e) {
         JOptionPane pane = getOptionPane((JComponent)e.getSource());
         // set the value of the option pane
         pane.setValue(JOptionPane.OK_OPTION);
       }
     });

代码示例来源:origin: hyperion-project/hypercon

@Override
  public void actionPerformed(ActionEvent e) {
    if (e.getSource().equals(mBlackBorderEnable)) {
      mBlackBorderConfig.mBlackBorderEnabled = mBlackBorderEnable
      .isSelected();
      toggleEnabled(mBlackBorderConfig.mBlackBorderEnabled);
    }
    mBlackBorderConfig.mBlackbordermCombo = (BlackBorderStandard) mBlackBordermCombo
        .getSelectedItem();
    }
};

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

@Override
     public void actionPerformed(ActionEvent e) {
       if (e.getSource() == thirdBtn) {
         //System.out.println("Third Button Click");
         System.out.println(((JComponent) e.getSource()).getName()+" Click");
       }
     }

代码示例来源:origin: cmu-phil/tetrad

public void actionPerformed(ActionEvent e) {
        JComboBox box = (JComboBox) e.getSource();
        Node node = (Node) box.getSelectedItem();
        System.out.println(node);

        if ("SELECT_ALL".equals(node.getName())) {
          nodes1 = new ArrayList<>(graph.getNodes());
        } else {
          nodes1 = Collections.singletonList(node);
        }

        Preferences.userRoot().put("pathFrom", node.getName());

//                update(graph, textArea, nodes1, nodes2, method);
      }

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

JButton button = new JButton("Button 1");
button.putClientProperty("ValueKey", "Actual value");

ActionListener listener = new ActionListener() {        
  @Override
  public void actionPerformed(ActionEvent e) {
    JButton button = (JButton)e.getSource();
    System.out.println(button.getClientProperty("ValueKey"));
  };
}

相关文章