📄 adapt.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Panel;
import java.io.*;
public class Adapt extends Frame implements ActionListener
{
private float a=0.5f,b=5.50f,e=0.01f,h;
Button bb;
public Adapt()
{
setLayout(new FlowLayout(FlowLayout.LEFT));
bb=new Button("DRAW");
add(bb);
setSize(700,500);
setBackground(Color.white);
bb.addActionListener(this);
}
public void paint(Graphics g)
{
float i,x;
g.drawLine(300,50,300,450);
g.drawLine(10,250,700,250);
for(i=a;i<=b;i=i+0.01f)
{
x=i-3.0f;
g.drawLine((int)(i*100),(int)(250-Fac(x)*100),(int)(i*100+1),(int)(250-Fac(x+0.01f)*100));
}
}
public float Fac(float x)//use after multiply 100,out same
{
float y;
if(x==0)y=0;
else
{
y=(float)(Math.sin(x)/x);
}
return y;
}
public void Scrawl(float AA,float HH)
{
int i=0,x1,x2,y1,y2;
float x;
Graphics g = getGraphics();
for(int j=0;j<500000000;j++){}
for(i=1;;i++)
{
x=AA+i*HH;
if(x>=b-3f)break;
x1=(int)(x*100)+300;
y1=(int)(250-Fac(x)*100);
x2=(int)(x*100)+300;
y2=250;
g.drawLine(x1,y1,x2,y2);
}
}
public void Metic(float A,float B,float E)
{
float H;
float T0,T1;
A=A-3f;
B=B-3f;
H=B-A;
T0=H*(Fac(A)+Fac(B))/2;
T1=T0/2+H*Fac(A+H/2)/2;
int n=1;
int k=1;
while(Math.abs(T1-T0)>=E)
{
H=H/2;
n=2*n;
T0=T1;
T1=0;
for(k=1;k<=n;k++)
{
T1=T1+Fac((float)(A+(k-0.5)*H));
}
T1=T0/2+H*T1/2;
Scrawl(A,H);
}
}
public void actionPerformed(ActionEvent eve)
{
if(eve.getSource()==bb)
{
Metic(a,b,e);
System.out.println("completed");
}
}
public static void main(String[] args)throws IOException
{
Adapt fuck=new Adapt();
fuck.setVisible(true);
/* InputStreamReader reader=new InputStreamReader(System.in);
BufferedReader input=new BufferedReader(reader);
String text=input.readLine();
a=new Float(text).floatValue();
text=input.readLine();
b=new Float(text).floatValue();
text=input.readLine();
e=new Float(text).floatValue();*/
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -