一个关于java的画图问题

,编写PaintExample类,要求继承JFrame,在窗口的中间位置画一个半径为30,填充色为蓝色的圆.

不会做。。有大神教下吗

贴一个我以前写的,模拟光纤收发器面板的代码。qq:21156410 http://xu-laoshi.cn

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
import java.net.URL;
import java.net.MalformedURLException;

public class Mb extends Applet//机架面板
{
Color BkColor=new Color(9,76,254);
final Color[] mycolor={new Color(0,255,0),new Color(198,195,198)};//0在线 1下线
String ip;
String JjNo;
String ledvalue;
String stylevalue;
public void init()
{
ip=getParameter("ip");
JjNo=getParameter("JjNo");
this.setLayout(new GridLayout(1,16));
for(int i=0;i<16;i++)
{
stylevalue=getParameter("style"+Integer.toString(i));
ledvalue=getParameter("led"+Integer.toString(i));
if (stylevalue == null) {
stylevalue = "255";
}
if (ledvalue == null){
ledvalue = "255";
}
add(new CcMb(i,stylevalue,ledvalue));
}
}

public boolean openurl(String avg)
{
    URL url;
    try
    {
        url = new URL("http://"+ip+"/cgi-bin/ccmain?jjno="+JjNo+"&ccno="+avg);
    }
    catch(MalformedURLException _ex)
    {
        System.out.println("URL not found.");
        return true;
    }
    getAppletContext().showDocument(url, "_blank");
    return true;
}

class CcMb extends JPanel implements ActionListener//插槽面板
{
    Button JjIndex=null;
    Label JjIdx=null;
    final String[] CcStyle={"第1型号","第2型号","第3型号"};
    String ledvalue;
    int temp;

    public CcMb(int j, String style, String led)
    {
        temp=Integer.valueOf(led).intValue();
        ledvalue=Integer.toBinaryString(temp);
        while(ledvalue.length()<8){
            ledvalue="0"+ledvalue;
        }

// this.add(new Label(ledvalue));}//////////////

        this.setBackground(BkColor);
        this.setLayout(new GridLayout(5,1));
        this.setBorder(BorderFactory.createLineBorder(Color.gray));
        if(Integer.parseInt(style)<16)
        {
            JjIndex=new Button(Integer.toString(j));
            JjIndex.setBackground(BkColor);
            JjIndex.addActionListener(this);
            if(Integer.parseInt(style)==1)//自适应
            {
                add(JjIndex);
                add(new FxPanel("电口 0",ledvalue.charAt(5)));//5
                add(new FxPanel("电口 1",ledvalue.charAt(4)));//4
                add(new sixLedPanel1(style,ledvalue));
                add(new LxPanel("光口",ledvalue.charAt(3)));//3
            }
            else if(Integer.parseInt(style)==2)//100M
            {
                add(JjIndex);
                add(new Label(""));
                add(new FxPanel("电口",ledvalue.charAt(4)));//4
                add(new sixLedPanel2(style,ledvalue));
                add(new LxPanel("光口",ledvalue.charAt(3)));//3
            }
        }else
        {
            JjIdx=new Label(Integer.toString(j));
            add(JjIdx);
        }
    }


    public void actionPerformed(ActionEvent ev)
    {
        String label=ev.getActionCommand();
        openurl(label);
    }
}

class FxPanel extends JPanel//电口
{
    int cl=1;
    public FxPanel(String hint,char colorindex)
    {
        if(colorindex=='1')
            cl=0;
        this.setBackground(BkColor);
        this.setToolTipText(hint);
    }

    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        g.setColor(mycolor[cl]);
        g.fill3DRect(5,5,20,30,false);
        g.fill3DRect(25,10,5,20,false);
    }
}

class LxPanel extends JPanel//光口
{
    int cl=1;
    public LxPanel(String hint,char colorindex)
    {
        if(colorindex=='1')
            cl=0;
        this.setBackground(BkColor);
        this.setToolTipText(hint);
    }

    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        g.setColor(mycolor[cl]);
        g.fill3DRect(5,5,25,35,false);
        g.fillArc(12,10,10,10,0,360);
        g.fillArc(12,25,10,10,0,360);
    }
}

class sixLedPanel1 extends JPanel//6个灯 自适应
{
    public sixLedPanel1(String sty,String led)
    {
        this.setBackground(new Color(9,76,254));
        this.setLayout(new GridLayout(2,3));
        add(new LedPanel("SPD 1",led.charAt(6)));//6
        add(new LedPanel("SPD 0",led.charAt(7)));//7
        add(new LedPanel("电源",'1'));
        add(new LedPanel("电口 1 Link",led.charAt(4)));//4
        add(new LedPanel("电口 0 Link",led.charAt(5)));//5
        add(new LedPanel("光口Link",led.charAt(3)));//3
    }
}

class sixLedPanel2 extends JPanel//6个灯 100M
{
    public sixLedPanel2(String sty,String led)
    {
        this.setBackground(new Color(9,76,254));
        this.setLayout(new GridLayout(2,3));
        add(new LedPanel("TP_TX",led.charAt(6)));//6
        add(new LedPanel("光口Link",led.charAt(3)));//3
        add(new LedPanel("FDXLED",led.charAt(7)));//7
        add(new LedPanel("FX-T",led.charAt(5)));//5
        add(new LedPanel("电口Link",led.charAt(4)));//4
        add(new LedPanel("电源",'1'));
    }
}

class LedPanel extends JPanel//一个灯
{
    int ledx,ledy,ledr;
    int cd=1;
    public LedPanel(String hint,char clindex)
    {
        if(clindex=='1')
            cd=0;
        this.setBackground(BkColor);
        this.setToolTipText(hint);
    }

    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        g.setColor(mycolor[cd]);
        g.fillArc(0,0,8,8,0,360);
    }
}

}

有很多办法能实现,可以用如下代码:

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

import javax.swing.JComponent;
import javax.swing.JFrame;

public class Demo extends JFrame {

    public Demo() {
        setSize(400, 400);//JFrame的尺寸
        add(new CirclePanel());
        setLocationRelativeTo(null);
        setVisible(true);
    }

    public static void main(String[] args) {
        Demo c = new Demo();
    }
}

class CirclePanel extends JComponent {
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.BLUE);
        g.fillOval((getWidth()-30)/2,(getHeight()-30)/2, 30, 30);//在中心绘制
    }
}

图片说明

http://bbs.csdn.net/topics/390414963 这是一个大牛,画的太极,不知道能不能帮上你