package com032401;
例子:
例子:
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class DrawListener implements MouseListener{
private double x1,x2,y1,y2;
private int x,y;
public static float a=1.7f,b=1.7f,c=0.06f,d=1.2f;
Graphics g;
public DrawListener(Graphics g){
this.g=g;
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
System.out.print("ssss");
this.Draw(e);
}
public void Draw(MouseEvent e){
for(int i=0;i<500000;i++){
x2=Math.sin(a*y1)+c*Math.cos(a*x1);
y2=Math.sin(b*x1)+d*Math.cos(b*y1);
x1=x2;
y1=y2;
x=(int)(x1*100)+500;
y=(int)(y1*100)+400;
g.drawLine(x, y, x, y);
}
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
}
}
package com032401;
import java.awt.FlowLayout;
import java.awt.Graphics;
import javax.swing.JFrame;
import com032401.DrawBorder;
import com032401.DrawListener;
public class DrawBorder extends JFrame{
//定义主函数
public static void main(String[] args){
//实例化DrawBorder类的对象
DrawBorder db=new DrawBorder();
//调用initUI函数
db.initUI();
}
//定义一个initUI函数
public void initUI(){
//设置属性值
this.setTitle("");
this.setSize(800, 900);
this.setDefaultCloseOperation(3);
this.setResizable(true);
this.setLocationRelativeTo(null);
this.setLayout(new FlowLayout());
this.setVisible(true);
Graphics g=this.getGraphics();
DrawListener d=new DrawListener(g);
this.addMouseListener(d);
}
}