List of usage examples for java.awt.event MouseListener MouseListener
MouseListener
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;// w ww . j a va 2 s . co m } SystemTray tray = SystemTray.getSystemTray(); Dimension size = tray.getTrayIconSize(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); PopupMenu popup = new PopupMenu(); MenuItem miExit = new MenuItem("Exit"); ActionListener al; al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; miExit.addActionListener(al); popup.add(miExit); TrayIcon ti = new TrayIcon(bi, "System Tray Demo #2"); ti.setPopupMenu(popup); al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(e.getActionCommand()); } }; ti.setActionCommand("My Icon"); ti.addActionListener(al); MouseListener ml = new MouseListener() { public void mouseClicked(MouseEvent e) { System.out.println("Tray icon: Mouse clicked"); } public void mouseEntered(MouseEvent e) { System.out.println("Tray icon: Mouse entered"); } public void mouseExited(MouseEvent e) { System.out.println("Tray icon: Mouse exited"); } public void mousePressed(MouseEvent e) { System.out.println("Tray icon: Mouse pressed"); } public void mouseReleased(MouseEvent e) { System.out.println("Tray icon: Mouse released"); } }; ti.addMouseListener(ml); MouseMotionListener mml = new MouseMotionListener() { public void mouseDragged(MouseEvent e) { System.out.println("Tray icon: Mouse dragged"); } public void mouseMoved(MouseEvent e) { System.out.println("Tray icon: Mouse moved"); } }; ti.addMouseMotionListener(mml); ActionListener[] actionListeners = ti.getActionListeners(); for (ActionListener ac : actionListeners) { ti.removeActionListener(ac); } tray.add(ti); }
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;//from www . j a va 2s.c om } SystemTray tray = SystemTray.getSystemTray(); Dimension size = tray.getTrayIconSize(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); PopupMenu popup = new PopupMenu(); MenuItem miExit = new MenuItem("Exit"); ActionListener al; al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; miExit.addActionListener(al); popup.add(miExit); TrayIcon ti = new TrayIcon(bi, "System Tray Demo #2"); ti.setPopupMenu(popup); al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(e.getActionCommand()); } }; ti.setActionCommand("My Icon"); ti.addActionListener(al); MouseListener ml = new MouseListener() { public void mouseClicked(MouseEvent e) { System.out.println("Tray icon: Mouse clicked"); } public void mouseEntered(MouseEvent e) { System.out.println("Tray icon: Mouse entered"); } public void mouseExited(MouseEvent e) { System.out.println("Tray icon: Mouse exited"); } public void mousePressed(MouseEvent e) { System.out.println("Tray icon: Mouse pressed"); } public void mouseReleased(MouseEvent e) { System.out.println("Tray icon: Mouse released"); } }; ti.addMouseListener(ml); MouseMotionListener mml = new MouseMotionListener() { public void mouseDragged(MouseEvent e) { System.out.println("Tray icon: Mouse dragged"); } public void mouseMoved(MouseEvent e) { System.out.println("Tray icon: Mouse moved"); } }; ti.addMouseMotionListener(mml); MouseListener[] mouseListeners = ti.getMouseListeners(); for (MouseListener ac : mouseListeners) { ti.removeMouseListener(ac); } tray.add(ti); }
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;//w ww .j a v a 2 s . c o m } SystemTray tray = SystemTray.getSystemTray(); Dimension size = tray.getTrayIconSize(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); PopupMenu popup = new PopupMenu(); MenuItem miExit = new MenuItem("Exit"); ActionListener al; al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; miExit.addActionListener(al); popup.add(miExit); TrayIcon ti = new TrayIcon(bi, "System Tray Demo #2"); ti.setPopupMenu(popup); al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(e.getActionCommand()); } }; ti.setActionCommand("My Icon"); ti.addActionListener(al); MouseListener ml = new MouseListener() { public void mouseClicked(MouseEvent e) { System.out.println("Tray icon: Mouse clicked"); } public void mouseEntered(MouseEvent e) { System.out.println("Tray icon: Mouse entered"); } public void mouseExited(MouseEvent e) { System.out.println("Tray icon: Mouse exited"); } public void mousePressed(MouseEvent e) { System.out.println("Tray icon: Mouse pressed"); } public void mouseReleased(MouseEvent e) { System.out.println("Tray icon: Mouse released"); } }; ti.addMouseListener(ml); MouseMotionListener mml = new MouseMotionListener() { public void mouseDragged(MouseEvent e) { System.out.println("Tray icon: Mouse dragged"); } public void mouseMoved(MouseEvent e) { System.out.println("Tray icon: Mouse moved"); } }; ti.addMouseMotionListener(mml); MouseMotionListener[] mouseMotionListeners = ti.getMouseMotionListeners(); for (MouseMotionListener ac : mouseMotionListeners) { ti.removeMouseMotionListener(ac); } tray.add(ti); }
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;//w w w . j a v a 2s. co m } SystemTray tray = SystemTray.getSystemTray(); Dimension size = tray.getTrayIconSize(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); PopupMenu popup = new PopupMenu(); MenuItem miExit = new MenuItem("Exit"); ActionListener al; al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; miExit.addActionListener(al); popup.add(miExit); TrayIcon ti = new TrayIcon(bi, "System Tray Demo #2"); ti.setPopupMenu(popup); al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(e.getActionCommand()); } }; ti.setActionCommand("My Icon"); ti.addActionListener(al); MouseListener ml = new MouseListener() { public void mouseClicked(MouseEvent e) { System.out.println("Tray icon: Mouse clicked"); } public void mouseEntered(MouseEvent e) { System.out.println("Tray icon: Mouse entered"); } public void mouseExited(MouseEvent e) { System.out.println("Tray icon: Mouse exited"); } public void mousePressed(MouseEvent e) { System.out.println("Tray icon: Mouse pressed"); } public void mouseReleased(MouseEvent e) { System.out.println("Tray icon: Mouse released"); } }; ti.addMouseListener(ml); MouseMotionListener mml = new MouseMotionListener() { public void mouseDragged(MouseEvent e) { System.out.println("Tray icon: Mouse dragged"); } public void mouseMoved(MouseEvent e) { System.out.println("Tray icon: Mouse moved"); } }; ti.addMouseMotionListener(mml); Image image = ti.getImage(); tray.add(ti); }
From source file:SystemTrayDemo2.java
public static void main(String[] args) { if (!SystemTray.isSupported()) { return;/*w w w . j ava2 s. c om*/ } SystemTray tray = SystemTray.getSystemTray(); Dimension size = tray.getTrayIconSize(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); g.setColor(Color.yellow); int ovalSize = (size.width < size.height) ? size.width : size.height; ovalSize /= 2; g.fillOval(size.width / 4, size.height / 4, ovalSize, ovalSize); try { PopupMenu popup = new PopupMenu(); MenuItem miExit = new MenuItem("Exit"); ActionListener al; al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Goodbye"); System.exit(0); } }; miExit.addActionListener(al); popup.add(miExit); TrayIcon ti = new TrayIcon(bi, "System Tray Demo #2", popup); al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(e.getActionCommand()); } }; ti.setActionCommand("My Icon"); ti.addActionListener(al); MouseListener ml; ml = new MouseListener() { public void mouseClicked(MouseEvent e) { System.out.println("Tray icon: Mouse clicked"); } public void mouseEntered(MouseEvent e) { System.out.println("Tray icon: Mouse entered"); } public void mouseExited(MouseEvent e) { System.out.println("Tray icon: Mouse exited"); } public void mousePressed(MouseEvent e) { System.out.println("Tray icon: Mouse pressed"); } public void mouseReleased(MouseEvent e) { System.out.println("Tray icon: Mouse released"); } }; ti.addMouseListener(ml); MouseMotionListener mml; mml = new MouseMotionListener() { public void mouseDragged(MouseEvent e) { System.out.println("Tray icon: Mouse dragged"); } public void mouseMoved(MouseEvent e) { System.out.println("Tray icon: Mouse moved"); } }; ti.addMouseMotionListener(mml); tray.add(ti); } catch (AWTException e) { System.out.println(e.getMessage()); return; } }
From source file:MouseTest.java
public MouseTest() { super();/*from w ww.ja v a 2 s . com*/ final JPopupMenu pop = new JPopupMenu(); pop.add(new JMenuItem("Cut")); pop.add(new JMenuItem("Copy")); pop.add(new JMenuItem("Paste")); pop.addSeparator(); pop.add(new JMenuItem("Select All")); pop.setInvoker(this); MouseListener popup = new MouseListener() { public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { showPopup(e); } } public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { showPopup(e); } } private void showPopup(MouseEvent e) { pop.show(e.getComponent(), e.getX(), e.getY()); } }; addMouseListener(popup); MouseListener drawing1 = new MouseListener() { public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { color = Color.RED; startX = endX = e.getX(); startY = endY = e.getY(); repaint(); } public void mouseReleased(MouseEvent e) { color = Color.BLACK; repaint(); } }; addMouseListener(drawing1); MouseMotionListener drawing2 = new MouseMotionListener() { public void mouseDragged(MouseEvent e) { endX = e.getX(); endY = e.getY(); repaint(); } public void mouseMoved(MouseEvent e) { } }; addMouseMotionListener(drawing2); }
From source file:ui.frame.KAIQRFrame.java
public KAIQRFrame() { // init frames super("KAI QR Code Generator"); mouseDownCompCoords = null;//from www . ja va2s.c o m addMouseListener(new MouseListener() { public void mouseReleased(MouseEvent e) { mouseDownCompCoords = null; } public void mousePressed(MouseEvent e) { mouseDownCompCoords = e.getPoint(); } public void mouseExited(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseClicked(MouseEvent e) { } }); addMouseMotionListener(new MouseMotionListener() { public void mouseMoved(MouseEvent e) { } public void mouseDragged(MouseEvent e) { Point currCoords = e.getLocationOnScreen(); setLocation(currCoords.x - mouseDownCompCoords.x, currCoords.y - mouseDownCompCoords.y); } }); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); menuPanel = p.createPanel(Layouts.grid, 5, 1); btnLogOut = b.createButton("Logout"); btnLogOut.setPreferredSize(new Dimension(100, 50)); btnLogOut.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { APICall api = new APICall(); try { JSONObject response = new JSONObject(api.logout(Data.targetURL, Data.sessionKey)); if (response.getString("result").equals("ok")) { UILogin login = new UILogin(); Data.mainFrame.setVisible(false); } } catch (JSONException e1) { e1.printStackTrace(); } } }); menuPanel.add(btnLogOut); cardPanel = p.createPanel(Layouts.card); cardLayout = new CardLayout(); cardPanel.setLayout(cardLayout); getContentPane().setBackground(CustomColor.NavyBlue.returnColor()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new BorderLayout()); setLocationRelativeTo(null); add(menuPanel, BorderLayout.WEST); add(cardPanel, BorderLayout.CENTER); pack(); }
From source file:com.antelink.sourcesquare.gui.controller.SourceSquareController.java
public void bind() { this.view.getSelectButtonLabel().addMouseListener(new MouseListener() { @Override//from w w w.j a v a 2 s . co m public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseClicked(MouseEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileHidingEnabled(false); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int showDialog = fileChooser.showDialog(SourceSquareController.this.view, "Select directory"); if (showDialog == JFileChooser.APPROVE_OPTION) { SourceSquareController.this.view.getTextField() .setText(fileChooser.getSelectedFile().getAbsolutePath()); } } }); this.view.getScanButtonLabel().addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseClicked(MouseEvent arg0) { File toScan = new File(SourceSquareController.this.view.getTextField().getText()); if (!toScan.exists() || toScan.list().length == 0) { JOptionPane.showMessageDialog(SourceSquareController.this.view, "Choose a valid and not empty directory", null, JOptionPane.ERROR_MESSAGE); return; } SourceSquareController.this.view.setVisible(false); SourceSquareController.this.eventBus.fireEvent(new StartScanEvent(toScan)); } }); }
From source file:se.llbit.chunky.ui.Minimap.java
/** * @param parent//from ww w .jav a2s . c om */ public Minimap(Chunky parent) { this.chunky = parent; setBackground(Color.white); setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT)); setMinimumSize(new Dimension(100, 100)); setIgnoreRepaint(false); view = chunky.getMinimapView(); mapBuffer = new MapBuffer(view); addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { chunky.moveView(e.getX() - getWidth() / 2, e.getY() - getHeight() / 2); } @Override public void mouseExited(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseClicked(MouseEvent e) { } }); addComponentListener(new ComponentListener() { @Override public void componentShown(ComponentEvent e) { } @Override public void componentResized(ComponentEvent e) { chunky.minimapResized(getWidth(), getHeight()); } @Override public void componentMoved(ComponentEvent e) { } @Override public void componentHidden(ComponentEvent e) { } }); }
From source file:com.antelink.sourcesquare.gui.controller.ExitController.java
public void bind() { this.view.getOpenButtonLabel().addMouseListener(new MouseListener() { @Override/*from w w w .j a v a 2 s.c om*/ public void mouseReleased(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseClicked(MouseEvent arg0) { try { Desktop.getDesktop().browse(new URI("http://localhost:9524/")); } catch (IOException e) { logger.error("Error opening the browser", e); } catch (URISyntaxException e) { logger.error("Error opening the browser", e); } } }); this.eventBus.addHandler(StartScanEvent.TYPE, new StartScanEventHandler() { @Override public String getId() { return "Exit Controller is now Handling"; } @Override public void handle(File toScan) { display(); } }); this.eventBus.addHandler(ErrorEvent.TYPE, new ErrorEventHandler() { @Override public String getId() { return "Handling error"; } @Override public void handle(String error) { JOptionPane.showMessageDialog(ExitController.this.view, error, null, JOptionPane.ERROR_MESSAGE); System.exit(0); } }); }