标签:
最近一直没有空写博客,事情比较多,静不下心,事情顺其自然好了,有些事我也不懂为什么会变成现在这样,你以为你付出了你最珍贵的,但或许别人并不喜欢。算了,不多想,顺其自然好了。
JAVA在图形绘制方面效率跟不上C++,但是我觉得JAVA也有其在图形方面的一些优势,不过对于大型桌面游戏就不行了,估计连流畅度都不能保证。
下面给出最近写的代码:
package draw;
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
public class DrawTest
{
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
JFrame frame=new DrawFrame();
frame.setTitle("Draw");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
class DrawFrame extends JFrame
{
public DrawFrame()
{
add(new DrawComponent());
pack();
}
}
class DrawComponent extends JComponent
{
private static final int DEFAULT_WIDTH=400;
private static final int DEFAULT_HEIGHT=400;
public void paintComponent(Graphics g)
{
Graphics2D g2=(Graphics2D) g;
double leftX=100;
double topY=100;
double width=200;
double height=150;
Rectangle2D rect=new Rectangle2D.Double(leftX,topY,width,height);
g2.draw(rect);
Ellipse2D ellipse=new Ellipse2D.Double();
ellipse.setFrame(rect);
g2.draw(ellipse);
g2.draw(new Line2D.Double(leftX,topY,width,height));
double centerX=rect.getCenterX();
double centerY=rect.getCenterY();
double radius=150;
Ellipse2D circle=new Ellipse2D.Double(centerX,centerY,centerX+radius,centerY+radius);
circle.setFrameFromCenter(centerX,centerY,centerX+radius,centerY+radius);
g2.draw(circle);
}
public Dimension getPreferredSize()
{
return new Dimension(DEFAULT_WIDTH,DEFAULT_HEIGHT);
}
}

这是效果图,我正在考虑要不要用JAVA来做GUI,然后来调用我之前项目中写的一些DLL文件,这样导师让我做的界面就很容易了,本来导师让我用OpenGL做界面,感觉那样这不就是开发一个微型Swing或者WPF吗。。。
标签:
原文地址:http://www.cnblogs.com/northsnow95/p/5565533.html