我正在为即将到来的测试练习我的挥杆能力,并且油炸让我想到了这样的生物危害标志:
alt text http://img62.imageshack.us/img62/8372/lab6b.gif
我可以用Elipse2D绘制圆圈,但是我不知何故需要剪切这3个三角形。我有什么想法可以做到吗?
答案 0 :(得分:5)
您可以使用Java2D和canvas。你可能正在使用的东西是Circle和Arc。你应该有三个30度的弧。
我尝试在框架上使用简单的图形。
这是一次尝试
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);
}
}
}
}
原始的:源代码可以在http://pastebin.com/HSNFx7Gq
找到答案 1 :(得分:3)
您可以使用Arc2D
类通过以度为单位指定start
和extent
参数来绘制每一行。
答案 2 :(得分:1)
也许这实际上非常简单(我不确定Swing API如何处理行)。画出从中心到圆周圆点的线条,然后跳过这些部分进行线条绘制。