Example usage for java.awt.event ActionListener ActionListener

List of usage examples for java.awt.event ActionListener ActionListener

Introduction

In this page you can find the example usage for java.awt.event ActionListener ActionListener.

Prototype

ActionListener

Source Link

Usage

From source file:ComboBoxes.java

public void init() {
    for (int i = 0; i < 4; i++)
        c.addItem(description[count++]);
    t.setEditable(false);//from   w  ww. j av a  2 s .  co  m
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (count < description.length)
                c.addItem(description[count++]);
        }
    });
    c.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            t.setText("index: " + c.getSelectedIndex() + "   " + ((JComboBox) e.getSource()).getSelectedItem());
        }
    });
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(t);
    cp.add(c);
    cp.add(b);
}

From source file:MainClass.java

public MainClass() {
    super();//from   w  w  w .  j av a2  s  . com
    JToolBar urlToolBar = new JToolBar();
    mURLField = new JTextField(40);
    urlToolBar.add(new JLabel("Location:"));
    urlToolBar.add(mURLField);
    frame.add(urlToolBar, BorderLayout.NORTH);

    mEditorPane = new JEditorPane();
    mEditorPane.setEditable(false);
    frame.add(new JScrollPane(mEditorPane), BorderLayout.CENTER);

    openURL("http://www.java2s.com");

    mURLField.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            openURL(ae.getActionCommand());
        }
    });

    mEditorPane.addHyperlinkListener(new LinkActivator());

    setSize(500, 600);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:JDK6SplashTest.java

public JDK6SplashTest() {
    super("SplashScreen demo");
    setSize(500, 300);/*from  w  ww .j a va2  s.  c om*/
    setLayout(new BorderLayout());
    Menu m1 = new Menu("File");
    MenuItem mi1 = new MenuItem("Exit");
    m1.add(mi1);
    mi1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }

    });

    MenuBar mb = new MenuBar();
    setMenuBar(mb);
    mb.add(m1);
    final SplashScreen splash = SplashScreen.getSplashScreen();
    if (splash == null) {
        System.out.println("SplashScreen.getSplashScreen() returned null");
        return;
    }
    Graphics2D g = (Graphics2D) splash.createGraphics();
    if (g == null) {
        System.out.println("g is null");
        return;
    }
    for (int i = 0; i < 100; i++) {
        renderSplashFrame(g, i);
        splash.update();
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
        }
    }
    splash.close();
    setVisible(true);
    toFront();
}

From source file:EspectroForm.java

/**
 * Creates new form EspectroForm// w w  w. j  av a2s .  c om
 */
public EspectroForm(HashMap<Double, Double> espectro) {
    initComponents();
    setIconImage(ChartTest.createImage().getImage());
    setTitle("Modulacin Angular: Espectro de Frecuencia");
    initChart(espectro);
    initPanel();
    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    okButton.addActionListener(new ActionListener() {

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

}

From source file:EscapeDialog.java

protected JRootPane createRootPane() {
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            setVisible(false);/*from  w  ww.ja v a  2  s  .  com*/
        }
    };
    JRootPane rootPane = new JRootPane();
    KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    rootPane.registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
    return rootPane;
}

From source file:ActionDisabled.java

public ActionDisabled() {
    this.setJMenuBar(menuBar);
    menuBar.add(testMenu);//from   ww  w. ja  v  a  2s  .  c o m

    testMenu.add(theAction);
    toolBar.add(theAction);

    disableActionItem.setActionCommand(DISABLE);
    testMenu.add(disableActionItem);
    disableActionItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals(DISABLE)) {
                theAction.setEnabled(false);
                disableActionItem.setText("Enable the Action");
                disableActionItem.setActionCommand(ENABLE);
            } else {
                theAction.setEnabled(true);
                disableActionItem.setText("Disable the Action");
                disableActionItem.setActionCommand(DISABLE);
            }
        }
    });
    this.getContentPane().add(toolBar, BorderLayout.NORTH);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.getContentPane().setBackground(Color.red);
    this.setSize(320, 200);
    this.setVisible(true);
}

From source file:ClipArea.java

public ClipArea() {
    super();//from  ww w  .  j  a  v  a  2 s.  c  o  m
    Container contentPane = getContentPane();

    canvas = new MyCanvas();
    contentPane.add(canvas);

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(1, 2));
    clipButton = new JRadioButton("Clip", true);
    clipButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            canvas.clip = true;
            canvas.clipFurther = false;
            canvas.repaint();
        }
    });
    clipFurButton = new JRadioButton("Clip Further");
    clipFurButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            canvas.clipFurther = true;
            canvas.repaint();
        }
    });
    ButtonGroup group = new ButtonGroup();
    group.add(clipButton);
    group.add(clipFurButton);

    panel.add(clipButton);
    panel.add(clipFurButton);
    contentPane.add(BorderLayout.SOUTH, panel);

    // 4. Add a window listener to close the frame properly.
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    pack();
    setVisible(true);
}

From source file:MyFilterChooser.java

public MyFilterChooser() {
    super("Filter Test Frame");
    setSize(350, 200);/*from ww  w .  j a  v a2  s .c  o  m*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container c = getContentPane();
    c.setLayout(new FlowLayout());

    JButton openButton = new JButton("Open");
    final JLabel statusbar = new JLabel("Output of your selection will go here");

    openButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            String[] pics = new String[] { "gif", "jpg", "tif" };
            String[] audios = new String[] { "au", "aiff", "wav" };
            JFileChooser chooser = new JFileChooser();
            chooser.addChoosableFileFilter(new SimpleFileFilter(pics, "Images (*.gif, *.jpg, *.tif)"));
            chooser.addChoosableFileFilter(new SimpleFileFilter(".MOV"));
            chooser.addChoosableFileFilter(new SimpleFileFilter(audios, "Sounds (*.aiff, *.au, *.wav)"));
            int option = chooser.showOpenDialog(MyFilterChooser.this);
            if (option == JFileChooser.APPROVE_OPTION) {
                if (chooser.getSelectedFile() != null)
                    statusbar.setText("You chose " + chooser.getSelectedFile().getName());
            } else {
                statusbar.setText("You canceled.");
            }
        }
    });

    c.add(openButton);
    c.add(statusbar);
    setVisible(true);
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container pane = getContentPane();
    GroupLayout gl = new GroupLayout(pane);
    pane.setLayout(gl);//from  ww w .  j  ava 2 s . co  m

    gl.setAutoCreateGaps(true);
    gl.setAutoCreateContainerGaps(true);

    JButton btn = new JButton("Switch");
    btn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (int i = 1; i < 9; i++) {
                labels[i].setVisible(!labels[i].isVisible());
            }
        }
    });

    gl.setHonorsVisibility(false);

    SequentialGroup seqGroup = gl.createSequentialGroup();
    gl.setHorizontalGroup(seqGroup);
    seqGroup.addComponent(btn);
    seqGroup.addPreferredGap(ComponentPlacement.UNRELATED, 10, 10);
    for (int i = 0; i < 10; i++) {
        seqGroup.addComponent(labels[i]);
        seqGroup.addPreferredGap(ComponentPlacement.UNRELATED, 10, 10);
    }
    ParallelGroup parGroup = gl.createParallelGroup();
    gl.setVerticalGroup(parGroup);
    parGroup.addComponent(btn);

    for (int i = 0; i < 10; i++) {
        parGroup.addComponent(labels[i]);
    }
    pack();
}

From source file:Main.java

public Main() {
    setLayout(new BorderLayout());
    model = new DefaultListModel();
    list = new JList(model);
    JScrollPane pane = new JScrollPane(list);
    JButton addButton = new JButton("Add Element");
    JButton removeButton = new JButton("Remove Element");
    for (int i = 0; i < 15; i++)
        model.addElement("Element " + i);

    addButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            model.addElement("Element " + counter);
            counter++;/*from   ww  w . ja  va 2 s .  co m*/
        }
    });
    removeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (model.getSize() > 0)
                model.removeElementAt(0);
        }
    });

    add(pane, BorderLayout.NORTH);
    add(addButton, BorderLayout.WEST);
    add(removeButton, BorderLayout.EAST);
}