import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.applet.Applet; public class Poordvordeline extends Applet implements ActionListener{ double A=0; TextField a=new TextField(""+0); Button nupp=new Button(" OK "); public Poordvordeline(){ setLayout(null); a.setBounds(340, 5, 30, 20); nupp.setBounds(410, 5, 40, 20); add(a); add(nupp); nupp.addActionListener(this); } public void paint(Graphics g){ g.setColor(Color.blue); g.drawString("y =", 320, 20); g.drawString("/x", 375, 20); for(int i=0; i<20; i++){ g.setColor(Color.gray); g.drawLine(0+30*i, 0, 0+30*i, 600); //y- telge pidi g.drawLine(0, 0+30*i, 600, 0+30*i); //x- telge pidi } //teljestik g.setColor(Color.black); g.drawLine(300, 0, 300, 600); //y- telg g.drawLine(0, 300, 600, 300); //x- telg for(int i=0; i<20; i++){ g.drawLine(0+i*30, 295, 0+i*30, 305); //x- telg kriipsud g.drawLine(295, 0+i*30, 305, 0+i*30); //y- telg kriipsud for(int nr=0; nr<10; nr++){ g.drawString(nr-10+"", 305, 600-nr*30); g.drawString(nr+1+"", 305, 270-nr*30); g.drawString(nr+1+"", 330+nr*30, 295); g.drawString(nr-10+"", 0+nr*30, 295); g.drawString(0+"", 305, 295); } } //teljestiku osa lõpp //graafiku joonistamine g.setColor(Color.blue); double vanax=0; double vanay=300-(A/-300*900); for(int d=-300; d<=300; d++){ double uusx=300+d; double uusy=300-(A/d*900); //Graphics2D ga=(Graphics2D)g; // GeneralPath gp=new GeneralPath(); // gp.append(new Line2D.Double(vanax, vanay, uusx, uusy), false); // ga.draw(gp); if((300-vanay)*(300-uusy)>0){ g.drawLine((int)vanax, (int)vanay, (int)uusx, (int)uusy); } vanax=uusx; vanay=uusy; } } public void actionPerformed(ActionEvent e){ A=Double.parseDouble(a.getText().replace(',', '.')); repaint(); } public static void main(String argumendid[]){ Frame f=new Frame("Poordvordeline"); f.add(new Poordvordeline()); f.setSize(600, 600); f.setVisible(true); f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); } }