List of usage examples for java.awt.event ActionListener ActionListener
ActionListener
From source file:Main.java
private JComboBox createComboBox(final Map<Integer, Student> map) { final JComboBox cbox = new JComboBox(); for (Integer id : map.keySet()) { cbox.addItem(id);//from www. j a va 2s.c o m } cbox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Integer id = (Integer) cbox.getSelectedItem(); System.out.println(map.get(id)); } }); return cbox; }
From source file:org.jfree.chart.demo.Bottom_panel.java
/** * Create the panel.//from www. j a va2 s.c o m */ public Bottom_panel(ArrayList<Graphic> Grafs, ArrayList<XYSeries> series, int x, int y, int width, int height) { graf = Grafs.get(8); serie = series; setBounds(x, y, width, height); setLayout(new GridLayout(0, 4, 2, 0)); final JCheckBox chckbxNewCheckBox_5 = new JCheckBox("Graph 1"); chckbxNewCheckBox_5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { XYSeries sr = serie.get(0); if (chckbxNewCheckBox_5.isSelected() == true) { graf.change_data(serie.get(0), true); } else { graf.change_data(serie.get(0), false); } } }); chckbxNewCheckBox_5.setBackground(new Color(176, 199, 246)); add(chckbxNewCheckBox_5); final JCheckBox chckbxNewCheckBox_1 = new JCheckBox("Graph2"); chckbxNewCheckBox_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { XYSeries sr = serie.get(1); if (chckbxNewCheckBox_1.isSelected() == true) { graf.change_data(serie.get(1), true); } else { graf.change_data(serie.get(1), false); } } }); chckbxNewCheckBox_1.setBackground(new Color(176, 199, 246)); add(chckbxNewCheckBox_1); final JCheckBox chckbxNewCheckBox_2 = new JCheckBox("Graph 3"); chckbxNewCheckBox_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { XYSeries sr = serie.get(2); if (chckbxNewCheckBox_2.isSelected() == true) { graf.change_data(serie.get(2), true); } else { graf.change_data(serie.get(2), false); } } }); chckbxNewCheckBox_2.setBackground(new Color(176, 199, 246)); add(chckbxNewCheckBox_2); final JCheckBox chckbxNewCheckBox = new JCheckBox("Graph 4"); chckbxNewCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { XYSeries sr = serie.get(3); if (chckbxNewCheckBox.isSelected() == true) { graf.change_data(serie.get(3), true); } else { graf.change_data(serie.get(3), false); } } }); chckbxNewCheckBox.setBackground(new Color(176, 199, 246)); add(chckbxNewCheckBox); final JCheckBox chckbxNewCheckBox_3 = new JCheckBox("Graph 5"); chckbxNewCheckBox_3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { XYSeries sr = serie.get(4); if (chckbxNewCheckBox_3.isSelected() == true) { graf.change_data(serie.get(4), true); } else { graf.change_data(serie.get(4), false); } } }); chckbxNewCheckBox_3.setBackground(new Color(176, 199, 246)); add(chckbxNewCheckBox_3); final JCheckBox chckbxNewCheckBox_4 = new JCheckBox("Graph 6"); chckbxNewCheckBox_4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { XYSeries sr = serie.get(5); if (chckbxNewCheckBox_4.isSelected() == true) { graf.change_data(serie.get(5), true); } else { graf.change_data(serie.get(5), false); } } }); chckbxNewCheckBox_4.setBackground(new Color(176, 199, 246)); add(chckbxNewCheckBox_4); final JCheckBox chckbxNewCheckBox_6 = new JCheckBox("Graph 7"); chckbxNewCheckBox_6.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { XYSeries sr = serie.get(6); if (chckbxNewCheckBox_6.isSelected() == true) { graf.change_data(serie.get(6), true); } else { graf.change_data(serie.get(6), false); } } }); chckbxNewCheckBox_6.setBackground(new Color(176, 199, 246)); add(chckbxNewCheckBox_6); final JCheckBox chckbxNewCheckBox_7 = new JCheckBox("Graph 8"); chckbxNewCheckBox_7.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { XYSeries sr = serie.get(7); if (chckbxNewCheckBox_6.isSelected() == true) { graf.change_data(serie.get(7), true); } else { graf.change_data(serie.get(7), false); } } }); chckbxNewCheckBox_7.setBackground(new Color(176, 199, 246)); add(chckbxNewCheckBox_7); }
From source file:MainClass.java
public MainClass() { // Build a mapping from book titles to their entries for (int i = 0; i < items.length; i++) { itemMap.put(items[i].getTitle(), items[i]); }// www . ja v a 2s . c o m setLayout(new BorderLayout()); JComboBox bookCombo = new JComboBox(items); bookCombo.setEditable(true); bookCombo.setEditor(new MyComboBoxEditor(itemMap, items[0])); bookCombo.setMaximumRowCount(4); bookCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("You chose " + ((JComboBox) e.getSource()).getSelectedItem() + "!"); } }); bookCombo.setActionCommand("Hello"); add(bookCombo, BorderLayout.CENTER); }
From source file:Test.java
public Test() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuItem item = new JMenuItem("Test1"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Menu item Test1"); }// w w w .ja va 2 s . com }); menu.add(item); item = new JMenuItem("Test2"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Menu item Test2"); } }); menu.add(item); getContentPane().add(label); pack(); setSize(300, 100); }
From source file:ColorPicker3.java
public ColorPicker3() { super("JColorChooser Test Frame"); setSize(200, 100);/*from w w w . j av a 2 s . c o m*/ final JButton go = new JButton("Show JColorChoser"); final Container contentPane = getContentPane(); go.addActionListener(new ActionListener() { final JColorChooser chooser = new JColorChooser(); boolean first = true; public void actionPerformed(ActionEvent e) { if (first) { first = false; GrayScalePanel gsp = new GrayScalePanel(); chooser.addChooserPanel(gsp); chooser.setPreviewPanel(new CustomPane()); } JDialog dialog = JColorChooser.createDialog(ColorPicker3.this, "Demo 3", true, chooser, new ActionListener() { public void actionPerformed(ActionEvent e) { c = chooser.getColor(); } }, null); dialog.setVisible(true); contentPane.setBackground(c); } }); contentPane.add(go, BorderLayout.SOUTH); // addWindowListener(new BasicWindowMonitor()); // 1.1 & 1.2 setDefaultCloseOperation(EXIT_ON_CLOSE); }
From source file:MyViewChooser.java
public MyViewChooser() { super("File View Test Frame"); setSize(350, 200);/*from w ww. ja va 2s . c o m*/ setDefaultCloseOperation(EXIT_ON_CLOSE); parent = this; Container c = getContentPane(); c.setLayout(new FlowLayout()); JButton openButton = new JButton("Open"); final JLabel statusbar = new JLabel("Output of your selection will go here"); openButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JFileChooser chooser = new JFileChooser(); // Ok, set up our own file view for the chooser chooser.setFileView(new ThumbNailFileView(MyViewChooser.this)); int option = chooser.showOpenDialog(parent); if (option == JFileChooser.APPROVE_OPTION) { statusbar.setText("You chose " + chooser.getSelectedFile().getName()); } else { statusbar.setText("You cancelled."); } } }); c.add(openButton); c.add(statusbar); }
From source file:IntroExample.java
public IntroExample() { JMenu fileMenu = new JMenu("File"); JMenu editMenu = new JMenu("Edit"); JMenu otherMenu = new JMenu("Other"); JMenu subMenu = new JMenu("SubMenu"); JMenu subMenu2 = new JMenu("SubMenu2"); // Assemble the File menus with mnemonics ActionListener printListener = new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("Menu item [" + event.getActionCommand() + "] was pressed."); }// w w w . j a v a 2 s. c o m }; for (int i = 0; i < fileItems.length; i++) { JMenuItem item = new JMenuItem(fileItems[i], fileShortcuts[i]); item.addActionListener(printListener); fileMenu.add(item); } // Assemble the File menus with keyboard accelerators for (int i = 0; i < editItems.length; i++) { JMenuItem item = new JMenuItem(editItems[i]); item.setAccelerator(KeyStroke.getKeyStroke(editShortcuts[i], Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false)); item.addActionListener(printListener); editMenu.add(item); } // Insert a separator in the Edit Menu in Position 1 after "Undo" editMenu.insertSeparator(1); // Assemble the submenus of the Other Menu JMenuItem item; subMenu2.add(item = new JMenuItem("Extra 2")); item.addActionListener(printListener); subMenu.add(item = new JMenuItem("Extra 1")); item.addActionListener(printListener); subMenu.add(subMenu2); // Assemble the Other Menu itself otherMenu.add(subMenu); otherMenu.add(item = new JCheckBoxMenuItem("Check Me")); item.addActionListener(printListener); otherMenu.addSeparator(); ButtonGroup buttonGroup = new ButtonGroup(); otherMenu.add(item = new JRadioButtonMenuItem("Radio 1")); item.addActionListener(printListener); buttonGroup.add(item); otherMenu.add(item = new JRadioButtonMenuItem("Radio 2")); item.addActionListener(printListener); buttonGroup.add(item); otherMenu.addSeparator(); otherMenu.add(item = new JMenuItem("Potted Plant", new ImageIcon("image.gif"))); item.addActionListener(printListener); // Finally, add all the menus to the menu bar add(fileMenu); add(editMenu); add(otherMenu); }
From source file:MenuElementExample.java
public MenuElementExample() { popup = new JPopupMenu(); slider = new SliderMenuItem(); popup.add(slider);/* www . j a v a2 s. c om*/ popup.add(new JSeparator()); JMenuItem ticks = new JCheckBoxMenuItem("Slider Tick Marks"); ticks.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { slider.setPaintTicks(!slider.getPaintTicks()); } }); JMenuItem labels = new JCheckBoxMenuItem("Slider Labels"); labels.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { slider.setPaintLabels(!slider.getPaintLabels()); } }); popup.add(ticks); popup.add(labels); popup.addPopupMenuListener(new PopupPrintListener()); addMouseListener(new MousePopupListener()); }
From source file:EditorDropTarget4.java
public static void main(String[] args) { try {//from www .j av a 2s .com UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } final JFrame f = new JFrame("JEditor Pane Drop Target Example 4"); // Create an editor with autoscrolling support final JEditorPane pane = new AutoScrollingEditorPane(); // Add a drop target to the JEditorPane EditorDropTarget4 target = new EditorDropTarget4(pane); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); JPanel panel = new JPanel(); final JCheckBox editable = new JCheckBox("Editable"); editable.setSelected(true); panel.add(editable); editable.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pane.setEditable(editable.isSelected()); } }); final JCheckBox enabled = new JCheckBox("Enabled"); enabled.setSelected(true); panel.add(enabled); enabled.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pane.setEnabled(enabled.isSelected()); } }); f.getContentPane().add(new JScrollPane(pane), BorderLayout.CENTER); f.getContentPane().add(panel, BorderLayout.SOUTH); f.setSize(500, 400); f.setVisible(true); }
From source file:MainClass.java
public MainClass() { JToggleButton tog = new JToggleButton("ToggleButton"); JCheckBox cb = new JCheckBox("CheckBox"); JRadioButton radio = new JRadioButton("RadioButton"); SimpleListener sl = new SimpleListener(); tog.addActionListener(sl);/*from ww w .java 2 s . com*/ 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); 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()); } } }); Box undoRedoBox = new Box(BoxLayout.X_AXIS); undoRedoBox.add(Box.createGlue()); undoRedoBox.add(undoButton); undoRedoBox.add(Box.createHorizontalStrut(2)); undoRedoBox.add(redoButton); undoRedoBox.add(Box.createGlue()); Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(buttonBox, BorderLayout.CENTER); content.add(undoRedoBox, BorderLayout.SOUTH); setSize(400, 150); }