List of usage examples for java.awt.event ActionListener ActionListener
ActionListener
From source file:teambootje.A2.java
public A2() { initComponents();/*from ww w. j a v a 2s . c o m*/ setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 2"); 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 Datum, COUNT(*) AS Aantal FROM posts GROUP BY Datum"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String datum = rs.getString("Datum"); int aantal = 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 dat = datum; int a1 = aantal; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue(dat, a1); pieDataset.setValue("2015-04-06", new Integer(5)); pieDataset.setValue("2015-04-05", new Integer(5)); pieDataset.setValue("2015-04-04", new Integer(14)); pieDataset.setValue("2015-04-03", new Integer(4)); pieDataset.setValue("2015-04-02", new Integer(1)); pieDataset.setValue("2015-04-01", new Integer(32)); pieDataset.setValue("2015-03-31", new Integer(32)); pieDataset.setValue("2015-03-30", new Integer(9)); pieDataset.setValue("2015-03-29", new Integer(4)); pieDataset.setValue("2015-03-28", new Integer(1)); pieDataset.setValue("2015-03-27", new Integer(3)); pieDataset.setValue("2015-03-26", new Integer(6)); pieDataset.setValue("2015-03-25", new Integer(1)); pieDataset.setValue("2015-03-24", new Integer(1)); pieDataset.setValue("2015-03-23", new Integer(1)); pieDataset.setValue("2015-03-22", new Integer(1)); pieDataset.setValue("2015-03-21", new Integer(1)); pieDataset.setValue("2015-03-20", new Integer(1)); pieDataset.setValue("2015-03-19", new Integer(1)); pieDataset.setValue("2015-03-18", new Integer(2)); pieDataset.setValue("2015-03-17", new Integer(1)); JFreeChart chart = ChartFactory.createPieChart3D("Aantal Posts per datum", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Aantal Posts per datum", 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[] = { "Datum", "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 ColorChooserEditor() { ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Color color = JColorChooser.showDialog(delegate, "Color Chooser", savedColor); ColorChooserEditor.this.changeColor(color); }//w w w.j a v a 2s .c o m }; delegate.addActionListener(actionListener); }
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); }/*from www .j a v a 2s.c o m*/ }; delegate.addActionListener(actionListener); addCellEditorListener(new CellEditorListener() { @Override public void editingCanceled(ChangeEvent e0) { System.out.println(e0); } @Override public void editingStopped(ChangeEvent e1) { System.out.println(e1); } }); }
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); }/*from w ww . ja va 2 s .com*/ }; delegate.addActionListener(actionListener); CellEditorListener lis = new CellEditorListener() { @Override public void editingCanceled(ChangeEvent e0) { System.out.println(e0); } @Override public void editingStopped(ChangeEvent e1) { System.out.println(e1); } }; addCellEditorListener(lis); removeCellEditorListener(lis); }
From source file:com.tag.Hyperlink.java
private void init() { setHorizontalAlignment(SwingConstants.LEFT); setBackground(Color.WHITE);/*from w w w. j a v a 2 s .c o m*/ setBorder(null); setBorderPainted(false); setOpaque(false); String toolTip = getUri().toString(); setToolTipText(toolTip); addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Desktop desktop = Desktop.getDesktop(); boolean mail = desktop.isSupported(Action.BROWSE); if (mail) { try { desktop.browse(uri); } catch (IOException ex) { ex.printStackTrace(); } } } }); }
From source file:ButtonScroll.java
public ButtonScroll() { super("Scrolling Programmatically"); setSize(400, 400);//from ww w . j a v a 2 s .com getContentPane().setLayout(new BorderLayout()); ImageIcon shuttle = new ImageIcon("largeJava2sLogo.GIF"); pgVertical = shuttle.getIconHeight() / 5; pgHorzontal = shuttle.getIconWidth() / 5; JLabel lbl = new JLabel(shuttle); viewport = new JViewport(); viewport.setView(lbl); viewport.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { enableButtons(ButtonScroll.this.viewport.getViewPosition()); } }); getContentPane().add(viewport, BorderLayout.CENTER); JPanel pv = new JPanel(new BorderLayout()); upButton = createButton("up", 'u'); ActionListener lst = new ActionListener() { public void actionPerformed(ActionEvent e) { movePanel(0, -1); } }; upButton.addActionListener(lst); pv.add(upButton, BorderLayout.NORTH); downButton = createButton("down", 'd'); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { movePanel(0, 1); } }; downButton.addActionListener(lst); pv.add(downButton, BorderLayout.SOUTH); getContentPane().add(pv, BorderLayout.EAST); JPanel ph = new JPanel(new BorderLayout()); leftButton = createButton("left", 'l'); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { movePanel(-1, 0); } }; leftButton.addActionListener(lst); ph.add(leftButton, BorderLayout.WEST); rightButton = createButton("right", 'r'); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { movePanel(1, 0); } }; rightButton.addActionListener(lst); ph.add(rightButton, BorderLayout.EAST); getContentPane().add(ph, BorderLayout.SOUTH); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); movePanel(0, 0); }
From source file:bazaar4idea.ui.BzrPullDialog.java
public BzrPullDialog(Project project) { super(project, false); this.project = project; hgRepositorySelector.setTitle("Select repository to pull changesets for"); hgRepositorySelector.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { onChangeRepository();// ww w. j a v a 2s .c om } }); DocumentListener documentListener = new DocumentListener() { public void insertUpdate(DocumentEvent e) { onChangePullSource(); } public void removeUpdate(DocumentEvent e) { onChangePullSource(); } public void changedUpdate(DocumentEvent e) { onChangePullSource(); } }; sourceTxt.getDocument().addDocumentListener(documentListener); setTitle("Pull"); init(); }
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); }/*from w w w .ja v a 2 s. co m*/ }; delegate.addActionListener(actionListener); CellEditorListener lis = new CellEditorListener() { @Override public void editingCanceled(ChangeEvent e0) { System.out.println(e0); } @Override public void editingStopped(ChangeEvent e1) { System.out.println(e1); } }; addCellEditorListener(lis); CellEditorListener[] listeners = getCellEditorListeners(); }
From source file:com.vrane.metaGlacier.gui.SNSTopicDialog.java
SNSTopicDialog() { super(Main.frame, true); JPanel mainPanel = new JPanel(new GridLayout(4, 2)); final JTextField topicNameJT = new JTextField(10); final JTextField emailJT = new JTextField(10); final JButton subscribeButton = new JButton("subscribe"); mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 5, 5, 5)); mainPanel.add(new JLabel("topic name")); mainPanel.add(topicNameJT);/*from w w w . j a v a 2s . com*/ mainPanel.add(new JLabel("email")); mainPanel.add(emailJT); final String metadata_account_email = Main.frame.getMPCUser(); if (metadata_account_email != null) { emailJT.setText(metadata_account_email); } mainPanel.add(new JLabel()); mainPanel.add(subscribeButton); subscribeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { final String email = emailJT.getText(); final String name = topicNameJT.getText(); boolean success = false; if (!EmailValidator.getInstance().isValid(email)) { JOptionPane.showMessageDialog(null, "Invalid email address"); return; } try { success = new SNSTopic().createTopic(name, email); } catch (Exception ex) { LGR.log(Level.SEVERE, null, ex); } if (success) { JOptionPane.showMessageDialog(null, "Please check your email to confirm"); dispose(); return; } JOptionPane.showMessageDialog(null, "Error subscribing"); } }); add(mainPanel); pack(); setLocationRelativeTo(Main.frame); setVisible(true); }