📄 laglangre.java
字号:
/*@author 邱宇峰 ,software project031,
*2004,9,19
*/
import java.awt.*;
import java.awt.event.*;
public class LagLangre extends Frame implements MouseListener,ActionListener{
static LagLangre frm=new LagLangre();
static Button b1;
static int array[][]=new int[30][2];
static int X=0;
static int count=0;
static double p=0;
public static void main(String[] args){
frm.setTitle("拉格朗日逼近法");
b1=new Button("start");
frm.add(b1,"South");
frm.setSize(500,500);
frm.setLocation(200,200);
frm.setVisible(true);
frm.addMouseListener(frm);
b1.addActionListener(frm);
frm.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}
});
}
public void mouseEntered(MouseEvent e){ }
public void mousePressed(MouseEvent e){ }
public void mouseExited(MouseEvent e){ }
public void mouseReleased(MouseEvent e){ }
/*this mouseevent is to get the basic spots
*/
public void mouseClicked(MouseEvent e){
Graphics g=getGraphics();
int x=e.getX();
int y=e.getY();
array[count][0]=x;array[count][1]=y;
g.drawString("。",x,y);
count++;
}
/*this actionevent is to draw the line
*/
public void actionPerformed(ActionEvent e){
Graphics g=getGraphics();
for(X=array[0][0];X<array[count-1][0];X++){
for(long h=0;h<5000000;h++);
double s=0;
for(int i=0;i<count;i++){
p=(double)array[i][1];
for(int j=0;j<count;j++){
if(j!=i) p=p*(((double)X-(double)array[j][0])/((double)array[i][0]-(double)array[j][0]));
}
s=s+p;
}
g.drawString(".",X,(int)s);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -