Applet小应用程序绘制笛卡尔积曲线
package com.dhcc.example;
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/**
* @公司 东华软件股份公司
* @作者 张友学
* @来源 互联网
* @时间 2013-08-14 15:58
* @描述 Applet小应用程序绘制笛卡尔积曲线
*/
public class Descartes extends Applet
{
int AppletWidth,AppletHeight;
Image OffScreen;
Graphics drawOffScreen;
public void init(){
setBackground(Color.black);
AppletWidth = getSize().width;
AppletHeight = getSize().height;
OffScreen = createImage(AppletWidth,AppletHeight);
drawOffScreen = OffScreen.getGraphics();
}
public void paint(Graphics g){
drawOffScreen.clearRect(0,0,AppletWidth,AppletHeight);
drawOffScreen.setColor(Color.white);
int i,j;
double x,y,r;
for ( i = 0; i <= 90; i++ )
for ( j = 0; j <= 90; j++ )
{
r=Math.PI/45*i*(1-Math.sin(Math.PI/45*j))*18;
x=r*Math.cos(Math.PI/45*j)*Math.sin(Math.PI/45*i)
+AppletWidth/2;
y=-r*Math.sin(Math.PI/45*j)+AppletHeight/4;
drawOffScreen.fillOval((int)x,(int)y,2,2);
}
g.drawImage(OffScreen,0,0,this);
}
public static void main(String[] args){
Descartes applet = new Descartes ();
JFrame frame = new JFrame("这是一个applet转化的application");
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
frame.getContentPane().add(applet);
frame.setSize(600,500);
frame.setVisible(true);
applet.init();
applet.start();
}
//添加main函数后,本程序既是applet又是application。
}
运行效果: