📄 func.java
字号:
package mp3_test2;
import java.awt.*;
import java.util.*;
import javax.swing.*;
public class Func extends JPanel implements Runnable{
int move=5;
public Thread thread;
Func(){
this.setPreferredSize(new Dimension(200,300));
show();
thread=new Thread(this);
thread.start();
}
double f(double x) {
double a= (4*Math.sin(5*x)-2);
if(a>=0)
return a;
else return 0;
}
public void run(){
while(true){
try{
repaint();
move+=10;
thread.sleep(500);
}catch (InterruptedException ex){ex.printStackTrace();}
}
}
public void paint(Graphics g) {
g.clearRect(0,0,getSize().width,getSize().height);
double x0,x1,y0,y1,xd,yd;
double max=5.0;
int w,h,hw,hh;
w=getSize().width;
h=getSize().height;
hw=w/2; hh=h/2;
g.setColor(Color.red);
g.drawLine(0,hh,w,hh);
xd=2*max/w;
yd=hh/max;
g.setColor(Color.blue);
for (int x=0 ; x<w-1; x++) {
x0=-max+(x+move)*xd; y0=f(x0)*yd;
x1=x0+xd; y1=f(x1)*yd;
g.drawLine(x,(int)(hh-y0),x+1,(int)(hh-y1));
}
g.setColor(Color.white);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -