List of usage examples for java.awt.event ActionListener ActionListener
ActionListener
From source file:MainClass.java
public MainClass() { JFrame frame = new JFrame(); textPane = new JTextPane(); JScrollPane scrollPane = new JScrollPane(textPane); JPanel north = new JPanel(); JButton print = new JButton("Print"); print.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { paintToPDF(textPane);//from ww w .j av a 2 s .c o m } }); JMenuBar menu = new JMenuBar(); JMenu styleMenu = new JMenu(); styleMenu.setText("Style"); Action boldAction = new BoldAction(); boldAction.putValue(Action.NAME, "Bold"); styleMenu.add(boldAction); Action italicAction = new ItalicAction(); italicAction.putValue(Action.NAME, "Italic"); styleMenu.add(italicAction); menu.add(styleMenu); north.add(menu); north.add(print); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(north, BorderLayout.NORTH); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(800, 500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:MultiKeyCombo.java
public MultiKeySelectionManager() { resetTimer = new Timer(RESET_DELAY, new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { currentSearch.setLength(0);// w ww . j a v a2s.c om } }); }
From source file:teambootje.A1.java
public A1() { initComponents();/*from w w w.j av a 2 s .c o m*/ setLocationRelativeTo(null); setLayout(new BorderLayout()); setSize(500, 500); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 1"); 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 JPanel ana = new JPanel(); add(ana, BorderLayout.CENTER); //tabel String nvt = "SELECT Geslacht, COUNT(*) AS Aantal FROM persoon GROUP BY geslacht"; String male = "SELECT Geslacht AS male, COUNT(*) AS Aantal_Male FROM persoon WHERE Geslacht = 'man'"; String Female = "SELECT Geslacht AS female, COUNT(*) AS Aantal_Female FROM persoon WHERE Geslacht = 'vrouw'"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(nvt); while (rs.next()) { String geslacht = rs.getString("Geslacht"); 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); try { rs = db.runSql(male); while (rs.next()) { String man = rs.getString("male"); int am = rs.getInt("Aantal_Male"); String[] row1 = new String[rs.getMetaData().getColumnCount()]; for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { row1[i - 1] = rs.getString(i); } try { rs = db.runSql(Female); while (rs.next()) { String vrouw = rs.getString("female"); int af = rs.getInt("Aantal_Female"); String[] row2 = new String[rs.getMetaData().getColumnCount()]; for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { row2[i - 1] = rs.getString(i); } Object[][] array = new Object[list.size()][]; Object columnNames[] = { "Geslacht", "Aantal" }; list.toArray(array); JTable table = new JTable(array, columnNames); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(400, 400)); ana.add(scroll); //chart JButton chart = new JButton("Chart"); add(chart, BorderLayout.SOUTH); chart.addActionListener(new ActionListener() { String g1 = geslacht; String m = man; String v = vrouw; int a1 = aantal; int a2 = am; int a3 = af; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("Niet vrij gegeven", a1); pieDataset.setValue("Man", a2); pieDataset.setValue("vrouw", a3); JFreeChart chart = ChartFactory.createPieChart3D("Aantal mannen en vrouwen", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Aantal mannen en vrouwen", 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 v) { JOptionPane.showMessageDialog(null, v); } } } catch (SQLException m) { JOptionPane.showMessageDialog(null, m); } } } catch (SQLException e) { JOptionPane.showMessageDialog(null, e); } }
From source file:customize.swing.startMain.java
public startMain() { initComponents();//from w ww .j a v a 2 s. c om initComponents(); jfc.setCurrentDirectory(new File("d://"));// ?d genButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // String text = TextField.getText(); //? String text1 = textField3.getText(); if (StringUtils.isBlank(text)) { JOptionPane.showMessageDialog(null, "??!!"); return; } if (StringUtils.isBlank(text1)) { JOptionPane.showMessageDialog(null, "??!!"); return; } if (StringUtils.isBlank(rootTextField.getText())) { JOptionPane.showMessageDialog(null, "???!!"); return; } if (StringUtils.isBlank(PasswordField.getText())) { JOptionPane.showMessageDialog(null, "??!!"); return; } if (StringUtils.isBlank(textField8.getText())) { JOptionPane.showMessageDialog(null, "???!!"); return; } if (StringUtils.isBlank(textField2.getText())) { JOptionPane.showMessageDialog(null, "?!!"); return; } String xml = ""; String model = ""; String dao = ""; xml = textField6.getText(); model = textField7.getText(); dao = textField1.getText(); if (StringUtils.isBlank(xml)) { xml = "./"; } if (StringUtils.isBlank(model)) { model = "./"; } if (StringUtils.isBlank(dao)) { dao = "./"; } RequestModel requestModel = new RequestModel(); requestModel.setDriverClass(text); requestModel.setConnectionURL(text1); requestModel.setUserId(rootTextField.getText()); requestModel.setPassword(PasswordField.getText()); requestModel.setTableName(textField8.getText()); requestModel.setProjectPath(textField2.getText()); requestModel.setXmlPackage(xml); requestModel.setModelPackage(model); requestModel.setInterfacePackage(dao); if (CheckBox1.isSelected()) { requestModel.setUseActualColumnNames(false); } if (!CheckBox2.isSelected()) { requestModel.setSuppressAllComments(false); } GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap(); try { generatorSqlmap.generator(requestModel); JOptionPane.showMessageDialog(null, "?~"); File file = new File(textField2.getText()); java.awt.Desktop.getDesktop().open(file.getParentFile()); } catch (Exception e1) { JOptionPane.showMessageDialog(null, "~ :" + e1.getMessage()); e1.printStackTrace(); } } }); ButtonView.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource().equals(ButtonView)) {// ? setTextValue(textField2); } } }); }
From source file:com.mirth.connect.client.ui.ChannelTagDialog.java
protected JRootPane createRootPane() { JRootPane rootPane = new JRootPane(); KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); rootPane.registerKeyboardAction(new ActionListener() { @Override//w w w.j av a 2 s. c o m public void actionPerformed(ActionEvent e) { addButtonActionPerformed(null); } }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); return rootPane; }
From source file:UndoableToggleApp2.java
public UndoableToggleApp2() { JToggleButton tog = new JToggleButton("ToggleButton"); JCheckBox cb = new JCheckBox("CompoundEdit ExampleCheckBox"); JRadioButton radio = new JRadioButton("RadioButton"); SimpleListener sl = new SimpleListener(); tog.addActionListener(sl);//ww w. j a 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); undoButton.setEnabled(false); redoButton.setEnabled(false); endButton.setEnabled(false); 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()); } } }); endButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { edit.end(); endButton.setEnabled(false); undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } }); Box undoRedoEndBox = new Box(BoxLayout.X_AXIS); undoRedoEndBox.add(Box.createGlue()); undoRedoEndBox.add(undoButton); undoRedoEndBox.add(Box.createHorizontalStrut(2)); undoRedoEndBox.add(redoButton); undoRedoEndBox.add(Box.createHorizontalStrut(2)); undoRedoEndBox.add(endButton); undoRedoEndBox.add(Box.createGlue()); Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(buttonBox, BorderLayout.CENTER); content.add(undoRedoEndBox, BorderLayout.SOUTH); setSize(400, 150); }
From source file:JDK6TabbedPaneExample.java
public void add() { final JPanel content = new JPanel(); JPanel tab = new JPanel(); tab.setOpaque(false);//from w w w . ja v a 2 s. co m JLabel tabLabel = new JLabel("Tab " + (++tabCounter)); JButton tabCloseButton = new JButton(closeXIcon); tabCloseButton.setPreferredSize(closeButtonSize); tabCloseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int closeTabNumber = tabbedPane.indexOfComponent(content); tabbedPane.removeTabAt(closeTabNumber); } }); tab.add(tabLabel, BorderLayout.WEST); tab.add(tabCloseButton, BorderLayout.EAST); tabbedPane.addTab(null, content); tabbedPane.setTabComponentAt(tabbedPane.getTabCount() - 1, tab); }
From source file:teambootje.A5.java
/** * Creates new form A5/*from w w w . ja v a2s . c o m*/ */ public A5() { initComponents(); setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 5"); 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 Leeftijd, COUNT(*) AS Aantal FROM persoon GROUP BY Leeftijd"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String age = rs.getString("Leeftijd"); 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 leeftijd = age; int a1 = aantal; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("Niet vrijgegeven", a1); JFreeChart chart = ChartFactory.createPieChart3D("Aantal mensen per leeftijd", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Aantal mensen per leeftijd", 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[] = { "Leeftijd", "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.A6.java
/** * Creates new form A6//from www . j a v a 2 s . co m */ public A6() { initComponents(); setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 6"); 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 Locatie.land, locatie.stad, count(persoon.LID) as Aantal FROM persoon, Locatie WHERE persoon.LID = locatie.LID GROUP BY stad"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String city = rs.getString("locatie.stad"); 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 c1 = city; int a1 = amount; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue(c1, a1); pieDataset.setValue("Rotterdam", new Integer(1)); pieDataset.setValue("Bergen op zoom", new Integer(1)); JFreeChart chart = ChartFactory.createPieChart3D("Waar komen bezoekers vandaan", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Waar komen bezoekers vandaan", 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[] = { "Land", "stad", "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.A3.java
/** * Creates new form A3/* w w w .ja va 2s .com*/ */ public A3() { initComponents(); setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 3"); 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 locatie.land, locatie.stad, COUNT(posts.PID) AS Aantal FROM persoon, locatie, posts WHERE persoon.LID = locatie.LID AND persoon.AID = posts.AID GROUP BY locatie.land ORDER BY count(posts.PID)"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String land = rs.getString("locatie.land"); String stad = rs.getString("locatie.stad"); 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 l1 = land; String s1 = stad; int a1 = aantal; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue(s1, a1); JFreeChart chart = ChartFactory.createPieChart3D("Aantal Posts per locatie", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Aantal Posts per locatie", 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[] = { "Land", "Stad", "Aantal" }; list.toArray(array); JTable table = new JTable(array, columnNames); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(400, 400)); ana.add(scroll); }