List of usage examples for java.awt.event MouseAdapter MouseAdapter
MouseAdapter
From source file:PopUpColorMenu.java
public PopUpColorMenu() { JFrame frame = new JFrame(); final JPopupMenu colorMenu = new JPopupMenu("Color"); colorMenu.add(makeMenuItem("Red")); colorMenu.add(makeMenuItem("Green")); colorMenu.add(makeMenuItem("Blue")); MouseListener mouseListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { checkPopup(e);//from w w w . j a va2 s. c o m } public void mouseClicked(MouseEvent e) { checkPopup(e); } public void mouseReleased(MouseEvent e) { checkPopup(e); } private void checkPopup(MouseEvent e) { if (e.isPopupTrigger()) { selectedComponent = e.getComponent(); colorMenu.show(e.getComponent(), e.getX(), e.getY()); } } }; frame.setLayout(new FlowLayout()); JButton button = new JButton("Uno"); button.addMouseListener(mouseListener); frame.add(button); button = new JButton("Due"); button.addMouseListener(mouseListener); frame.add(button); button = new JButton("Tre"); button.addMouseListener(mouseListener); frame.add(button); frame.getContentPane().addMouseListener(mouseListener); frame.setSize(200, 50); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
public CirclePanel() { this.setPreferredSize(new Dimension(80, 80)); this.setForeground(new Color(r.nextInt())); this.addMouseListener(new MouseAdapter() { @Override//w w w . j a va 2s . c om public void mousePressed(MouseEvent e) { update(); } }); }
From source file:ColorsBeanInfo.java
public Colors() { addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent me) { change();/*from w ww . j a v a 2 s .c o m*/ } }); rectangular = false; setSize(200, 100); change(); }
From source file:Main.java
public PopupMenu() { super(BoxLayout.Y_AXIS); final JPopupMenu menu = new JPopupMenu("Options"); for (int i = 1; i < 20; i++) menu.add(new JMenuItem("Option" + i)); JLabel clickMe = new JLabel("ClickMe"); clickMe.setAlignmentX(RIGHT_ALIGNMENT); clickMe.addMouseListener(new MouseAdapter() { @Override//from www .j a v a 2s. c om public void mouseClicked(MouseEvent e) { menu.show(e.getComponent(), e.getX(), e.getY()); } }); add(clickMe); }
From source file:Main.java
private void goWebsite(JLabel website) { website.addMouseListener(new MouseAdapter() { @Override/* w w w .j a v a2 s . c o m*/ public void mouseClicked(MouseEvent e) { try { try { Desktop.getDesktop().browse(new URI("http://www.java2s.com")); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } catch (URISyntaxException ex) { } } }); }
From source file:Main.java
public Main(BufferedImage pic) { super(new Frame()); this.pic = pic; addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { System.exit(0);// w w w . j a v a2s .com } }); }
From source file:MainClass.java
public MainClass(BufferedImage pic) { super(new Frame()); this.pic = pic; addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { System.exit(0);//ww w.j a v a2 s . com } }); }
From source file:Main.java
public Main() { setSize(500, 500);/* w w w . j a v a2 s. c o m*/ setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setLayout(new GridLayout(0, 1)); JPanel buttonPanel = new JPanel(); JButton addButton = new JButton("add"); addButton.addActionListener(e -> addElementToArrayList()); JButton removeButton = new JButton("remove"); removeButton.addActionListener(e -> removeElementFromArrayList()); tabbedPane = new JTabbedPane(); tabbedPaneMouseListener = (new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { if (e.getClickCount() == 1) { System.out.println("Do Something"); } } } }); tabbedPane.addMouseListener(tabbedPaneMouseListener); buttonPanel.add(addButton); buttonPanel.add(removeButton); add(buttonPanel); this.add(tabbedPane); }
From source file:Main.java
/** * Set the button to have simplified UI. * /*from w ww . j ava2 s . c o m*/ * @param button * button to be modified * @param <T> * type of button * @return button */ public static <T extends AbstractButton> T decoratedToSimpleButton(final T button) { button.setForeground(Color.BLACK); button.setBackground(Color.LIGHT_GRAY); button.setBorderPainted(true); button.setFocusPainted(true); button.setContentAreaFilled(false); button.setOpaque(true); if (button instanceof JToggleButton) { ((JToggleButton) button).addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (button.isSelected()) { button.setBackground(Color.WHITE); } } }); } button.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { super.mouseEntered(e); button.setBackground(Color.WHITE); } @Override public void mouseExited(MouseEvent e) { super.mouseExited(e); if (!button.isSelected()) { button.setBackground(Color.LIGHT_GRAY); } } }); button.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { if (!button.isSelected()) { button.setBackground(Color.LIGHT_GRAY); } } }); Border line = new LineBorder(Color.BLACK); Border margin = new EmptyBorder(5, 15, 5, 15); Border compound = new CompoundBorder(line, margin); button.setBorder(compound); return button; }
From source file:ColorSink.java
/** Create a new ColorSink object */ public ColorSink() { // Listen for double clicks. Use them to trigger a paste action. addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { pastecolor();/*from ww w . jav a 2s . co m*/ e.consume(); } } }); // We have to create a DropTarget object to support Drag-and-Drop // It will listen for drops on top of us, and notify our DropTargetListener // methods when drag-and-drop related events occur. setDropTarget(new DropTarget(this, this)); }