Search in sources :

Example 26 with Graphics

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

the class ControlCharacter method createAndShowGUI.

static void createAndShowGUI() {
    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();
        }
    };
    panel.addKeyListener(new KeyListener());
    frame.add(panel);
    lock.lock();
    frame.setVisible(true);
    panel.requestFocusInWindow();
    try {
        isPainted.await();
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } finally {
        lock.unlock();
    }
}
Also used : Graphics(java.awt.Graphics) Panel(java.awt.Panel) Frame(java.awt.Frame)

Example 27 with Graphics

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

the class TexturePaintPrintingTest method doPaint.

public void doPaint(Graphics2D g2d) {
    BufferedImage patternImage = new BufferedImage(2, 2, BufferedImage.TYPE_INT_ARGB);
    Graphics gImage = patternImage.getGraphics();
    gImage.setColor(Color.WHITE);
    gImage.drawLine(0, 1, 1, 0);
    gImage.setColor(Color.BLACK);
    gImage.drawLine(0, 0, 1, 1);
    gImage.dispose();
    Rectangle2D.Double shape = new Rectangle2D.Double(0, 0, DIM * 6 / 5, DIM * 8 / 5);
    g2d.setPaint(new TexturePaint(patternImage, new Rectangle2D.Double(0, 0, DIM * 6 / 50, DIM * 8 / 50)));
    g2d.fill(shape);
    g2d.setPaint(Color.BLACK);
    g2d.draw(shape);
}
Also used : Graphics(java.awt.Graphics) TexturePaint(java.awt.TexturePaint) Rectangle2D(java.awt.geom.Rectangle2D) BufferedImage(java.awt.image.BufferedImage)

Example 28 with Graphics

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

the class GifTransparencyTest method show.

public void show() {
    JPanel p = new JPanel(new BorderLayout()) {

        public void paintComponent(Graphics g) {
            g.setColor(Color.blue);
            g.fillRect(0, 0, getWidth(), getHeight());
        }
    };
    p.add(new ImageComponent(src), BorderLayout.WEST);
    if (dst != null) {
        p.add(new ImageComponent(dst), BorderLayout.EAST);
    }
    JFrame f = new JFrame("Transparency");
    f.add(p);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
}
Also used : Graphics(java.awt.Graphics) JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame)

Example 29 with Graphics

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

the class HiDPIRobotScreenCaptureTest method main.

public static void main(String[] args) throws Exception {
    try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception e) {
        return;
    }
    Frame frame = new Frame();
    frame.setBounds(40, 30, 400, 300);
    frame.setUndecorated(true);
    Panel panel = new Panel(new BorderLayout());
    Canvas canvas = new Canvas() {

        @Override
        public void paint(Graphics g) {
            super.paint(g);
            int w = getWidth();
            int h = getHeight();
            g.setColor(COLORS[0]);
            g.fillRect(0, 0, w / 2, h / 2);
            g.setColor(COLORS[1]);
            g.fillRect(w / 2, 0, w / 2, h / 2);
            g.setColor(COLORS[2]);
            g.fillRect(0, h / 2, w / 2, h / 2);
            g.setColor(COLORS[3]);
            g.fillRect(w / 2, h / 2, w / 2, h / 2);
        }
    };
    panel.add(canvas);
    frame.add(panel);
    frame.setVisible(true);
    Robot robot = new Robot();
    robot.waitForIdle();
    Thread.sleep(200);
    Rectangle rect = canvas.getBounds();
    rect.setLocation(canvas.getLocationOnScreen());
    BufferedImage image = robot.createScreenCapture(rect);
    frame.dispose();
    int w = image.getWidth();
    int h = image.getHeight();
    if (w != frame.getWidth() || h != frame.getHeight()) {
        throw new RuntimeException("Wrong image size!");
    }
    if (image.getRGB(w / 4, h / 4) != COLORS[0].getRGB()) {
        throw new RuntimeException("Wrong image color!");
    }
    if (image.getRGB(3 * w / 4, h / 4) != COLORS[1].getRGB()) {
        throw new RuntimeException("Wrong image color!");
    }
    if (image.getRGB(w / 4, 3 * h / 4) != COLORS[2].getRGB()) {
        throw new RuntimeException("Wrong image color!");
    }
    if (image.getRGB(3 * w / 4, 3 * h / 4) != COLORS[3].getRGB()) {
        throw new RuntimeException("Wrong image color!");
    }
}
Also used : Graphics(java.awt.Graphics) Panel(java.awt.Panel) Frame(java.awt.Frame) BorderLayout(java.awt.BorderLayout) Canvas(java.awt.Canvas) Rectangle(java.awt.Rectangle) Robot(java.awt.Robot) BufferedImage(java.awt.image.BufferedImage)

Example 30 with Graphics

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

the class MultiResolutionSplashTest method getScaleFactor.

static float getScaleFactor() {
    final Dialog dialog = new Dialog((Window) null);
    dialog.setSize(100, 100);
    dialog.setModal(true);
    final float[] scaleFactors = new float[1];
    Panel panel = new Panel() {

        @Override
        public void paint(Graphics g) {
            float scaleFactor = 1;
            if (g instanceof SunGraphics2D) {
                scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
            }
            scaleFactors[0] = scaleFactor;
            dialog.setVisible(false);
        }
    };
    dialog.add(panel);
    dialog.setVisible(true);
    dialog.dispose();
    return scaleFactors[0];
}
Also used : Graphics(java.awt.Graphics) Panel(java.awt.Panel) Dialog(java.awt.Dialog) SunGraphics2D(sun.java2d.SunGraphics2D)

Aggregations

Graphics (java.awt.Graphics)217 BufferedImage (java.awt.image.BufferedImage)104 Dimension (java.awt.Dimension)35 Point (java.awt.Point)32 Graphics2D (java.awt.Graphics2D)31 Color (java.awt.Color)28 JPanel (javax.swing.JPanel)22 Insets (java.awt.Insets)21 Rectangle (java.awt.Rectangle)21 JLabel (javax.swing.JLabel)19 BorderLayout (java.awt.BorderLayout)18 File (java.io.File)18 FontMetrics (java.awt.FontMetrics)16 Frame (java.awt.Frame)16 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)16 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)16 Component (java.awt.Component)15 Font (java.awt.Font)15 GridBagLayout (java.awt.GridBagLayout)15 JScrollPane (javax.swing.JScrollPane)15