List of usage examples for java.awt.event ActionListener ActionListener
ActionListener
From source file:daylightchart.gui.actions.BaseBrowserAction.java
BaseBrowserAction(final String text, final String iconResource, final String shortcutKey, final String url) { super(text, iconResource); if (StringUtils.isNotBlank(shortcutKey)) { setShortcutKey(KeyStroke.getKeyStroke(shortcutKey)); }/*from ww w. ja va2 s.c o m*/ addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent actionevent) { BareBonesBrowserLaunch.openURL(url); } }); }
From source file:Main.java
public TestPane() { setLayout(new BorderLayout()); JPanel searchPane = new JPanel(); searchPane.add(new JLabel("Find: ")); searchPane.add(findText);//from w w w .ja v a 2s . c om add(searchPane, BorderLayout.NORTH); add(new JScrollPane(ta)); try (BufferedReader reader = new BufferedReader(new FileReader(new File("c:/Java_Dev/run.bat")))) { ta.read(reader, "Text"); } catch (Exception e) { e.printStackTrace(); } ta.setCaretPosition(0); keyTimer = new Timer(250, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String find = findText.getText(); Document document = ta.getDocument(); try { for (int index = 0; index + find.length() < document.getLength(); index++) { String match = document.getText(index, find.length()); if (find.equals(match)) { DefaultHighlighter.DefaultHighlightPainter highlightPainter = new DefaultHighlighter.DefaultHighlightPainter( Color.YELLOW); ta.getHighlighter().addHighlight(index, index + find.length(), highlightPainter); } } } catch (BadLocationException exp) { exp.printStackTrace(); } } }); keyTimer.setRepeats(false); findText.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { keyTimer.restart(); } @Override public void removeUpdate(DocumentEvent e) { keyTimer.restart(); } @Override public void changedUpdate(DocumentEvent e) { keyTimer.restart(); } }); }
From source file:DatabaseTest.java
public DatabaseTest() { super("Database Test Frame"); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(350, 200);/* w ww . ja va 2 s . c o m*/ qtm = new QueryTableModel(); JTable table = new JTable(qtm); JScrollPane scrollpane = new JScrollPane(table); JPanel p1 = new JPanel(); p1.setLayout(new GridLayout(3, 2)); p1.add(new JLabel("Enter the Host URL: ")); p1.add(hostField = new JTextField()); p1.add(new JLabel("Enter your query: ")); p1.add(queryField = new JTextField()); p1.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()); } }); p1.add(jb); getContentPane().add(p1, BorderLayout.NORTH); getContentPane().add(scrollpane, BorderLayout.CENTER); }
From source file:teambootje.A9.java
/** * Creates new form A9/*w w w . j a v a2s. c o m*/ */ public A9() { initComponents(); setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 9"); ImageIcon icon = new ImageIcon("img/bootje.jpg"); setIconImage(icon.getImage()); // back BTN JButton back = new JButton("Back"); add(back, BorderLayout.NORTH); back.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); // panel en Label JPanel ana = new JPanel(); add(ana, BorderLayout.CENTER); //tabel String sql = "SELECT persoon.Name, COUNT(post) AS Aantal FROM persoon, posts WHERE persoon.AID = posts.AID GROUP BY persoon.Name"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String name = rs.getString("persoon.Name"); int amount = rs.getInt("Aantal"); String[] row = new String[rs.getMetaData().getColumnCount()]; for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { row[i - 1] = rs.getString(i); } list.add(row); //chart JButton chart = new JButton("Chart"); add(chart, BorderLayout.SOUTH); chart.addActionListener(new ActionListener() { String n1 = name; int a1 = amount; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue(n1, a1); pieDataset.setValue("WestCordHotels", new Integer(1)); pieDataset.setValue("Voetbalr", new Integer(2)); pieDataset.setValue("VeraBauman", new Integer(1)); pieDataset.setValue("TonWesselink", new Integer(2)); pieDataset.setValue("Stoomschip Rotterdam", new Integer(25)); pieDataset.setValue("shirleys86", new Integer(2)); pieDataset.setValue("SevereWeather_N", new Integer(2)); pieDataset.setValue("SalvatoreOrtisi", new Integer(4)); pieDataset.setValue("RuudvEck", new Integer(2)); pieDataset.setValue("RuudvandenBos", new Integer(1)); pieDataset.setValue("Roffa85", new Integer(1)); pieDataset.setValue("RichardPh0t0", new Integer(2)); pieDataset.setValue("RebekkaKadijk", new Integer(2)); pieDataset.setValue("ray_rademaker", new Integer(6)); pieDataset.setValue("PoushNL", new Integer(1)); pieDataset.setValue("popupsquare", new Integer(2)); pieDataset.setValue("Plan_78", new Integer(3)); pieDataset.setValue("Petrahoogenboom", new Integer(1)); pieDataset.setValue("PatriciaBenard", new Integer(2)); pieDataset.setValue("OVKatendrecht", new Integer(2)); pieDataset.setValue("OdileHemmen", new Integer(2)); pieDataset.setValue("NLMaritiem", new Integer(2)); pieDataset.setValue("Nellyvdvlies", new Integer(1)); pieDataset.setValue("meerkatting", new Integer(2)); pieDataset.setValue("MeerkatsNow", new Integer(2)); pieDataset.setValue("marygoossens1", new Integer(1)); pieDataset.setValue("MarjoleinNagel", new Integer(1)); pieDataset.setValue("MaaikeMaasdijk", new Integer(1)); pieDataset.setValue("KidsErOpUit", new Integer(2)); pieDataset.setValue("Katendrechtnr1", new Integer(25)); pieDataset.setValue("jpsoree", new Integer(2)); pieDataset.setValue("JolandaBolscher", new Integer(2)); pieDataset.setValue("jes4life", new Integer(1)); pieDataset.setValue("JaccoScheer", new Integer(1)); pieDataset.setValue("GwNpop", new Integer(2)); pieDataset.setValue("Gerarddegraaff", new Integer(1)); pieDataset.setValue("FR12Patrick", new Integer(3)); pieDataset.setValue("FlorentinaNow", new Integer(1)); pieDataset.setValue("FIVBWorldChamps", new Integer(2)); pieDataset.setValue("FIVBVolleyball", new Integer(2)); pieDataset.setValue("FeestdjNik", new Integer(1)); pieDataset.setValue("ensanne", new Integer(1)); pieDataset.setValue("elsekramer", new Integer(1)); pieDataset.setValue("EelcoBeijl", new Integer(1)); pieDataset.setValue("EdwindeKoning1", new Integer(2)); pieDataset.setValue("DMiddelman", new Integer(3)); pieDataset.setValue("de_rotterdam", new Integer(2)); pieDataset.setValue("CvanAdrighem", new Integer(2)); pieDataset.setValue("carolinedejager", new Integer(1)); pieDataset.setValue("CaatVanEnst", new Integer(1)); pieDataset.setValue("BotlekBusiness", new Integer(2)); pieDataset.setValue("AnneWallisDeVri", new Integer(2)); pieDataset.setValue("010byday", new Integer(4)); JFreeChart chart = ChartFactory.createPieChart3D("Aantal posts per personen", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Aantal posts per personen", chart); pie.setVisible(true); pie.setSize(500, 500); pie.setLocationRelativeTo(null); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); } } catch (SQLException e) { JOptionPane.showMessageDialog(null, e); } Object[][] array = new Object[list.size()][]; Object columnNames[] = { "Naam", "Aantal" }; list.toArray(array); JTable table = new JTable(array, columnNames); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(400, 400)); ana.add(scroll); }
From source file:MainClass.java
public MainClass() { super("Selection Model Test"); setSize(450, 350);// w w w. j a v a 2 s . c o m setDefaultCloseOperation(EXIT_ON_CLOSE); TableModel tm = new AbstractTableModel() { public int getRowCount() { return 10; } public int getColumnCount() { return 10; } public Object getValueAt(int r, int c) { return "0"; } }; final JTable jt = new JTable(tm); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); JPanel controlPanel, buttonPanel, columnPanel, rowPanel; buttonPanel = new JPanel(); final JCheckBox cellBox, columnBox, rowBox; cellBox = new JCheckBox("Cells", jt.getCellSelectionEnabled()); columnBox = new JCheckBox("Columns", jt.getColumnSelectionAllowed()); rowBox = new JCheckBox("Rows", jt.getRowSelectionAllowed()); cellBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { jt.setCellSelectionEnabled(cellBox.isSelected()); columnBox.setSelected(jt.getColumnSelectionAllowed()); rowBox.setSelected(jt.getRowSelectionAllowed()); } }); columnBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { jt.setColumnSelectionAllowed(columnBox.isSelected()); cellBox.setSelected(jt.getCellSelectionEnabled()); } }); rowBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { jt.setRowSelectionAllowed(rowBox.isSelected()); cellBox.setSelected(jt.getCellSelectionEnabled()); } }); buttonPanel.add(new JLabel("Selections allowed:")); buttonPanel.add(cellBox); buttonPanel.add(columnBox); buttonPanel.add(rowBox); columnPanel = new JPanel(); ListSelectionModel csm = jt.getColumnModel().getSelectionModel(); JLabel columnCounter = new JLabel("Selected Column Indices:"); csm.addListSelectionListener(new SelectionDebugger(columnCounter, csm)); columnPanel.add(new JLabel("Selected columns:")); columnPanel.add(columnCounter); rowPanel = new JPanel(); ListSelectionModel rsm = jt.getSelectionModel(); JLabel rowCounter = new JLabel("Selected Row Indices:"); rsm.addListSelectionListener(new SelectionDebugger(rowCounter, rsm)); rowPanel.add(new JLabel("Selected rows:")); rowPanel.add(rowCounter); controlPanel = new JPanel(new GridLayout(0, 1)); controlPanel.add(buttonPanel); controlPanel.add(columnPanel); controlPanel.add(rowPanel); getContentPane().add(controlPanel, BorderLayout.SOUTH); }
From source file:UndoableToggleApp4.java
public UndoableToggleApp4() { SimpleListener sl = new SimpleListener(); tog.addActionListener(sl);//from w w w .ja v a 2 s . c om cb.addActionListener(sl); radio.addActionListener(sl); Box buttonBox = new Box(BoxLayout.Y_AXIS); buttonBox.add(tog); buttonBox.add(cb); buttonBox.add(radio); startButton.setEnabled(true); endButton.setEnabled(false); undoButton.setEnabled(false); redoButton.setEnabled(false); startButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { edit = new StateEdit(UndoableToggleApp4.this); startButton.setEnabled(false); endButton.setEnabled(true); // undoButton.setEnabled(edit.canUndo()); // // NOTE: We really don't want to be able to undo until end() is pressed, // but StateEdit does not enforce this for us! undoButton.setEnabled(false); redoButton.setEnabled(edit.canRedo()); } }); endButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { edit.end(); startButton.setEnabled(true); endButton.setEnabled(false); undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } }); // Add a listener to the undo button. It attempts to call undo() on the // current edit, then enables/disables the undo/redo buttons as appropriate. undoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.undo(); } catch (CannotUndoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); redoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.redo(); } catch (CannotRedoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); // Lay out the state/end and undo/redo buttons. Box undoRedoBox = new Box(BoxLayout.X_AXIS); undoRedoBox.add(Box.createGlue()); undoRedoBox.add(startButton); undoRedoBox.add(Box.createHorizontalStrut(2)); undoRedoBox.add(endButton); undoRedoBox.add(Box.createHorizontalStrut(2)); undoRedoBox.add(undoButton); undoRedoBox.add(Box.createHorizontalStrut(2)); undoRedoBox.add(redoButton); undoRedoBox.add(Box.createGlue()); // Lay out the main frame. Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(buttonBox, BorderLayout.CENTER); content.add(undoRedoBox, BorderLayout.SOUTH); setSize(400, 150); }
From source file:AccessoryFileChooser.java
public AccessoryFileChooser() { super("Accessory Test Frame"); setSize(350, 200);//from w ww .j av a 2 s. c om setDefaultCloseOperation(EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(new FlowLayout()); JButton accButton = new JButton("Accessory"); statusbar = new JLabel("Output of your selection will go here"); chooser = new JFileChooser(); AudioAccessory aa = new AudioAccessory(); chooser.setAccessory(aa); chooser.addPropertyChangeListener(aa); // to receive selection changes chooser.addActionListener(aa); // to receive approve/cancel button // events accButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { int option = chooser.showOpenDialog(AccessoryFileChooser.this); if (option == JFileChooser.APPROVE_OPTION) { statusbar.setText("You chose " + ((chooser.getSelectedFile() != null) ? chooser.getSelectedFile().getName() : "nothing")); } else { statusbar.setText("You canceled."); } } }); c.add(accButton); c.add(statusbar); }
From source file:Main.java
public Main() { setLayout(new GridLayout(ROWS, COLS)); for (int row = 0; row < grid.length; row++) { for (int col = 0; col < grid[row].length; col++) { JLabel label = new JLabel(); int index = random.nextInt(COLORS.length); label.setIcon(ICONS[index]); add(label);//from w w w . j a v a 2s. c o m grid[row][col] = label; } } new Timer(TIMER_DELAY, new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { for (int i = 0; i < NUMBER_TO_SWAP; i++) { int row = random.nextInt(ROWS); int col = random.nextInt(COLS); int iconIndex = random.nextInt(ICONS.length); grid[row][col].setIcon(ICONS[iconIndex]); } } }).start(); }
From source file:Main.java
public Main() { label = new JLabel("Waiting..."); frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(label);/*from ww w.j a v a2 s . c om*/ frame.setSize(200, 200); frame.setVisible(true); Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { int count; @Override public void eventDispatched(AWTEvent event) { Object source = event.getSource(); if (source instanceof Component) { Component comp = (Component) source; Window win = null; if (comp instanceof Window) { win = (Window) comp; } else { win = SwingUtilities.windowForComponent(comp); } if (win == frame) { timer.restart(); label.setText("Interrupted..." + (++count)); } } } }, AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK); timer = new Timer(5000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { frame.dispose(); } }); timer.start(); }
From source file:Main.java
public ColorChooserEditor() { ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Color color = JColorChooser.showDialog(delegate, "Color Chooser", savedColor); ColorChooserEditor.this.changeColor(color); }// w ww . j a v a 2s. co m }; }