List of usage examples for java.awt.event ActionListener ActionListener
ActionListener
From source file:AlphaCompositeDemo.java
public AlphaCompositeDemo() { super();/*w ww.j a v a 2s. c om*/ Container container = getContentPane(); canvas = new MyCanvas(); container.add(canvas); rulesBox = new JComboBox(rulesLabels); rulesBox.setSelectedIndex(0); rulesBox.setAlignmentX(Component.LEFT_ALIGNMENT); rulesBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox cb = (JComboBox) e.getSource(); canvas.compositeRule = rules[cb.getSelectedIndex()]; canvas.repaint(); } }); slider.setPaintTicks(true); slider.setMajorTickSpacing(25); slider.setMinorTickSpacing(25); slider.setPaintLabels(true); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider slider = (JSlider) e.getSource(); canvas.alphaValue = (float) slider.getValue() / 100; canvas.repaint(); } }); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(1, 3)); panel.add(rulesBox); panel.add(new JLabel("Alpha Adjustment x E-2: ", JLabel.RIGHT)); panel.add(slider); container.add(panel, BorderLayout.SOUTH); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setSize(500, 300); setVisible(true); }
From source file:teambootje.A7.java
/** * Creates new form A7/* ww w . j av a2 s . c o m*/ */ public A7() { initComponents(); setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 7"); 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 doelgroep.doelgroep, COUNT(*) AS Aantal FROM doelgroep GROUP BY doelgroep.doelgroep"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String ta = rs.getString("doelgroep.Doelgroep"); 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 dd = ta; int a1 = amount; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue(dd, a1); pieDataset.setValue("Bedrijfsleven", new Integer(1)); pieDataset.setValue("50+", new Integer(1)); pieDataset.setValue("40+", new Integer(1)); pieDataset.setValue("30+", new Integer(1)); JFreeChart chart = ChartFactory.createPieChart3D("Aantal mensen per Doelgroep", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Aantal mensen per Doelgroep", 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[] = { "Doelgroep", "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:teambootje.A8.java
/** * Creates new form A8//from w w w. ja v a2s. c om */ public A8() { initComponents(); setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 8"); 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 doelgroep.Doelgroep, COUNT(posts.post) AS Aantal FROM doelgroep, posts WHERE posts.DID = doelgroep.DID GROUP BY doelgroep.Doelgroep"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String ta = rs.getString("doelgroep.Doelgroep"); 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 dd = ta; int a1 = amount; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue(dd, a1); pieDataset.setValue("50+", new Integer(0)); pieDataset.setValue("Tiener", new Integer(0)); pieDataset.setValue("40+", new Integer(0)); pieDataset.setValue("30+", new Integer(0)); JFreeChart chart = ChartFactory.createPieChart3D("Aantal Posts per doelgroep", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Aantal Posts per doelgroep", 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[] = { "Doelgoep", "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:dataform.components.WorkTimer.java
private void init() throws Exception { stopWatch = new StopWatch(); setEditable(false);/* w w w .ja va 2s .com*/ setForeground(Color.RED); setHorizontalAlignment(JLabel.RIGHT); setMargin(new Insets(2, 2, 2, 4)); timer = new javax.swing.Timer(ONE_SECOND, new ActionListener() { public void actionPerformed(ActionEvent evt) { timer_ActionPerformed(evt); } }); stopWatch.start(); timer.start(); }
From source file:FactoryDemo.java
public static JPanel demo2() { // Demo 2: Change the format of a field when the user presses a button. // We can't call field.setFormatter() because that's a protected method. // (Plus it wouldn't work anyway. The old factory would replace our new // formatter with an "old" one next time the field gains or loses // focus.)/* w ww . j av a 2 s .c o m*/ // The thing to do is send a new factory to field.setFormatterFactory(). JPanel pan = new JPanel(new BorderLayout()); pan.setBorder(new TitledBorder("Demo 2: change format midstream")); MaskFormatter lowercase = null; try { lowercase = new MaskFormatter("LLLL"); } catch (ParseException pe) { } final JFormattedTextField field = new JFormattedTextField(lowercase); field.setValue("Fore"); pan.add(field, BorderLayout.CENTER); final JButton change = new JButton("change format"); JPanel changePanel = new JPanel(); changePanel.add(change); pan.add(changePanel, BorderLayout.SOUTH); change.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { try { field.commitEdit(); // commit current edit (if any) MaskFormatter uppercase = new MaskFormatter("UUUU"); DefaultFormatterFactory factory = new DefaultFormatterFactory(uppercase); field.setFormatterFactory(factory); change.setEnabled(false); } catch (ParseException pe) { } } }); return pan; }
From source file:Main.java
public Main() { DefaultMutableTreeNode forums = new DefaultMutableTreeNode("B"); forums.add(new DefaultMutableTreeNode("T")); DefaultMutableTreeNode articles = new DefaultMutableTreeNode("A"); articles.add(new DefaultMutableTreeNode("A")); DefaultMutableTreeNode examples = new DefaultMutableTreeNode("E"); examples.add(new DefaultMutableTreeNode("E")); rootNode.add(forums);/*from ww w. j a v a 2 s . c o m*/ rootNode.add(articles); rootNode.add(examples); m_tree.setEditable(true); m_tree.setSelectionRow(0); JScrollPane scrollPane = new JScrollPane(m_tree); getContentPane().add(scrollPane, BorderLayout.CENTER); JPanel panel = new JPanel(); m_addButton = new JButton("Add Node"); m_addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { DefaultMutableTreeNode selNode = (DefaultMutableTreeNode) m_tree.getLastSelectedPathComponent(); if (selNode == null) { return; } DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("New"); m_model.insertNodeInto(newNode, selNode, selNode.getChildCount()); TreeNode[] nodes = m_model.getPathToRoot(newNode); TreePath path = new TreePath(nodes); m_tree.scrollPathToVisible(path); m_tree.setSelectionPath(path); m_tree.startEditingAtPath(path); } }); panel.add(m_addButton); getContentPane().add(panel, BorderLayout.SOUTH); m_delButton = new JButton("Delete Node"); m_delButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { DefaultMutableTreeNode selNode = (DefaultMutableTreeNode) m_tree.getLastSelectedPathComponent(); if (selNode == null) { return; } MutableTreeNode parent = (MutableTreeNode) (selNode.getParent()); if (parent == null) { return; } MutableTreeNode toBeSelNode = (MutableTreeNode) selNode.getPreviousSibling(); if (toBeSelNode == null) { toBeSelNode = (MutableTreeNode) selNode.getNextSibling(); } if (toBeSelNode == null) { toBeSelNode = parent; } TreeNode[] nodes = m_model.getPathToRoot(toBeSelNode); TreePath path = new TreePath(nodes); m_tree.scrollPathToVisible(path); m_tree.setSelectionPath(path); m_model.removeNodeFromParent(selNode); } }); panel.add(m_delButton); getContentPane().add(panel, BorderLayout.SOUTH); setSize(300, 400); setVisible(true); }
From source file:ExecDemoNS.java
/** Constructor - set up strings and things. */ public ExecDemoNS(String prog) { super("ExecDemo: " + prog); String osname = System.getProperty("os.name"); if (osname == null) throw new IllegalArgumentException("no os.name"); if (prog.equals("netscape")) program = // Windows or UNIX only for now, sorry Mac fans (osname.toLowerCase().indexOf("windows") != -1) ? "c:/program files/netscape/communicator/program/netscape.exe" : "/usr/local/netscape/netscape"; else//from ww w . j a v a2 s . com program = prog; Container cp = getContentPane(); cp.setLayout(new FlowLayout()); JButton b; cp.add(b = new JButton("Exec")); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { runProg(); } }); cp.add(b = new JButton("Wait")); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { doWait(); } }); cp.add(b = new JButton("Exit")); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.exit(0); } }); pack(); }
From source file:com.joey.software.memoryToolkit.MemoryUsagePanel.java
public static JFrame getMemoryUsagePanel(int dataNum, int delay) { final MemoryUsagePanel u = new MemoryUsagePanel(dataNum, delay); JFrame f = new JFrame("Memory Usage"); f.setLayout(new BorderLayout()); f.getContentPane().add(u, BorderLayout.CENTER); f.setSize(800, 400);//from w w w . jav a 2s. c om f.setVisible(true); final JButton runButton = new JButton("Start"); runButton.addActionListener(new ActionListener() { boolean running = false; @Override public void actionPerformed(ActionEvent e) { if (running) { running = false; u.stopUpdating(); runButton.setText("Start"); } else { running = true; u.startUpdating(); runButton.setText("Stop"); } } }); JButton garbage = new JButton("Run GC"); garbage.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.gc(); } }); JPanel temp = new JPanel(new GridLayout(1, 1)); temp.add(runButton); temp.add(garbage); f.getContentPane().add(temp, BorderLayout.SOUTH); return f; }
From source file:com.willowtreeapps.respeeker.idea.ResPeekerTools.java
public ResPeekerTools() { navigateToLayoutButton.addActionListener(new ActionListener() { @Override/*www . ja va 2 s .c om*/ public void actionPerformed(ActionEvent e) { navigate(); } }); deviceCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { DeviceItem deviceItem = getSelectedDeviceItem(); updateLayoutInfo(deviceItem == null ? null : deviceItem.layoutInfo); updateConfigInfo(deviceItem == null ? null : deviceItem.configInfo); } }); }
From source file:Java2DExample.java
public Java2DExample() { super("Java 2D Image Processing Demo"); imagePanel = new ImagePanel(Java2DExample.class.getResource("yourImage.png")); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar);//from w w w. j a v a2 s. com filterMenu.setMnemonic('I'); JMenuItem originalMenuItem = new JMenuItem("Display Original"); originalMenuItem.setMnemonic('O'); originalMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent action) { imagePanel.displayOriginalImage(); } }); JMenuItem invertMenuItem = createMenuItem("Invert", 'I', invertFilter); JMenuItem sharpenMenuItem = createMenuItem("Sharpen", 'S', sharpenFilter); JMenuItem blurMenuItem = createMenuItem("Blur", 'B', blurFilter); JMenuItem changeColorsMenuItem = createMenuItem("Change Colors", 'C', colorFilter); filterMenu.add(originalMenuItem); filterMenu.add(invertMenuItem); filterMenu.add(sharpenMenuItem); filterMenu.add(blurMenuItem); filterMenu.add(changeColorsMenuItem); menuBar.add(filterMenu); getContentPane().add(imagePanel, BorderLayout.CENTER); }