Java AWT Graphics draw oval

Description

Java AWT Graphics draw oval


import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main extends JPanel {
  @Override//from w w w.ja  v a  2 s . com
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    this.setBackground(Color.WHITE);

    g.setColor(Color.MAGENTA);
    g.drawOval(15, 10, 90, 55);
    g.fillOval(20, 10, 90, 55);
  }

  public static void main(String[] args) {
    // create frame for Main
    JFrame frame = new JFrame("Drawing ovals");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Main Main = new Main();
    Main.setBackground(Color.WHITE);
    frame.add(Main);
    frame.setSize(400, 210);
    frame.setVisible(true);
  }
}



PreviousNext

Related