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:TextEditFrame.java

public TextEditFrame() {
    setTitle("TextEditTest");
    setSize(500, 300);//  w  ww .  j  a va2s.  c o m
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    Container contentPane = getContentPane();

    JPanel panel = new JPanel();

    JButton replaceButton = new JButton("Replace");
    panel.add(replaceButton);
    replaceButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            String from = fromField.getText();
            int start = textArea.getText().indexOf(from);
            if (start >= 0 && from.length() > 0)
                textArea.replaceRange(toField.getText(), start, start + from.length());
        }
    });

    panel.add(fromField);

    panel.add(new JLabel("with"));

    panel.add(toField);

    contentPane.add(panel, "South");
    contentPane.add(scrollPane, "Center");
}

From source file:bankingclient.DKFrame.java

public DKFrame(MainFrame vmain) {
    initComponents();//from   w  w w  .java 2  s .  com
    this.main = vmain;
    this.jTextField1.setText("");
    this.jTextField2.setText("");
    this.jTextField3.setText("");
    this.jTextField4.setText("");
    this.jTextField5.setText("");
    this.setVisible(false);
    jButton1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (jTextField2.getText().equals(jTextField3.getText())
                    && NumberUtils.isNumber(jTextField4.getText())
                    && NumberUtils.isNumber(jTextField5.getText())) {
                try {
                    Socket client = new Socket("113.22.46.207", 6013);
                    String cusName = jTextField1.getText();
                    String pass = jTextField2.getText();
                    String sdt = jTextField4.getText();
                    String cmt = jTextField5.getText();
                    DataOutputStream dout = new DataOutputStream(client.getOutputStream());
                    dout.writeByte(1);
                    dout.writeUTF(cusName + "\n" + pass + "\n" + sdt + "\n" + cmt);
                    dout.flush();
                    DataInputStream din = new DataInputStream(client.getInputStream());
                    byte check = din.readByte();
                    if (check == 1) {
                        JOptionPane.showMessageDialog(rootPane, "da dang ki tai khoan thanh cong");
                    } else {
                        JOptionPane.showMessageDialog(rootPane, "dang ki tai khoan khong thanh cong");

                    }
                    client.close();
                } catch (Exception ee) {
                    ee.printStackTrace();
                }
                main.setVisible(true);
                DKFrame.this.setVisible(false);

            } else {
                JOptionPane.showMessageDialog(rootPane, "Nhap thong tin sai, moi nhap lai");
            }
        }
    });
    jButton2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            main.setVisible(true);
            DKFrame.this.setVisible(false);
        }
    });
}

From source file:Main.java

private JPanel createComboLabelPanel(int index, JComboBox<ComboColor> combo) {
    JPanel panel = new JPanel();
    JLabel label = new JLabel(SIGNAL + " " + index);
    label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    label.setOpaque(true);//  w  w w  .j  a  va  2  s  .c  o m
    combo.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            ComboColor cColor = (ComboColor) combo.getSelectedItem();
            label.setBackground(cColor.getColor());
        }
    });

    panel.add(label);
    panel.add(combo);
    return panel;
}

From source file:Main.java

public Main() {
    setSize(300, 300);//from  w  w w  .j  a va 2s.  c om
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JPanel controlPane = new JPanel(new GridLayout(2, 1));
    controlPane.setOpaque(false);
    controlPane.add(new JLabel("Please wait..."));
    controlPane.add(waiter);
    glass.setOpaque(false);
    glass.add(padding);
    glass.add(new JLabel());
    glass.add(controlPane);
    glass.add(new JLabel());
    glass.add(new JLabel());
    glass.setSize(new Dimension(300, 300));

    setGlassPane(glass);

    JButton startB = new JButton("Start!");

    startB.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent A) {
            glass.setVisible(true);
            padding.requestFocus();
        }
    });
    Container contentPane = getContentPane();
    contentPane.add(startB, BorderLayout.SOUTH);
}

From source file:Main.java

public ProgressBarFrame() {
    setSize(300, 300);/*from   w  w  w.j ava 2s .c o m*/
    JPanel panel = new JPanel();
    progressBar.setStringPainted(true);
    panel.add(startButton);
    panel.add(progressBar);
    checkBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            progressBar.setIndeterminate(checkBox.isSelected());
            progressBar.setStringPainted(!progressBar.isIndeterminate());
        }
    });
    panel.add(checkBox);
    add(new JScrollPane(textArea), BorderLayout.CENTER);
    add(panel, BorderLayout.SOUTH);
    startButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            startButton.setEnabled(false);
            activity = new SimulatedActivity(MAX);
            activity.execute();
        }
    });
}

From source file:PrinterSettingUpDialogPrint.java

public PrinterSettingUpDialogPrint() {
    getContentPane().add(canvas);/*from   ww w.  ja  v a  2  s  .c o m*/

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(1, 3));

    setUpButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent a) {
            setup();
        }
    });
    panel.add(setUpButton);
    printButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent a) {
            print();
        }
    });
    panel.add(printButton);
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent a) {
            cancel();
        }
    });
    panel.add(cancelButton);
    getContentPane().add(BorderLayout.SOUTH, panel);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 275);
    setVisible(true);
}

From source file:TabPanelwithImageIconCustom.java

public TabPanelwithImageIconCustom() {
    setSize(450, 350);//from ww  w  .  j a v a2s  . co m
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().add(textfield, BorderLayout.SOUTH);

    JMenuBar mbar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menu.add(new JCheckBoxMenuItem("Check Me"));
    menu.addSeparator();
    JMenuItem item = new JMenuItem("Exit");
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    menu.add(item);
    mbar.add(menu);
    setJMenuBar(mbar);

    JTabbedPane tabbedPane = new JTabbedPane();

    tabbedPane.addTab("Button", new TabIcon(), new JButton(""), "Click here for Button demo");
}

From source file:Test.java

public Test() {
    this.setBounds(100, 100, 200, 100);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createSoftBevelBorder(BevelBorder.LOWERED, Color.lightGray, Color.yellow));
    //panel.setBorder(BorderFactory.createSoftBevelBorder(BevelBorder.RAISED, 
    //  Color.lightGray, Color.yellow));
    //panel.setBorder(BorderFactory.createSoftBevelBorder(BevelBorder.LOWERED, 
    //  Color.lightGray, Color.lightGray, Color.white, Color.orange));

    this.setLayout(new FlowLayout());

    JButton exitButton = new JButton("Exit");
    panel.add(exitButton);//from  w  w w  .jav  a 2s.  com
    this.add(panel);

    exitButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });
}

From source file:Main.java

public BackgroundPane() {
    try {/*from www  .j  a v  a2  s .co  m*/
        bg = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    Timer timer = new Timer(40, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            yOffset += yDelta;
            if (yOffset > getHeight()) {
                yOffset = 0;
            }
            repaint();
        }
    });
    timer.start();
}

From source file:TDialog.java

protected JRootPane createRootPane() {
    ActionListener al = new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            hide();/* w w w  .ja  v  a  2 s  .c  om*/
            bCancel = true;
        }
    };

    KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    JRootPane rootPane = super.createRootPane();

    rootPane.registerKeyboardAction(al, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);

    return rootPane;
}