// The copyright of this program is reserved by NL. /* Tschebyscheff ̑ */ /* */ import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Ex061009a extends JApplet implements ActionListener{ boolean flag=false; double h=0.01; JComboBox cb; int num = 1; String cbl[]={"k=0","k=1","k=2","k=3","k=4","k=5","k=6","k=7","k=8","k=9","k=10"}; public void init(){ Container cp = getContentPane(); JPanel pl = new JPanel(); pl.setBackground(Color.black); pl.setLayout(null); cb = new JComboBox(cbl); cb.setBounds(0,0,60,20); cb.setSelectedIndex(0); cb.addActionListener(this); pl.add(cb); cp.add(pl); } public void actionPerformed(ActionEvent event){ num = cb.getSelectedIndex(); flag=true; repaint(); } public void paint(Graphics g){ super.paint(g); g.setColor(Color.blue); g.drawLine(50,150,250,150); g.drawLine(150,50,150,250); g.drawRect(50,50,200,200); g.setColor(Color.red); g.setFont(new Font("Dialog", Font.PLAIN,20)); g.drawString("-1",30,160); g.drawString("1",260,160); g.drawString(" 1",140,40); g.drawString("-1",140,270); if(flag==true) for(double x=-1.0;x<1.0;x+=h){ g.setColor(Color.green); g.drawLine((int)(x*100+150),150-(int)(tschebyscheff(num,x)*100),(int)((x+h)*100+150),150-(int)(tschebyscheff(num,x+h)*100)); } } public double tschebyscheff(int n,double x){ if(n==0) return(1.0); if(n==1) return(x); return(tschebyscheff(n-1,x)*2.0*x-tschebyscheff(n-2,x)); } }