我自己写了一个,你运行试试!import java.awt.*; import java.awt.geom.*; import javax.swing.*;public class DrawCircle { public static void main(String[] args) { DrawFrame frame = new DrawFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.show(); } }class DrawFrame extends JFrame { public DrawFrame() { setTitle("Circle"); setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
DrawPanel panel = new DrawPanel(); Container contentPane = getContentPane(); contentPane.add(panel); } public static final int DEFAULT_WIDTH = 400; public static final int DEFAULT_HEIGHT = 400; }class DrawPanel extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g;
Ellipse2D circle = new Ellipse2D.Double(); circle.setFrameFromCenter(200,200,350,350); g2.draw(circle); } }
import java.awt.geom.*;
import javax.swing.*;public class DrawCircle {
public static void main(String[] args)
{
DrawFrame frame = new DrawFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}class DrawFrame extends JFrame
{
public DrawFrame()
{
setTitle("Circle");
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
DrawPanel panel = new DrawPanel();
Container contentPane = getContentPane();
contentPane.add(panel);
}
public static final int DEFAULT_WIDTH = 400;
public static final int DEFAULT_HEIGHT = 400;
}class DrawPanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
Ellipse2D circle = new Ellipse2D.Double();
circle.setFrameFromCenter(200,200,350,350);
g2.draw(circle);
}
}