Search in sources :

Example 31 with MouseAdapter

use of java.awt.event.MouseAdapter in project jdk8u_jdk by JetBrains.

the class MissingEventsOnModalDialogTest method showModalDialog.

private static void showModalDialog(Frame targetFrame) {
    Dialog dialog = new Dialog(targetFrame, true);
    dialog.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            passed = true;
            dialog.dispose();
        }
    });
    dialog.setSize(400, 300);
    dialog.setTitle("Modal Dialog!");
    clickOnModalDialog(dialog);
    dialog.setVisible(true);
}
Also used : MouseEvent(java.awt.event.MouseEvent) Dialog(java.awt.Dialog) MouseAdapter(java.awt.event.MouseAdapter)

Example 32 with MouseAdapter

use of java.awt.event.MouseAdapter in project jdk8u_jdk by JetBrains.

the class MultimonFullscreenTest method actionPerformed.

public void actionPerformed(ActionEvent ae) {
    GraphicsDevice dev = deviceMap.get(ae.getSource());
    System.err.println("Setting FS on device:" + dev);
    final Window fsWindow;
    if (useFSWindow) {
        fsWindow = new Window(this, dev.getDefaultConfiguration()) {

            public void paint(Graphics g) {
                renderDimensions(g, getBounds(), this.getGraphicsConfiguration());
            }
        };
    } else if (useFSDialog) {
        fsWindow = new Dialog((Frame) null, "FS Dialog on device " + dev, false, dev.getDefaultConfiguration());
        fsWindow.add(new Component() {

            public void paint(Graphics g) {
                renderDimensions(g, getBounds(), this.getGraphicsConfiguration());
            }
        });
    } else {
        fsWindow = new Frame("FS Frame on device " + dev, dev.getDefaultConfiguration()) {

            public void paint(Graphics g) {
                renderDimensions(g, getBounds(), this.getGraphicsConfiguration());
            }
        };
        if (addHWChildren) {
            fsWindow.add("South", new Panel() {

                public void paint(Graphics g) {
                    g.setColor(Color.red);
                    g.fillRect(0, 0, getWidth(), getHeight());
                }
            });
            fsWindow.add("North", new Button("Button, sucka!"));
        }
    }
    fsWindow.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
                done = true;
                fsWindow.dispose();
            }
        }
    });
    fsWindow.addWindowListener(new WindowHandler());
    dev.setFullScreenWindow(fsWindow);
    if (dmChange && dev.isDisplayChangeSupported()) {
        DisplayMode[] dms = dev.getDisplayModes();
        DisplayMode myDM = null;
        for (DisplayMode dm : dms) {
            if (dm.getWidth() == 800 && dm.getHeight() == 600 && (dm.getBitDepth() >= 16 || dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) && (dm.getRefreshRate() >= 60 || dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN)) {
                myDM = dm;
                break;
            }
        }
        if (myDM != null) {
            System.err.println("Setting Display Mode: " + myDM.getWidth() + "x" + myDM.getHeight() + "x" + myDM.getBitDepth() + "@" + myDM.getRefreshRate() + "Hz on device" + dev);
            dev.setDisplayMode(myDM);
        } else {
            System.err.println("Can't find suitable display mode.");
        }
    }
    done = false;
    if (runRenderLoop) {
        Thread updateThread = new Thread(new Runnable() {

            public void run() {
                BufferStrategy bs = null;
                if (useBS) {
                    fsWindow.createBufferStrategy(2);
                    bs = fsWindow.getBufferStrategy();
                }
                while (!done) {
                    if (useBS) {
                        Graphics g = bs.getDrawGraphics();
                        renderDimensions(g, fsWindow.getBounds(), fsWindow.getGraphicsConfiguration());
                        bs.show();
                    } else {
                        fsWindow.repaint();
                    }
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                    }
                }
                if (useBS) {
                    bs.dispose();
                }
            }
        });
        updateThread.start();
    }
}
Also used : Window(java.awt.Window) Frame(java.awt.Frame) MouseEvent(java.awt.event.MouseEvent) BufferStrategy(java.awt.image.BufferStrategy) MouseAdapter(java.awt.event.MouseAdapter) Graphics(java.awt.Graphics) DisplayMode(java.awt.DisplayMode) Panel(java.awt.Panel) GraphicsDevice(java.awt.GraphicsDevice) Button(java.awt.Button) Dialog(java.awt.Dialog) Component(java.awt.Component)

Example 33 with MouseAdapter

use of java.awt.event.MouseAdapter in project jdk8u_jdk by JetBrains.

the class ExtraMouseClick method init.

public void init() {
    this.setLayout(new BorderLayout());
    frame.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            System.out.println("MousePressed");
            pressed = true;
        }

        public void mouseReleased(MouseEvent e) {
            System.out.println("MouseReleased");
            released = true;
        }

        public void mouseClicked(MouseEvent e) {
            System.out.println("MouseClicked!!!!");
            clicked = true;
        }
    });
    frame.addMouseMotionListener(new MouseMotionAdapter() {

        public void mouseDragged(MouseEvent e) {
            System.out.println("MouseDragged--" + e);
            dragged = true;
        }

        public void mouseMoved(MouseEvent e) {
        }
    });
}
Also used : MouseMotionAdapter(java.awt.event.MouseMotionAdapter) MouseEvent(java.awt.event.MouseEvent) BorderLayout(java.awt.BorderLayout) MouseAdapter(java.awt.event.MouseAdapter)

Example 34 with MouseAdapter

use of java.awt.event.MouseAdapter in project jdk8u_jdk by JetBrains.

the class GrabOnUnfocusableToplevel method main.

public static void main(String[] args) {
    Robot r = Util.createRobot();
    JWindow w = new JWindow();
    w.setSize(100, 100);
    w.setVisible(true);
    Util.waitForIdle(r);
    final JPopupMenu menu = new JPopupMenu();
    JButton item = new JButton("A button in popup");
    menu.add(item);
    w.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent me) {
            menu.show(me.getComponent(), me.getX(), me.getY());
            System.out.println("Showing menu at " + menu.getLocationOnScreen() + " isVisible: " + menu.isVisible() + " isValid: " + menu.isValid());
        }
    });
    Util.clickOnComp(w, r);
    Util.waitForIdle(r);
    if (!menu.isVisible()) {
        throw new RuntimeException("menu was not shown");
    }
    menu.hide();
    System.out.println("Test passed.");
}
Also used : MouseEvent(java.awt.event.MouseEvent) JWindow(javax.swing.JWindow) JButton(javax.swing.JButton) MouseAdapter(java.awt.event.MouseAdapter) Robot(java.awt.Robot) JPopupMenu(javax.swing.JPopupMenu)

Example 35 with MouseAdapter

use of java.awt.event.MouseAdapter in project jdk8u_jdk by JetBrains.

the class JPEGsNotAcceleratedTest method showRes.

private static void showRes(String desc, final BufferedImage src) {
    final int w = src.getWidth();
    final int h = src.getHeight();
    Frame f = new Frame(desc + ": dbl-click to exit");
    Component c;
    f.add(c = new Component() {

        public Dimension getPreferredSize() {
            return new Dimension(w, h);
        }

        public void paint(Graphics g) {
            g.clearRect(0, 0, getWidth(), getHeight());
            g.drawImage(src, 0, 0, null);
        }
    });
    c.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
                System.exit(0);
            }
        }
    });
    f.pack();
    synchronized (JPEGsNotAcceleratedTest.class) {
        f.setLocation(frameX, frameY);
        frameX += f.getWidth();
        if ((frameX + f.getWidth()) > f.getGraphicsConfiguration().getBounds().width) {
            frameY += TEST_H;
            if ((frameY + f.getHeight()) > f.getGraphicsConfiguration().getBounds().height) {
                startY += 30;
                startX += 30;
                frameY = startY;
            }
            frameX = startX;
        }
    }
    ;
    f.setVisible(true);
}
Also used : Graphics(java.awt.Graphics) Frame(java.awt.Frame) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) Dimension(java.awt.Dimension) Component(java.awt.Component)

Aggregations

MouseAdapter (java.awt.event.MouseAdapter)202 MouseEvent (java.awt.event.MouseEvent)199 JLabel (javax.swing.JLabel)52 JPanel (javax.swing.JPanel)48 ActionEvent (java.awt.event.ActionEvent)36 JScrollPane (javax.swing.JScrollPane)36 BorderLayout (java.awt.BorderLayout)35 Dimension (java.awt.Dimension)34 JButton (javax.swing.JButton)33 ActionListener (java.awt.event.ActionListener)32 Insets (java.awt.Insets)24 GridBagConstraints (java.awt.GridBagConstraints)20 KeyEvent (java.awt.event.KeyEvent)20 KeyAdapter (java.awt.event.KeyAdapter)19 JTextField (javax.swing.JTextField)16 ListSelectionEvent (javax.swing.event.ListSelectionEvent)16 Component (java.awt.Component)15 Point (java.awt.Point)15 JTable (javax.swing.JTable)15 ListSelectionListener (javax.swing.event.ListSelectionListener)15