⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 monitor1.java.bak

📁 GoldSearch 黄金搜索算法 JAVA 制作
💻 BAK
字号:

import java.awt.*;
import java.awt.event.*;

class Monitor1 implements ActionListener{
	
    Monitor1(Frame f)
	{
		this.f=f;
	}
    private Frame f; 
	private double a=(-3.1415926)/2;
    private double b=(3.1415926)/2;
    private double e1=0.001;
    private double x1,x2,f1,f2,Xmax,Ymax;

    public void actionPerformed(ActionEvent e){
		
		x1=a+0.382*(b-a);
		x2=a+0.618*(b-a);
		Functor g3=new Functor();
		f1=g3.Functor(x1);
		f2=g3.Functor(x2);
		while((b-a)>e1)
		{
			if(f2>f1){ 
				a=x1;
				x1=x2;f1=f2;
				x2=a+0.618*(b-a);
				f2=g3.Functor(x2);
			}
			else{ 
				b=x2;x2=x1;f2=f1;
				x1=a+0.382*(b-a);
				f1=g3.Functor(x1);
			}
		}
		Xmax=(a+b)/2;
		Ymax=g3.Functor(Xmax);
		Graphics g4=f.getGraphics();
		g4.setColor(Color.yellow); 
		g4.fillOval((int)(Xmax*100+300-5),(int)(300-Ymax*100-50-5),10,10);
		g4.setColor(Color.magenta);
		g4.drawString("Congratulation !!!",(int)(Xmax*100+300-120),(int)(300-Ymax*100-50-25));
		g4.drawString("You find it !!!",(int)(Xmax*100+300-110),(int)(300-Ymax*100-50-5));
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -