如何用摇摆画“生物危害” [英] How to draw 'biohazard' with swing

查看:142
本文介绍了如何用摇摆画“生物危害”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为即将到来的测试练习我的挥杆能力,而且油炸让我想到了这样的生物危害标志:




I'm practicing my swing abilities for the upcoming test, and fried gave me idea to draw biohazard sign like this :

alt text http://img62.imageshack.us/img62/8372/lab6b.gif

I could draw the circles with Elipse2D, but then I somehow need to cut those 3 triangles. Any ideas how I can do that ?

解决方案

You can use Java2D and canvas for this. The things that you may be using are, Circle and Arc. You should have three arcs with 30 degrees.

I tried using simple graphics over the frame.

Here is an attempt

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

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

public class Biohazard {
    public static void main(String[] args) {
        new Biohazard();
    }

    public Biohazard() {
        JFrame frame = new JFrame("Biohazard");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MyComponent());
        frame.setSize(260, 280);
        frame.setVisible(true);
    }

    public class MyComponent extends JComponent {
        public void paint(Graphics g) {
            int height = 120;
            int width = 120;
            g.setColor(Color.yellow);
            g.fillOval(60, 60, height, width);
            g.setColor(Color.black);
            g.drawOval(60, 60, height, width);

            int swivels = 6;
            int commonx, commony, commonh, commonw;

            for(int i=0;i<swivels;i++){
                commonx = commony = 120-i*10;
                commonh = commonw = i*20;
                g.drawArc(commonx, commony, commonh, commonw, 60 , 60);
                g.drawArc(commonx, commony, commonh, commonw, 180 , 60);
                g.drawArc(commonx, commony, commonh, commonw, 300 , 60);
            }
        }
    }
}

The original one : source code can be found at http://pastebin.com/HSNFx7Gq

这篇关于如何用摇摆画“生物危害”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆