public abstract void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
import java.awt.*; import javax.swing.*; public class Circle extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); g.drawArc(50, 50, 100, 100, 0, 360); } public static void main(String[] args) { JFrame frame = new JFrame("Circle Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200); Circle circle = new Circle(); frame.add(circle); frame.setVisible(true); } }
import java.awt.*; import javax.swing.*; public class Arc extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); g.drawArc(50, 50, 100, 100, 45, 90); } public static void main(String[] args) { JFrame frame = new JFrame("Arc Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200); Arc arc = new Arc(); frame.add(arc); frame.setVisible(true); } }This example draws an arc with a bounding rectangle of width 100 and height 100, with the top-left coordinates (50, 50) relative to the frame. The arc starts at an angle of 45 degrees and has an angular extent of 90 degrees. These examples demonstrate the usage of the drawArc method to draw different shapes on a graphical component using Java programming language.