各位大哥:
    小弟在JFrame中画图,总是产生异常,请问你们是怎么在JFrame中画出一个圆的,请给出画一个圆的代码,小弟学习学习,谢谢!
   小弟在线等侯!!!!

解决方案 »

  1.   

    我已经加了个JPanel可是后面怎么操作,我不要很深的,只要能在JPanel上画出一个圆就行了!谢谢!
      

  2.   

    我自己写了一个,你运行试试!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);
      }
    }