MineralTea 2017-05-04 02:33 采纳率: 0%
浏览 792
已结题

一个关于java的画图问题

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

不会做。。有大神教下吗

  • 写回答

3条回答 默认 最新

  • coolingxyz 2017-05-04 02:41
    关注

    贴一个我以前写的,模拟光纤收发器面板的代码。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);
        }
    }
    

    }

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!