// The copyright of this program is reserved by NL. /* Weierstrass function */ /* */ import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Ex061009c extends JApplet implements ActionListener{ boolean flag=false; double a=0.5; // Weierstrass functioňW double b=3.0; // Weierstrass functioňW double h=0.005; int num=0; JComboBox cb; String cbl[]={"n=0","n=1","n=2","n=3","n=4","n=5","n=6","n=7","n=8","n=9","n=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(20,160,600,160); g.drawLine(300,20,300,300); g.drawRect(20,20,560,280); g.setColor(Color.red); g.setFont(new Font("Dialog", Font.PLAIN,16)); g.drawString("-7",5,170); g.drawString(" 7",580,170); g.drawString(" 7",295,20); g.drawString("-7",295,315); if(flag==true) for(double x=-7.0;x<7.0;x+=h){ g.setColor(Color.green); g.drawLine((int)(x*40+300),160-(int)(Weierstrass(num,x)*80),(int)((x+h)*40+300),160-(int)(Weierstrass(num,x+h)*80)); } } public double Weierstrass(int n,double x){ double val=0.0; for(int i=0;i<=n;i++) val+=Math.pow(a,i)*Math.cos(Math.pow(b,i)*x); return(val); } }