import java.awt.*; import java.awt.event.*; import java.applet.*; public class Teljed4 extends Applet implements ActionListener{ double a=3; TextField tf1=new TextField(String.valueOf(a)); double b=5; TextField tf2=new TextField(String.valueOf(b)); double c=5; TextField tf3=new TextField(String.valueOf(c)); double d=5; TextField tf4=new TextField(String.valueOf(d)); double vanay; public Teljed4(){ add(tf1); add(tf2); add(tf3); add(tf4); tf1.addActionListener(this); tf2.addActionListener(this); tf3.addActionListener(this); tf4.addActionListener(this); } public void paint(Graphics g){ g.drawLine(100, 0, 100, getHeight()); g.drawLine( 0, 200, getWidth(), 200); int algx=-100; vanay=a*algx*algx*algx+b*algx*algx+c*algx+d; for(int x=algx; x<100; x++){ double y=a*x*x*x+b*x*x+c*x+d; if(y*vanay<=0){ g.drawOval((int)x+100-5, 200-5, 10, 10); } g.drawOval(x+100, 200-(int)y, 1, 1); vanay=y; } // double nullkoht=-b/a; // g.drawOval((int)nullkoht+100-5, 200-5, 10, 10); } public void actionPerformed(ActionEvent e){ a=Double.parseDouble(tf1.getText()); b=Double.parseDouble(tf2.getText()); c=Double.parseDouble(tf3.getText()); d=Double.parseDouble(tf4.getText()); repaint(); } public static void main(String argumendid[]){ Frame f=new Frame("Ruutfunktsiooni graafik"); f.add(new Teljed4()); f.setSize(250, 250); f.setVisible(true); } }