List of usage examples for java.awt.event ActionEvent META_MASK
int META_MASK
To view the source code for java.awt.event ActionEvent META_MASK.
Click Source Link
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Command: " + e.getActionCommand()); int modifiers = e.getModifiers(); System.out.println("\tALT : " + checkMod(modifiers, ActionEvent.ALT_MASK)); System.out.println("\tCTRL : " + checkMod(modifiers, ActionEvent.CTRL_MASK)); System.out.println("\tMETA : " + checkMod(modifiers, ActionEvent.META_MASK)); System.out.println("\tSHIFT: " + checkMod(modifiers, ActionEvent.SHIFT_MASK)); Object source = e.getSource(); if (source instanceof JComboBox) { JComboBox jb = (JComboBox) source; System.out.println("Combo: " + jb.getSelectedItem()); }/*from w w w.ja v a 2 s.c om*/ } private boolean checkMod(int modifiers, int mask) { return ((modifiers & mask) == mask); } }; String flavors[] = { "Item 1", "Item 2", "Item 3" }; JComboBox jc = new JComboBox(flavors); jc.setMaximumRowCount(4); jc.setEditable(true); jc.addActionListener(listener); contentPane.add(jc, BorderLayout.NORTH); JButton b = new JButton("Button!"); b.addActionListener(listener); contentPane.add(b, BorderLayout.CENTER); JPanel panel = new JPanel(); JLabel label = new JLabel("Label 1: "); JTextField text = new JTextField("Type your text", 15); text.addActionListener(listener); label.setDisplayedMnemonic(KeyEvent.VK_1); label.setLabelFor(text); panel.add(label); panel.add(text); contentPane.add(panel, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:ActionTest.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Command: " + e.getActionCommand()); System.out.println("Modifiers: "); int modifiers = e.getModifiers(); System.out.println("\tALT : " + checkMod(modifiers, ActionEvent.ALT_MASK)); System.out.println("\tCTRL : " + checkMod(modifiers, ActionEvent.CTRL_MASK)); System.out.println("\tMETA : " + checkMod(modifiers, ActionEvent.META_MASK)); System.out.println("\tSHIFT: " + checkMod(modifiers, ActionEvent.SHIFT_MASK)); Object source = e.getSource(); if (source instanceof JComboBox) { JComboBox jb = (JComboBox) source; System.out.println("Combo: " + jb.getSelectedItem()); }/*from w w w.ja v a 2 s . c o m*/ } private boolean checkMod(int modifiers, int mask) { return ((modifiers & mask) == mask); } }; String flavors[] = { "Item 1", "Item 2", "Item 3" }; JComboBox jc = new JComboBox(flavors); jc.setMaximumRowCount(4); jc.setEditable(true); jc.addActionListener(listener); contentPane.add(jc, BorderLayout.NORTH); JButton b = new JButton("Button!"); b.addActionListener(listener); contentPane.add(b, BorderLayout.CENTER); JPanel panel = new JPanel(); JLabel label = new JLabel("Label 1: "); JTextField text = new JTextField("Type your text", 15); text.addActionListener(listener); label.setDisplayedMnemonic(KeyEvent.VK_1); label.setLabelFor(text); panel.add(label); panel.add(text); contentPane.add(panel, BorderLayout.SOUTH); frame.pack(); frame.show(); }
From source file:EventObject.java
public static void main(String[] args) { JFrame f = new JFrame(); JButton ok = new JButton("Ok"); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(event.getWhen()); Locale locale = Locale.getDefault(); String s = DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(new Date()); if (event.getID() == ActionEvent.ACTION_PERFORMED) System.out.println(" Event Id: ACTION_PERFORMED"); System.out.println(" Time: " + s); String source = event.getSource().getClass().getName(); System.out.println(" Source: " + source); int mod = event.getModifiers(); if ((mod & ActionEvent.ALT_MASK) > 0) System.out.println("Alt "); if ((mod & ActionEvent.SHIFT_MASK) > 0) System.out.println("Shift "); if ((mod & ActionEvent.META_MASK) > 0) System.out.println("Meta "); if ((mod & ActionEvent.CTRL_MASK) > 0) System.out.println("Ctrl "); }/* ww w .j a va 2 s . c o m*/ }); f.add(ok); f.setSize(420, 250); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:MyActionListener.java
public void actionPerformed(ActionEvent e) { System.out.println("Command: " + e.getActionCommand()); int modifiers = e.getModifiers(); System.out.println("\tALT : " + checkMod(modifiers, ActionEvent.ALT_MASK)); System.out.println("\tCTRL : " + checkMod(modifiers, ActionEvent.CTRL_MASK)); System.out.println("\tMETA : " + checkMod(modifiers, ActionEvent.META_MASK)); System.out.println("\tSHIFT: " + checkMod(modifiers, ActionEvent.SHIFT_MASK)); Object source = e.getSource(); if (source instanceof JButton) { JButton jb = (JButton) source; System.out.println("JButton: " + jb.getText()); }/*from ww w . java 2s .co m*/ }
From source file:Main.java
public void actionPerformed(ActionEvent e) { Locale locale = Locale.getDefault(); Date date = new Date(e.getWhen()); String s = DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(date); if (!model.isEmpty()) { model.clear();/*from ww w. jav a 2 s . com*/ } if (e.getID() == ActionEvent.ACTION_PERFORMED) { model.addElement(" Event Id: ACTION_PERFORMED"); } model.addElement("Time: " + s); String source = e.getSource().getClass().getName(); int mod = e.getModifiers(); StringBuffer buffer = new StringBuffer("Modifiers: "); if ((mod & ActionEvent.ALT_MASK) > 0) { buffer.append("Alt "); } if ((mod & ActionEvent.SHIFT_MASK) > 0) { buffer.append("Shift "); } if ((mod & ActionEvent.META_MASK) > 0) { buffer.append("Meta "); } if ((mod & ActionEvent.CTRL_MASK) > 0) { buffer.append("Ctrl "); } model.addElement(buffer); }
From source file:PopupDemo.java
String getMods(int mods) { String modstr = ""; if ((mods & ActionEvent.SHIFT_MASK) == ActionEvent.SHIFT_MASK) modstr += (" SHIFT"); if ((mods & ActionEvent.ALT_MASK) == ActionEvent.ALT_MASK) modstr += (" ALT"); if ((mods & ActionEvent.CTRL_MASK) == ActionEvent.CTRL_MASK) modstr += (" CTRL"); if ((mods & ActionEvent.META_MASK) == ActionEvent.META_MASK) modstr += (" META"); return modstr; }
From source file:de.xplib.xdbm.util.I18N.java
/** * @param keyIn ..// w w w .ja va 2 s . c om * @return .. */ public KeyStroke getAccelerator(final String keyIn) { String value = this.getValue(keyIn, "accelerator"); if (value.startsWith(keyIn)) { return null; } String[] s = value.toUpperCase().split(","); if (s.length == 0 || s[0].equals("")) { return null; } int code = (int) s[0].charAt(0); int mod = 0; for (int i = 1; i < s.length; i++) { char c = s[i].charAt(0); if (c == 'S') { mod = mod | ActionEvent.SHIFT_MASK; } else if (c == 'A') { mod = mod | ActionEvent.ALT_MASK; } else if (c == 'C') { mod = mod | ActionEvent.CTRL_MASK; } else if (c == 'M') { mod = mod | ActionEvent.META_MASK; } } return KeyStroke.getKeyStroke(code, mod); }