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

public URLMonitorPanel(String url, Timer t) throws MalformedURLException {
    setLayout(new BorderLayout());
    timer = t;//from ww w.j  ava2  s  .co  m
    this.url = new URL(url);
    add(new JLabel(url), BorderLayout.CENTER);
    JPanel temp = new JPanel();
    status = new JPanel();
    status.setSize(20, 20);
    temp.add(status);
    startButton = new JButton("Start");
    startButton.setEnabled(false);
    startButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            makeTask();
            startButton.setEnabled(false);
            stopButton.setEnabled(true);
        }
    });
    stopButton = new JButton("Stop");
    stopButton.setEnabled(true);
    stopButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            task.cancel();
            startButton.setEnabled(true);
            stopButton.setEnabled(false);
        }
    });
    temp.add(startButton);
    temp.add(stopButton);
    add(temp, BorderLayout.EAST);
    makeTask();
}

From source file:MessageDigestTest.java

public MessageDigestFrame() {
    setTitle("MessageDigestTest");
    setSize(400, 200);/*w ww .  jav  a  2s .c om*/
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    JPanel panel = new JPanel();
    ButtonGroup group = new ButtonGroup();
    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            JCheckBox b = (JCheckBox) event.getSource();
            setAlgorithm(b.getText());
        }
    };
    addCheckBox(panel, "SHA-1", group, true, listener);
    addCheckBox(panel, "MD5", group, false, listener);

    Container contentPane = getContentPane();

    contentPane.add(panel, "North");
    contentPane.add(new JScrollPane(message), "Center");
    contentPane.add(digest, "South");
    digest.setFont(new Font("Monospaced", Font.PLAIN, 12));

    setAlgorithm("SHA-1");

    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    JMenuItem fileDigestItem = new JMenuItem("File digest");
    fileDigestItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            loadFile();
        }
    });
    menu.add(fileDigestItem);
    JMenuItem textDigestItem = new JMenuItem("Text area digest");
    textDigestItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String m = message.getText();
            computeDigest(m.getBytes());
        }
    });
    menu.add(textDigestItem);
    menuBar.add(menu);
    setJMenuBar(menuBar);
}

From source file:FontPicker.java

public FontPicker() {
    super("JColorChooser Test Frame");
    setSize(200, 100);//  ww  w. ja v a  2  s .c o  m
    final JButton go = new JButton("Show FontChooser");
    go.addActionListener(new ActionListener() {
        final FontChooser chooser = new FontChooser(FontPicker.this);

        boolean first = true;

        public void actionPerformed(ActionEvent e) {
            chooser.setVisible(true);
            // If we got a real font choice, then update our go button
            if (chooser.getNewFont() != null) {
                go.setFont(chooser.getNewFont());
                go.setForeground(chooser.getNewColor());
            }
        }
    });
    getContentPane().add(go);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
}

From source file:MiniBrowser.java

public MiniBrowser() {
    setSize(640, 480);/*from w ww  . j  a v  a2  s  . c  o m*/
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel buttonPanel = new JPanel();
    backButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            actionBack();
        }
    });
    backButton.setEnabled(false);
    buttonPanel.add(backButton);
    forwardButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            actionForward();
        }
    });
    forwardButton.setEnabled(false);
    buttonPanel.add(forwardButton);
    locationTextField.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                actionGo();
            }
        }
    });
    buttonPanel.add(locationTextField);
    JButton goButton = new JButton("GO");
    goButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            actionGo();
        }
    });
    buttonPanel.add(goButton);
    displayEditorPane.setContentType("text/html");
    displayEditorPane.setEditable(false);
    displayEditorPane.addHyperlinkListener(this);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(buttonPanel, BorderLayout.NORTH);
    getContentPane().add(new JScrollPane(displayEditorPane), BorderLayout.CENTER);
}

From source file:NewFilterTable.java

public NewFilterTable() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    String[] columns = { "ID", "Des", "Date", "Fixed" };
    Object[][] rows = { { 1, "C", new Date(), new Date() }, { 2, "G", new Date(), new Date() },
            { 5, "F", new Date(), new Date() } };

    TableModel model = new DefaultTableModel(rows, columns);
    JTable table = new JTable(model);
    final TableRowSorter<TableModel> sorter;
    sorter = new TableRowSorter<TableModel>(model);
    table.setRowSorter(sorter);//from ww w .j a va 2 s.  co  m
    getContentPane().add(new JScrollPane(table));

    JPanel pnl = new JPanel();
    pnl.add(new JLabel("Filter expression:"));
    final JTextField txtFE = new JTextField(25);
    pnl.add(txtFE);
    JButton btnSetFE = new JButton("Set Filter Expression");
    ActionListener al;
    al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String expr = txtFE.getText();
            sorter.setRowFilter(RowFilter.regexFilter(expr));
            sorter.setSortKeys(null);
        }
    };
    btnSetFE.addActionListener(al);
    pnl.add(btnSetFE);
    getContentPane().add(pnl, BorderLayout.SOUTH);

    setSize(750, 150);
    setVisible(true);
}

From source file:MainClass.java

public MainClass() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(350, 200);//from   w ww.  j av  a2s .  co m

    JTable table = new JTable(qtm);
    JScrollPane scrollpane = new JScrollPane(table);
    JPanel commandPanel = new JPanel();
    commandPanel.setLayout(new GridLayout(3, 2));
    commandPanel.add(new JLabel("Enter the Host URL: "));
    commandPanel.add(hostField = new JTextField());
    commandPanel.add(new JLabel("Enter your query: "));
    commandPanel.add(queryField = new JTextField());
    commandPanel.add(new JLabel("Click here to send: "));

    JButton jb = new JButton("Search");
    jb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            qtm.setHostURL(hostField.getText().trim());
            qtm.setQuery(queryField.getText().trim());
        }
    });
    commandPanel.add(jb);
    getContentPane().add(commandPanel, BorderLayout.NORTH);
    getContentPane().add(scrollpane, BorderLayout.CENTER);
}

From source file:bankingclient.DNFrame.java

public DNFrame(MainFrame vmain) {

    initComponents();//from  ww w. j a  va 2  s .c o m

    this.jTextField1.setText("");
    this.jTextField2.setText("");
    this.jTextField_cmt.setText("");
    this.jTextField_sdt.setText("");

    this.main = vmain;
    noAcc = new NewOrOldAccFrame(this);
    this.setVisible(false);
    jL_sdt.setVisible(false);
    jL_cmtnd.setVisible(false);
    jTextField_cmt.setVisible(false);
    jTextField_sdt.setVisible(false);

    jBt_dn.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (!jCheck_qmk.isSelected()) {
                try {
                    Socket client = new Socket("113.22.46.207", 6013);
                    DataOutputStream dout = new DataOutputStream(client.getOutputStream());
                    dout.writeByte(2);
                    dout.writeUTF(jTextField1.getText() + "\n" + jTextField2.getText());
                    dout.flush();
                    while (true) {
                        break;
                    }
                    DataInputStream din = new DataInputStream(client.getInputStream());
                    byte check = din.readByte();
                    if (check == 1) {
                        noAcc.setVisible(true);
                        DNFrame.this.setVisible(false);
                        noAcc.setMainCustomer(jTextField1.getText());

                    } else {
                        JOptionPane.showMessageDialog(new JFrame(),
                                "Tn ?ang Nhp Khng Tn Ti, hoac mat khau sai");
                    }

                } catch (Exception ex) {
                    ex.printStackTrace();
                    JOptionPane.showMessageDialog(rootPane, "C Li Kt Ni Mng....");
                }
            } else if ((!jTextField_cmt.getText().equals("")) && (!jTextField_sdt.getText().equals(""))
                    && (NumberUtils.isNumber(jTextField_cmt.getText()))
                    && (NumberUtils.isNumber(jTextField_sdt.getText()))) {
                try {
                    Socket client = new Socket("113.22.46.207", 6013);
                    DataOutputStream dout = new DataOutputStream(client.getOutputStream());
                    dout.writeByte(9);
                    dout.writeUTF(jTextField1.getText() + "\n" + jTextField_sdt.getText() + "\n"
                            + jTextField_cmt.getText());
                    dout.flush();
                    DataInputStream din = new DataInputStream(client.getInputStream());
                    byte check = din.readByte();
                    if (check == 1) {
                        noAcc.setVisible(true);
                        DNFrame.this.setVisible(false);
                        noAcc.setMainCustomer(jTextField1.getText());
                    } else {
                        JOptionPane.showMessageDialog(new JFrame(), "Khong dang nhap duoc, thong tin sai");
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            } else {
                JOptionPane.showMessageDialog(new JFrame(), "Can dien day du thong tin va dung mau");
            }
        }
    });
    jBt_ql.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            main.setVisible(true);
            DNFrame.this.setVisible(false);
        }
    });
    jCheck_qmk.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (jCheck_qmk.isSelected()) {
                jL_sdt.setVisible(true);
                jL_cmtnd.setVisible(true);
                jTextField_cmt.setVisible(true);
                jTextField_sdt.setVisible(true);
            } else {
                jL_sdt.setVisible(false);
                jL_cmtnd.setVisible(false);
                jTextField_cmt.setVisible(false);
                jTextField_sdt.setVisible(false);
            }
        }
    });
}

From source file:Main.java

void addTab() {
    JEditorPane ep = new JEditorPane();
    ep.setEditable(false);/* w ww.j a va2  s. co m*/
    tp.addTab(null, new JScrollPane(ep));

    JButton tabCloseButton = new JButton("Close");
    tabCloseButton.setActionCommand("" + tabCounter);

    ActionListener al;
    al = new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            JButton btn = (JButton) ae.getSource();
            String s1 = btn.getActionCommand();
            for (int i = 1; i < tp.getTabCount(); i++) {
                JPanel pnl = (JPanel) tp.getTabComponentAt(i);
                btn = (JButton) pnl.getComponent(0);
                String s2 = btn.getActionCommand();
                if (s1.equals(s2)) {
                    tp.removeTabAt(i);
                    break;
                }
            }
        }
    };
    tabCloseButton.addActionListener(al);

    if (tabCounter != 0) {
        JPanel pnl = new JPanel();
        pnl.setOpaque(false);
        pnl.add(tabCloseButton);
        tp.setTabComponentAt(tp.getTabCount() - 1, pnl);
        tp.setSelectedIndex(tp.getTabCount() - 1);
    }

    tabCounter++;
}

From source file:IsEDTExample.java

public IsEDTExample() {
    JTable table = new JTable(tableModel);
    table.setRowHeight(100);/*  w  w  w  .j a v  a  2 s . co m*/
    table.setDefaultRenderer(Object.class, new ColorRenderer());
    add(table);

    add(new JLabel("Thread Color Shade:"));
    ButtonGroup group = new ButtonGroup();
    JRadioButton redOption = new JRadioButton("Red");
    group.add(redOption);
    redOption.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            threadShade = RED;
        }
    });

    JRadioButton blueOption = new JRadioButton("Blue");
    group.add(blueOption);
    blueOption.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            threadShade = BLUE;
        }
    });

    JRadioButton greenOption = new JRadioButton("Green");
    group.add(greenOption);
    greenOption.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            threadShade = GREEN;
        }
    });

    redOption.setSelected(true);
    this.threadShade = RED;

    add(redOption);
    add(greenOption);
    add(blueOption);

    add(new JButton(new RandomColorAction()));

    this.keepRunning = true;
    this.colorShadeThread = new Thread(new RandomColorShadeRunnable());
    this.colorShadeThread.start();
}

From source file:ColorChooserMenu.java

protected JMenuBar createMenuBar() {
    final JMenuBar menuBar = new JMenuBar();

    ColorMenu cm = new ColorMenu("Foreground");
    cm.setMnemonic('f');
    ActionListener lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ColorMenu m = (ColorMenu) e.getSource();
            System.out.println(m.getColor());
        }//from w w  w . ja va2 s.c  o m
    };
    cm.addActionListener(lst);
    menuBar.add(cm);

    return menuBar;
}