Search in sources :

Example 51 with Panel

use of java.awt.Panel in project jdk8u_jdk by JetBrains.

the class SelectionInvisibleTest method main.

public static void main(String[] args) throws Exception {
    Frame frame = new Frame();
    frame.setSize(300, 200);
    TextField textField = new TextField(TEXT + LAST_WORD, 30);
    Panel panel = new Panel(new FlowLayout());
    panel.add(textField);
    frame.add(panel);
    frame.setVisible(true);
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    toolkit.realSync();
    Robot robot = new Robot();
    robot.setAutoDelay(50);
    Point point = textField.getLocationOnScreen();
    int x = point.x + textField.getWidth() / 2;
    int y = point.y + textField.getHeight() / 2;
    robot.mouseMove(x, y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    toolkit.realSync();
    robot.mousePress(InputEvent.BUTTON1_MASK);
    int N = 10;
    int dx = textField.getWidth() / N;
    for (int i = 0; i < N; i++) {
        x += dx;
        robot.mouseMove(x, y);
    }
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    toolkit.realSync();
    if (!textField.getSelectedText().endsWith(LAST_WORD)) {
        throw new RuntimeException("Last word is not selected!");
    }
}
Also used : Panel(java.awt.Panel) Frame(java.awt.Frame) FlowLayout(java.awt.FlowLayout) TextField(java.awt.TextField) SunToolkit(sun.awt.SunToolkit) Point(java.awt.Point) Robot(java.awt.Robot) Point(java.awt.Point)

Example 52 with Panel

use of java.awt.Panel in project jdk8u_jdk by JetBrains.

the class ScaledTransform method testScaleFactor.

private static void testScaleFactor(final GraphicsConfiguration gc) {
    final Dialog dialog = new Dialog((Frame) null, "Test", true, gc);
    try {
        dialog.setSize(100, 100);
        Panel panel = new Panel() {

            @Override
            public void paint(Graphics g) {
                if (g instanceof Graphics2D) {
                    AffineTransform gcTx = gc.getDefaultTransform();
                    AffineTransform gTx = ((Graphics2D) g).getTransform();
                    passed = gcTx.getScaleX() == gTx.getScaleX() && gcTx.getScaleY() == gTx.getScaleY();
                } else {
                    passed = true;
                }
                dialog.setVisible(false);
            }
        };
        dialog.add(panel);
        dialog.setVisible(true);
        if (!passed) {
            throw new RuntimeException("Transform is not scaled!");
        }
    } finally {
        dialog.dispose();
    }
}
Also used : Graphics(java.awt.Graphics) Panel(java.awt.Panel) Dialog(java.awt.Dialog) AffineTransform(java.awt.geom.AffineTransform) Graphics2D(java.awt.Graphics2D)

Example 53 with Panel

use of java.awt.Panel in project jdk8u_jdk by JetBrains.

the class DeviceIdentificationTest method main.

public static void main(String[] args) {
    final Frame f = new Frame("DeviceIdentificationTest");
    f.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            f.dispose();
        }
    });
    f.addComponentListener(new ComponentAdapter() {

        public void componentMoved(ComponentEvent e) {
            f.setTitle("Currently on: " + f.getGraphicsConfiguration().getDevice());
        }
    });
    Panel p = new Panel();
    Button b = new Button("Print Current Devices");
    b.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            GraphicsDevice[] gds = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
            int i = 0;
            System.err.println("--- Devices: ---");
            for (GraphicsDevice gd : gds) {
                System.err.println("Device[" + i + "]= " + gd);
                System.err.println("  bounds = " + gd.getDefaultConfiguration().getBounds());
                i++;
            }
            System.err.println("-------------------");
        }
    });
    p.add(b);
    b = new Button("Print My Device");
    b.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            GraphicsConfiguration gc = f.getGraphicsConfiguration();
            GraphicsDevice gd = gc.getDevice();
            System.err.println("--- My Device ---");
            System.err.println("Device  = " + gd);
            System.err.println(" bounds = " + gd.getDefaultConfiguration().getBounds());
        }
    });
    p.add(b);
    b = new Button("Create FS Frame on my Device");
    b.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            GraphicsConfiguration gc = f.getGraphicsConfiguration();
            final GraphicsDevice gd = gc.getDevice();
            System.err.println("--- Creating FS Frame on Device ---");
            System.err.println("Device  = " + gd);
            System.err.println(" bounds = " + gd.getDefaultConfiguration().getBounds());
            final Frame fsf = new Frame("Full-screen Frame on dev" + gd, gc) {

                public void paint(Graphics g) {
                    g.setColor(Color.green);
                    g.fillRect(0, 0, getWidth(), getHeight());
                    g.setColor(Color.red);
                    g.drawString("FS on device: " + gd, 200, 200);
                    g.drawString("Click to exit Full-screen.", 200, 250);
                }
            };
            fsf.setUndecorated(true);
            fsf.addMouseListener(new MouseAdapter() {

                public void mouseClicked(MouseEvent e) {
                    gd.setFullScreenWindow(null);
                    fsf.dispose();
                }
            });
            gd.setFullScreenWindow(fsf);
        }
    });
    p.add(b);
    f.add("North", p);
    p = new Panel();
    b = new Button("Test Passed");
    b.setBackground(Color.green);
    b.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            System.out.println("Test Passed");
            f.dispose();
        }
    });
    p.add(b);
    b = new Button("Test Failed");
    b.setBackground(Color.red);
    b.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            System.out.println("Test FAILED");
            f.dispose();
            throw new RuntimeException("Test FAILED");
        }
    });
    p.add(b);
    f.add("South", p);
    f.pack();
    f.setVisible(true);
}
Also used : Frame(java.awt.Frame) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter) WindowAdapter(java.awt.event.WindowAdapter) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics(java.awt.Graphics) Panel(java.awt.Panel) GraphicsDevice(java.awt.GraphicsDevice) ActionListener(java.awt.event.ActionListener) Button(java.awt.Button) WindowEvent(java.awt.event.WindowEvent) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 54 with Panel

use of java.awt.Panel in project jdk8u_jdk by JetBrains.

the class deadKeyMacOSX method createAndShowGUI.

static void createAndShowGUI() {
    Frame frame = new Frame();
    frame.setSize(300, 300);
    Panel panel = new Panel() {

        @Override
        public void paint(Graphics g) {
            super.paint(g);
            lock.lock();
            isPainted.signalAll();
            lock.unlock();
        }
    };
    frame.add(panel);
    lock.lock();
    frame.setVisible(true);
    panel.requestFocusInWindow();
    try {
        isPainted.await();
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } finally {
        lock.unlock();
        panel.addKeyListener(new DeadKeyListener());
    }
}
Also used : Graphics(java.awt.Graphics) Panel(java.awt.Panel) Frame(java.awt.Frame)

Example 55 with Panel

use of java.awt.Panel in project jdk8u_jdk by JetBrains.

the class OverriddenInsetsTest method main.

public static void main(String[] args) {
    if (GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getColorModel().getPixelSize() < 16) {
        System.out.println("<16 bit mode detected, test passed");
    }
    final Frame f = new Frame("OverriddenInsetsTest");
    f.setSize(260, 260);
    f.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            f.setVisible(false);
            System.exit(0);
        }
    });
    f.setBackground(Color.gray);
    Panel p1 = new Panel() {

        public Insets getInsets() {
            return INSETS1;
        }
    };
    p1.setLayout(null);
    p1.setSize(250, 250);
    Panel p = new Panel() {

        @Override
        public Insets getInsets() {
            return INSETS2;
        }

        public void paint(Graphics g) {
            // make sure Vista is done with its effects
            try {
                Thread.sleep(2000);
            } catch (InterruptedException ex) {
            }
            g.setColor(Color.red);
            g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
            g.setColor(Color.blue);
            g.fillRect(0, 0, getWidth() / 2, getHeight() / 2);
            Point p = getLocationOnScreen();
            try {
                Robot r = new Robot();
                BufferedImage bi = r.createScreenCapture(new Rectangle(p.x, p.y, getWidth() / 2, getHeight() / 2));
                for (int y = 0; y < bi.getHeight(); y++) {
                    for (int x = 0; x < bi.getWidth(); x++) {
                        if (bi.getRGB(x, y) != Color.blue.getRGB()) {
                            failed = true;
                            System.err.printf("Test failed at %d %d c=%x\n", x, y, bi.getRGB(x, y));
                            String name = "OverriddenInsetsTest_res.png";
                            try {
                                ImageIO.write(bi, "png", new File(name));
                                System.out.println("Dumped res to: " + name);
                            } catch (IOException e) {
                            }
                            return;
                        }
                    }
                }
            } catch (Exception e) {
                failed = true;
            } finally {
                lock.countDown();
            }
        }
    };
    p.setSize(200, 200);
    p1.add(p);
    p.setLocation(50, 50);
    f.add(p1);
    f.setVisible(true);
    try {
        lock.await();
    } catch (InterruptedException ex) {
        ex.printStackTrace();
    }
    if (args.length <= 0 || !"-show".equals(args[0])) {
        f.dispose();
    }
    if (failed) {
        throw new RuntimeException("Test FAILED.");
    }
    System.out.println("Test PASSED");
}
Also used : Frame(java.awt.Frame) Rectangle(java.awt.Rectangle) WindowAdapter(java.awt.event.WindowAdapter) Point(java.awt.Point) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) Point(java.awt.Point) IOException(java.io.IOException) Graphics(java.awt.Graphics) Panel(java.awt.Panel) WindowEvent(java.awt.event.WindowEvent) Robot(java.awt.Robot) File(java.io.File)

Aggregations

Panel (java.awt.Panel)70 BorderLayout (java.awt.BorderLayout)26 Button (java.awt.Button)25 Label (java.awt.Label)25 Frame (java.awt.Frame)18 GridBagLayout (java.awt.GridBagLayout)17 TextField (java.awt.TextField)17 GridBagConstraints (java.awt.GridBagConstraints)16 JPanel (javax.swing.JPanel)14 Dimension (java.awt.Dimension)13 Insets (java.awt.Insets)10 Point (java.awt.Point)10 Choice (java.awt.Choice)9 FlowLayout (java.awt.FlowLayout)9 Graphics (java.awt.Graphics)9 Checkbox (java.awt.Checkbox)7 GridLayout (java.awt.GridLayout)7 Font (java.awt.Font)6 JButton (javax.swing.JButton)6 Component (java.awt.Component)5