List of usage examples for java.awt.event ActionEvent getSource
public Object getSource()
From source file:MainClass.java
public void actionPerformed(ActionEvent e) { JComboBox jcb = (JComboBox) e.getSource(); ComboBoxEditor cbe = jcb.getEditor(); cbe.setItem(""); }
From source file:Main.java
public void actionPerformed(ActionEvent evt) { JTextComponent c = (JTextComponent) evt.getSource(); try {/* w w w .ja v a2 s .c om*/ c.getDocument().insertString(c.getCaretPosition(), " ", null); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public void actionPerformed(ActionEvent evt) { JButton button = (JButton) evt.getSource(); if (animate) { button.setText("Start Animation"); animate = false;/*from www. ja v a 2 s . c o m*/ } else { animate = true; button.setText("Stop Animation"); new Thread(this).start(); } }
From source file:TextAreaFrame.java
public void actionPerformed(ActionEvent evt) { Object source = evt.getSource(); if (source == insertButton) textArea.append(//from w ww . j a v a 2 s .co m "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog."); else if (source == wrapButton) { textArea.setLineWrap(true); scrollPane.validate(); } else if (source == noWrapButton) { textArea.setLineWrap(false); scrollPane.validate(); } }
From source file:ToolBarwithCheckBox.java
public ToolbarPanel() { setLayout(new BorderLayout()); JToolBar toolbar = new JToolBar(); for (int i = 1; i < 4; i++) { JCheckBox cbox = new JCheckBox("Checkbox #" + i); toolbar.add(cbox);/* w w w . java 2s . c o m*/ cbox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JCheckBox source = (JCheckBox) (e.getSource()); System.out.println("Toolbar " + source.getText()); } }); } add(toolbar, BorderLayout.NORTH); }
From source file:Main.java
public void actionPerformed(ActionEvent evt) { Object source = evt.getSource(); if (source == openItem) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); chooser.setFileFilter(new FileFilter() { public boolean accept(File f) { return f.getName().toLowerCase().endsWith(".zip") || f.isDirectory(); }//w w w . j a v a2 s. c o m public String getDescription() { return "ZIP Files"; } }); int r = chooser.showOpenDialog(this); if (r == JFileChooser.APPROVE_OPTION) { String zipname = chooser.getSelectedFile().getPath(); System.out.println(zipname); } } else if (source == exitItem) System.exit(0); }
From source file:Main.java
public void actionPerformed(ActionEvent e) { JComboBox cb = (JComboBox) e.getSource(); CheckComboStore store = (CheckComboStore) cb.getSelectedItem(); CheckComboRenderer ccr = (CheckComboRenderer) cb.getRenderer(); ccr.checkBox.setSelected((store.state = !store.state)); }
From source file:Main.java
public void actionPerformed(ActionEvent e) { String menuText = ((JMenuItem) e.getSource()).getText(); int messageType = JOptionPane.INFORMATION_MESSAGE; if (menuText.equals("Information")) { messageType = JOptionPane.INFORMATION_MESSAGE; } else if (menuText.equals("Warning")) { messageType = JOptionPane.WARNING_MESSAGE; } else if (menuText.equals("Error")) { messageType = JOptionPane.ERROR_MESSAGE; } else if (menuText.equals("Plain")) { messageType = JOptionPane.PLAIN_MESSAGE; }//from www .j av a 2s . c o m JOptionPane.showMessageDialog(myFrame, "This is message dialog box of type: " + menuText, menuText + " Message", messageType); }
From source file:Main.java
private void initComponents() { JFrame frame = new JFrame("JFormattedTextField Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); MaskFormatter mask = null;//from ww w . j av a 2 s .c o m try { mask = new MaskFormatter("##h##min##s");// the # is for numeric values mask.setPlaceholderCharacter('#'); } catch (ParseException e) { e.printStackTrace(); } final JFormattedTextField timeField = new JFormattedTextField(mask); // ActionListener for when enter is pressed timeField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { Object source = ae.getSource(); if (source == timeField) { // parse to a valid time here System.out.println(timeField.getText()); } } }); frame.add(timeField); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public void actionPerformed(ActionEvent e) { JComboBox comboBox = (JComboBox) e.getSource(); Item item = (Item) comboBox.getSelectedItem(); System.out.println(item.getId() + " : " + item.getDescription()); }