Example usage for java.awt Graphics fillOval

List of usage examples for java.awt Graphics fillOval

Introduction

In this page you can find the example usage for java.awt Graphics fillOval.

Prototype

public abstract void fillOval(int x, int y, int width, int height);

Source Link

Document

Fills an oval bounded by the specified rectangle with the current color.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    int size = 120;
    int pad = 10;
    BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.createGraphics();
    g.setColor(Color.WHITE);/*from ww w .java  2s.co  m*/
    g.fillRect(0, 0, size, size);
    g.setColor(Color.YELLOW);
    g.fillOval(pad, pad, size - (2 * pad), size - (2 * pad));
    g.dispose();

    BufferedImage image2 = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_BYTE_GRAY);

    ColorConvertOp op = new ColorConvertOp(bi.getColorModel().getColorSpace(),
            image2.getColorModel().getColorSpace(), null);
    op.filter(bi, image2);
    ImageIO.write(image2, "png", new File("c:/Java_Dev/image2.png"));
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame();
    f.add(new JComponent() {
        public void paintComponent(Graphics g) {

            // Some parameters.
            String text = "Some Label";
            int centerX = 150, centerY = 100;
            int ovalWidth = 200, ovalHeight = 100;

            // Draw oval
            g.setColor(Color.BLUE);
            g.fillOval(centerX - ovalWidth / 2, centerY - ovalHeight / 2, ovalWidth, ovalHeight);

            // Draw centered text
            FontMetrics fm = g.getFontMetrics();
            double textWidth = fm.getStringBounds(text, g).getWidth();
            g.setColor(Color.WHITE);
            g.drawString(text, (int) (centerX - textWidth / 2), (int) (centerY + fm.getMaxAscent() / 2));

        }//from w w w  . j  a  va2 s . co m
    });

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(300, 300);
    f.setVisible(true);
}

From source file:SystemTrayDemo1.java

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        return;/*from   ww w.j a  v a2  s.c  om*/
    }
    SystemTray tray = SystemTray.getSystemTray();

    PropertyChangeListener pcl;
    pcl = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent pce) {
            System.out.println("Property changed = " + pce.getPropertyName());
            TrayIcon[] tia = (TrayIcon[]) pce.getOldValue();
            if (tia != null) {
                System.out.println("Old tray icon array contents: ");
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
                System.out.println();
            }

            tia = (TrayIcon[]) pce.getNewValue();
            if (tia != null) {
                System.out.println("New tray icon array contents: ");
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
                System.out.println();
            }
        }
    };
    tray.addPropertyChangeListener("trayIcons", pcl);

    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);

    TrayIcon icon = null;
    tray.add(icon = new TrayIcon(bi));

    Thread.sleep(3000);
    tray.remove(icon);

    Thread.sleep(3000);
    System.exit(0);
}

From source file:SystemTrayDemo2.java

public static void main(String[] args) {
    if (!SystemTray.isSupported()) {
        return;// www. java  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);
    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:components.FrameDemo2.java

protected static Image createFDImage() {
    //Create a 16x16 pixel image.
    BufferedImage bi = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);

    //Draw into it.
    Graphics g = bi.getGraphics();
    g.setColor(Color.BLACK);/*from  w w  w  .j  av a2 s.c  o m*/
    g.fillRect(0, 0, 15, 15);
    g.setColor(Color.RED);
    g.fillOval(5, 3, 6, 6);

    //Clean up.
    g.dispose();

    //Return it.
    return bi;
}

From source file:FrameDemo2.java

protected static Image createFDImage() {
    // Create a 16x16 pixel image.
    BufferedImage bi = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);

    // Draw into it.
    Graphics g = bi.getGraphics();
    g.setColor(Color.BLACK);/*from ww w  . ja  v a2  s . c om*/
    g.fillRect(0, 0, 15, 15);
    g.setColor(Color.RED);
    g.fillOval(5, 3, 6, 6);

    // Clean up.
    g.dispose();

    // Return it.
    return bi;
}

From source file:edu.ku.brc.ui.GraphicsUtils.java

/**
 * Draws a filled circle using the given graphics context, centered at <code>(x,y)</code>,
 * having the given diameter.//from w  w  w .  jav a2  s. c o m
 * 
 * @see #drawCircle(Graphics, int, int, int)
 * @param g the graphics context to draw in
 * @param x the x coordinate for the center of the circle
 * @param y the y coordinate for the center of the circle
 * @param diameter the diameter of the circle
 */
public static void fillCircle(Graphics g, int x, int y, int diameter) {
    ((Graphics2D) g).addRenderingHints(hints);
    g.fillOval(x - diameter / 2, y - diameter / 2, diameter, diameter);
}

From source file:Main.java

public void paint(Graphics g) {

    g.fillOval(25, 25, 120, 120);
}

From source file:MainClass.java

public void paint(Graphics g) {
    g.fillOval(25, 25, 120, 120);

}

From source file:MainClass.java

public void paint(Graphics g) {
    g.setColor(Color.yellow);
    g.fillOval(5, 15, 50, 75);
}