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

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

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

AbstractButton.addActionListener介绍

暂无

代码示例

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

package experiments;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class CreateDialogFromOptionPane {

  public static void main(final String[] args) {
    final JFrame parent = new JFrame();
    JButton button = new JButton();

    button.setText("Click me to show dialog!");
    parent.add(button);
    parent.pack();
    parent.setVisible(true);

    button.addActionListener(new java.awt.event.ActionListener() {
      @Override
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        String name = JOptionPane.showInputDialog(parent,
            "What is your name?", null);
      }
    });
  }
}

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

gui.add(container, BorderLayout.CENTER);
container.add(tb, BorderLayout.NORTH);
for (int ii=0; ii<3; ii++) {
  tb.add(new JButton("Button"));
enable.addActionListener(new ActionListener(){
  @Override
  public void actionPerformed(ActionEvent ae) {

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

buttons.add( game );
buttons.add( highScores );
gui.add(buttons, BorderLayout.SOUTH);
game.addActionListener(al);
highScores.addActionListener(al);

代码示例来源:origin: org.netbeans.api/org-openide-dialogs

AbstractButton b = (AbstractButton) option;
removeOldListeners(b);
b.addActionListener(l);
JButton b = new JButton(text);

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

import java.awt.event.*;
import javax.swing.*;

public class YourDialog extends JDialog implements ActionListener {

 JButton button;

 public YourDialog() {
   button = new JButton("Close");
   button.addActionListener(this);
   add(button);
   pack();
   setVisible(true);
 }

 public void actionPerformed(ActionEvent e) {
   dispose();
 }
}

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

JFreeChart chart = createChart(dataset);
final JButton run = new JButton(STOP);
run.addActionListener(new ActionListener() {
btnPanel.add(run);
btnPanel.add(combo);
this.add(btnPanel, BorderLayout.SOUTH);

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

final JFrame frame = new JFrame("Nested Layout Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
plafComponents.add(plafChooser);
plafComponents.add(pack);
      SwingUtilities.updateComponentTreeUI(frame);
      if (pack.isSelected()) {
        frame.pack();
        frame.setMinimumSize(frame.getSize());
gui.add(plafComponents, BorderLayout.NORTH);
  new TitledBorder("GridLayout(0,2,3,3)") );
JButton addNew = new JButton("Add Another Label");
dynamicLabels.add( addNew, BorderLayout.NORTH );
addNew.addActionListener( new ActionListener(){
frame.pack();
frame.setVisible(true);

代码示例来源:origin: camunda/camunda-bpm-platform

public LogFactor5ErrorDialog(JFrame jframe, String message) {
 super(jframe, "Error", true);
 JButton ok = new JButton("Ok");
 ok.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
   hide();
  }
 });
 JPanel bottom = new JPanel();
 bottom.setLayout(new FlowLayout());
 bottom.add(ok);
 JPanel main = new JPanel();
 main.setLayout(new GridBagLayout());
 wrapStringOnPanel(message, main);
 getContentPane().add(main, BorderLayout.CENTER);
 getContentPane().add(bottom, BorderLayout.SOUTH);
 show();
}
//--------------------------------------------------------------------------

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

this.panel = new JPanel();
this.panel.setLayout(new FlowLayout());
add(panel, BorderLayout.CENTER);
JButton button = new JButton("CLICK HERE");
add(button, BorderLayout.SOUTH);
button.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 500);
setVisible(true);
this.panel.add(new JButton("Button"));
this.panel.revalidate();
validate();

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

private JButton copyButton = new JButton("Copy text from JTextFields");
private CopyTextControl2 control;
 copyButton.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
    if (control != null) {
 add(firstText);
 add(copyButton);

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

private JButton    m_multiplyBtn = new JButton("Multiply");
private JButton    m_clearBtn    = new JButton("Clear");
  content.add(new JLabel("Input"));
  content.add(m_userInputTf);
  content.add(m_multiplyBtn);
  content.add(new JLabel("Total"));
  content.add(m_totalTf);
  this.pack();
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  m_multiplyBtn.addActionListener(mal);
  m_clearBtn.addActionListener(cal);

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

final JScrollPane scroll = new JScrollPane(panel);
scroll.setPreferredSize(new Dimension(80,100));
gui.add(scroll, BorderLayout.CENTER);
JButton addLabel = new JButton("Add Label");
gui.add(addLabel, BorderLayout.NORTH);
ActionListener listener = new ActionListener() {
  int counter = 0;
  public void actionPerformed(ActionEvent ae) {
    panel.add(new JLabel("Label " + ++counter));
    panel.revalidate();
    int height = (int)panel.getPreferredSize().getHeight();
addLabel.addActionListener(listener);
JOptionPane.showMessageDialog(null, gui);

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

final JFrame frame = new JFrame();
final JTextField textFieldB = new HintTextField("Another hint here");
frame.add(textFieldA, BorderLayout.NORTH);
frame.add(textFieldB, BorderLayout.CENTER);
JButton btnGetText = new JButton("Get text");
btnGetText.addActionListener(new ActionListener() {
 @Override
 public void actionPerformed(ActionEvent e) {
frame.add(btnGetText, BorderLayout.SOUTH);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.pack();

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

JScrollPane scroll = new JScrollPane(panel);
scroll.setPreferredSize(new Dimension(80,100));
gui.add(scroll, BorderLayout.CENTER);
JButton addLabel = new JButton("Add Label");
gui.add(addLabel, BorderLayout.NORTH);
ActionListener listener = new ActionListener() {
  int counter = 0;
  public void actionPerformed(ActionEvent ae) {
    panel.add(new JLabel("Label " + ++counter));
    panel.revalidate();
    int height = (int)panel.getPreferredSize().getHeight();
addLabel.addActionListener(listener);
JOptionPane.showMessageDialog(null, gui);

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

JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
JButton saveBtn = new JButton("Save");
JButton openBtn = new JButton("Open");
saveBtn.addActionListener(new ActionListener() {
openBtn.addActionListener(new ActionListener() {
frame.add(new JLabel("File Chooser"), BorderLayout.NORTH);
frame.add(saveBtn, BorderLayout.CENTER);
frame.add(openBtn, BorderLayout.SOUTH);
frame.setTitle("File Chooser");
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);

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

JButton button = new JButton(new ImageIcon(icon));
      button.addActionListener(new ActionListener(){
        @Override
        public void actionPerformed(ActionEvent ae) {
      p.add(button);
    } else {
      JLabel label = new JLabel(new ImageIcon(icon));
      p.add(label);
center.add(p);
JOptionPane.showMessageDialog(null, center);

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

JFrame frame = new JFrame();
frame.setTitle("Welcome!");
frame.setSize(520, 480);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel heroShotPanel = new JPanel();
JLabel heroShot = new JLabel(heroShotImage);
heroShotPanel.add(heroShot);
JButton start = new JButton("Start");
start.setToolTipText("Click to use library");
start.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent e) {
submitPanel.add(start);
frame.getContentPane().add(heroShotPanel, BorderLayout.NORTH);
frame.getContentPane().add(submitPanel, BorderLayout.SOUTH);
frame.setVisible(true);
frame.getRootPane().setDefaultButton(start);
start.requestFocus();

代码示例来源:origin: camunda/camunda-bpm-platform

JButton newButton = new JButton("Clear Log Table");
newButton.addActionListener(
  new ActionListener() {
   public void actionPerformed(ActionEvent e) {
tb.add(new JLabel(" Font: "));
tb.add(fontCombo);
tb.add(fontSizeCombo);
tb.addSeparator();
tb.addSeparator();

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

Runnable r = new Runnable() {
 public void run() {
  final JFrame f = new JFrame("Test Screenshot");
    InputEvent.CTRL_DOWN_MASK
   ));
  screenshot.addActionListener(
   new ActionListener(){
    public void actionPerformed(ActionEvent ae) {
  p.add( new JScrollPane(new JTree()),
   BorderLayout.WEST );
  p.add( new JScrollPane( new JTextArea(HELP,10,30) ),
   BorderLayout.CENTER );
  f.pack();
  f.setLocationRelativeTo(null);
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  f.setVisible(true);

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

JButton next = new JButton(">");
next.addActionListener( new ActionListener(){
  public void actionPerformed(ActionEvent ae) {
    int height = table.getRowHeight()*(rows-1);
JButton previous = new JButton("<");
previous.addActionListener( new ActionListener(){
  public void actionPerformed(ActionEvent ae) {
    int height = table.getRowHeight()*(rows-1);
navigation.add(previous);
navigation.add(next);
gui.add(scrollPane, BorderLayout.CENTER);
gui.add(navigation, BorderLayout.SOUTH);

相关文章

微信公众号

最新文章

更多

AbstractButton类方法