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

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

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

JButton.addActionListener介绍

暂无

代码示例

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

  1. JButton button = new JButton("Do Something");
  2. button.addActionListener( action );

代码示例来源:origin: stanfordnlp/CoreNLP

  1. private void buildExtractButton() {
  2. if (extractButton == null) {
  3. JPanel buttonPanel = new JPanel();
  4. extractButton = new JButton("Extract");
  5. buttonPanel.add(extractButton);
  6. frame.add(buttonPanel, BorderLayout.SOUTH);
  7. extractButton.addActionListener(actor);
  8. }
  9. }

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

  1. JLabel label = new JLabel();
  2. JButton button = new JButton("Click me");
  3. button.addActionListener((ActionEvent e) -> {
  4. // This event listener is run when the button is clicked.
  5. // We don't need to loop while waiting.
  6. label.setText("Button was clicked");
  7. });

代码示例来源:origin: ballerina-platform/ballerina-lang

  1. private JButton createNewRowButton() {
  2. final JButton newRowButton = new JButton();
  3. newRowButton.setText("+");
  4. newRowButton.addActionListener(e -> rootPanel.add(createArtifactRow("", "", "", "")));
  5. return newRowButton;
  6. }

代码示例来源:origin: stanfordnlp/CoreNLP

  1. private void buildExtractButton() {
  2. if (extractButton == null) {
  3. JPanel buttonPanel = new JPanel();
  4. extractButton = new JButton("Run NER");
  5. buttonPanel.add(extractButton);
  6. frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
  7. extractButton.addActionListener(actor);
  8. }
  9. }

代码示例来源:origin: skylot/jadx

  1. public ProgressPanel(final MainWindow mainWindow, boolean showCancelButton) {
  2. progressLabel = new JLabel();
  3. progressBar = new JProgressBar(0, 100);
  4. progressBar.setIndeterminate(true);
  5. progressBar.setStringPainted(false);
  6. progressLabel.setLabelFor(progressBar);
  7. setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
  8. setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
  9. setVisible(false);
  10. add(progressLabel);
  11. add(progressBar);
  12. if (showCancelButton) {
  13. JButton cancelButton = new JButton(ICON_CANCEL);
  14. cancelButton.setPreferredSize(new Dimension(ICON_CANCEL.getIconWidth(), ICON_CANCEL.getIconHeight()));
  15. cancelButton.setToolTipText("Cancel background jobs");
  16. cancelButton.setBorderPainted(false);
  17. cancelButton.setFocusPainted(false);
  18. cancelButton.setContentAreaFilled(false);
  19. cancelButton.addActionListener(new ActionListener() {
  20. @Override
  21. public void actionPerformed(ActionEvent e) {
  22. mainWindow.cancelBackgroundJobs();
  23. }
  24. });
  25. add(cancelButton);
  26. }
  27. }

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

  1. tabPane.addTab(title, tabBody);
  2. int index = tabPane.indexOfTab(title);
  3. JPanel pnlTab = new JPanel(new GridBagLayout());
  4. pnlTab.setOpaque(false);
  5. JLabel lblTitle = new JLabel(title);
  6. JButton btnClose = new JButton("x");
  7. GridBagConstraints gbc = new GridBagConstraints();
  8. gbc.gridx = 0;
  9. gbc.gridy = 0;
  10. gbc.weightx = 1;
  11. pnlTab.add(lblTitle, gbc);
  12. gbc.gridx++;
  13. gbc.weightx = 0;
  14. pnlTab.add(btnClose, gbc);
  15. tabPane.setTabComponentAt(index, pnlTab);
  16. btnClose.addActionListener(myCloseActionHandler);

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

  1. private JButton createButton(String text) {
  2. JButton retval=new JButton(text);
  3. retval.addActionListener(this);
  4. return retval;
  5. }

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

  1. private JComponent getSouthLabel() {
  2. final JPanel result = new JPanel();
  3. final JButton ok = new JButton("OK");
  4. ok.addActionListener(new ActionListener() {
  5. public void actionPerformed(ActionEvent ae) {
  6. dispose();
  7. }
  8. });
  9. result.add(ok);
  10. return result;
  11. }

代码示例来源:origin: apache/ignite

  1. /**
  2. * Default constructor.
  3. */
  4. private HitRateMetricsSandbox() {
  5. IgniteUtils.onGridStart();
  6. JButton hitBtn = new JButton("Hit");
  7. hitBtn.addActionListener(new ActionListener() {
  8. @Override public void actionPerformed(ActionEvent e) {
  9. metrics.onHit();
  10. }
  11. });
  12. new Timer(100, new ActionListener() {
  13. @Override public void actionPerformed(ActionEvent evt) {
  14. rateLb.setText(Double.toString(metrics.getRate()));
  15. }
  16. }).start();
  17. setContentPane(createPanel(new JLabel("Hits in 5 seconds:"), rateLb, hitBtn));
  18. setMinimumSize(new Dimension(300, 120));
  19. }

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

  1. contentPanel.add(chart, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH,
  2. new Insets(0, 0, 0, 0), 0, 0));
  3. expandButton = new JButton("+");
  4. expandButton.setBorder(BorderFactory.createEmptyBorder(4, 10, 4, 10));
  5. contentPanel.add(expandButton, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST,
  6. GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
  7. expandButton.addActionListener(new ActionListener() {
  8. public void actionPerformed (ActionEvent event) {
  9. chart.setExpanded(!chart.isExpanded());

代码示例来源:origin: ballerina-platform/ballerina-lang

  1. private JButton createRemoveRowButton(final JPanel panel) {
  2. final JButton removeRowButton = new JButton();
  3. removeRowButton.setText("-");
  4. removeRowButton.addActionListener(e -> {
  5. final int idx = getComponentIndex(panel);
  6. rootPanel.remove(panel);
  7. rows.remove(idx);
  8. });
  9. return removeRowButton;
  10. }

代码示例来源:origin: stanfordnlp/CoreNLP

  1. private JPanel makeTSurgeonButtons() {
  2. JPanel tsurgeonButtonBox = new JPanel();
  3. tsurgeonButtonBox.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
  4. tsurgeonButtonBox.setLayout(new GridBagLayout());
  5. tsurgeonHelp = new JButton("Help");
  6. tsurgeonHelp.addActionListener(this);
  7. cancelTsurgeon = new JButton("Cancel");
  8. cancelTsurgeon.addActionListener(this);
  9. runScript = new JButton("Run script");
  10. runScript.addActionListener(this);
  11. //make constraints and add in
  12. GridBagConstraints c = new GridBagConstraints();
  13. c.anchor = GridBagConstraints.NORTHEAST;
  14. c.fill = GridBagConstraints.HORIZONTAL;
  15. tsurgeonButtonBox.add(runScript,c);
  16. tsurgeonButtonBox.add(cancelTsurgeon,c);
  17. tsurgeonButtonBox.add(tsurgeonHelp,c);
  18. c.gridwidth = GridBagConstraints.REMAINDER;
  19. c.weightx = 1.0;
  20. c.weighty = 1.0;
  21. tsurgeonButtonBox.add(new JLabel(), c);
  22. return tsurgeonButtonBox;
  23. }
  24. //separated out to make constructor more readable

代码示例来源:origin: stanfordnlp/CoreNLP

  1. JButton cancel = new javax.swing.JButton();
  2. new JLabel("Parsing " + sentences.size() + " sentences"));
  3. dialog.add(BorderLayout.CENTER, progress);
  4. dialog.add(BorderLayout.SOUTH, cancel);
  5. cancel.addActionListener(evt -> thread.cancelled = true);

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

  1. contentPanel.add(chart, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH,
  2. new Insets(0, 0, 0, 0), 0, 0));
  3. expandButton = new JButton("+");
  4. expandButton.setBorder(BorderFactory.createEmptyBorder(4, 10, 4, 10));
  5. contentPanel.add(expandButton, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST,
  6. GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
  7. expandButton.addActionListener(new ActionListener() {
  8. public void actionPerformed (ActionEvent event) {
  9. chart.setExpanded(!chart.isExpanded());

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

  1. private JButton createGoButton() {
  2. JButton b = new JButton("Go");
  3. b.setMnemonic('g');
  4. b.addActionListener(new ShowListener());
  5. b.addActionListener(new XPathListener());
  6. b.addActionListener(new DFAListener());
  7. b.addActionListener(new ActionListener() {
  8. @Override
  9. public void actionPerformed(ActionEvent e) {
  10. saveSettings();
  11. }
  12. });
  13. return b;
  14. }

代码示例来源:origin: stanfordnlp/CoreNLP

  1. private JPanel makeFoundStatsBox() {
  2. JPanel foundStatsBox = new JPanel();
  3. foundStatsBox.setLayout(new GridBagLayout());
  4. Box labelBox = Box.createHorizontalBox();
  5. foundStats = new JLabel(" ");
  6. labelBox.add(foundStats);
  7. historyButton = new JButton("Statistics");
  8. historyButton.setEnabled(false);
  9. historyButton.addActionListener(this);
  10. GridBagConstraints c = new GridBagConstraints();
  11. c.fill = GridBagConstraints.BOTH;
  12. c.weightx = 1.7;
  13. foundStatsBox.add(labelBox,c);
  14. c.weightx = .3;
  15. c.gridwidth = 1;
  16. foundStatsBox.add(historyButton);
  17. return foundStatsBox;
  18. }

代码示例来源:origin: skylot/jadx

  1. public SearchBar(RSyntaxTextArea textArea) {
  2. rTextArea = textArea;
  3. JLabel findLabel = new JLabel(NLS.str("search.find") + ":");
  4. add(findLabel);
  5. add(searchField);
  6. JButton prevButton = new JButton(NLS.str("search.previous"));
  7. prevButton.setIcon(ICON_UP);
  8. prevButton.addActionListener(new ActionListener() {
  9. @Override
  10. public void actionPerformed(ActionEvent e) {
  11. add(prevButton);
  12. JButton nextButton = new JButton(NLS.str("search.next"));
  13. nextButton.setIcon(ICON_DOWN);
  14. nextButton.addActionListener(new ActionListener() {
  15. @Override
  16. public void actionPerformed(ActionEvent e) {
  17. add(wholeWordCB);
  18. JButton closeButton = new JButton();
  19. closeButton.setIcon(ICON_CLOSE);
  20. closeButton.addActionListener(l -> toggle());
  21. closeButton.setBorderPainted(false);
  22. add(closeButton);

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

  1. FileBrowser() {
  2. super();
  3. setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
  4. textField = new JTextField(15);
  5. textField.setEnabled(false);
  6. add(textField);
  7. browse = new JButton("Browse");
  8. add(browse);
  9. browse.addActionListener(e -> {
  10. JFileChooser jFileChooser = new JFileChooser(file != null ? file.getParentFile() : null);
  11. int returnVal = jFileChooser.showOpenDialog(FileBrowser.this);
  12. if (returnVal == JFileChooser.APPROVE_OPTION) {
  13. setFile(jFileChooser.getSelectedFile());
  14. }
  15. });
  16. }

代码示例来源:origin: stanfordnlp/CoreNLP

  1. private JPanel makeBrowseButtonBox() {
  2. JPanel buttonBox = new JPanel();
  3. buttonBox.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
  4. buttonBox.setLayout(new GridBagLayout());
  5. browseButton = new JButton("Browse Trees");
  6. browseButton.addActionListener(this);
  7. JLabel sizeLabel = new JLabel("Tree size:");
  8. JSlider fontSlider = new JSlider(2, 64, 12);
  9. fontSlider.addChangeListener(this);
  10. GridBagConstraints buttonConstraints = new GridBagConstraints();
  11. buttonConstraints.fill = GridBagConstraints.HORIZONTAL;
  12. buttonConstraints.weightx = 0.2;
  13. buttonConstraints.weighty = 0.2;
  14. buttonBox.add(browseButton,buttonConstraints);
  15. buttonConstraints.weightx = 0.6;
  16. buttonBox.add(fontSlider, buttonConstraints);
  17. buttonConstraints.weightx = 0.2;
  18. buttonBox.add(sizeLabel, buttonConstraints);
  19. return buttonBox;
  20. }

相关文章

JButton类方法