import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; public class Siinus extends JApplet implements Runnable, ActionListener{ int raadius=50; int kiirus=3; int algus=0; int y_nullkoht=150; BufferedImage pilt=new BufferedImage(800,300,BufferedImage.TYPE_INT_RGB); TextField tf_kiirus=new TextField("3",1); TextField tf_raadius=new TextField("50",2); public Siinus(){ new Thread(this).start(); Panel p=new Panel(new FlowLayout()); p.add(new Label("kiirus")); p.add(tf_kiirus); p.add(new Label("raadius")); p.add(tf_raadius); tf_raadius.addActionListener(this); tf_kiirus.addActionListener(this); getContentPane().add(p, BorderLayout.NORTH); } public void paint(Graphics g){ Graphics graafika=pilt.getGraphics(); graafika.setColor(Color.white); graafika.fillRect(0,0,getSize().width,getSize().height); graafika.setColor(Color.black); joonistaTeljed(graafika); joonistaGraafik(graafika); joonistaRing(graafika); g.drawImage(pilt,0,0,this); } public void joonistaGraafik(Graphics g){ for(int i=algus;i<=(algus+360);i++){ int y_k=y_nullkoht-(int)(raadius*Math.sin(Math.toRadians(i))); int x_k=i+(100-algus); g.drawLine(x_k,y_k,x_k,y_k); } } public void joonistaRing(Graphics g){ int punkt_x=(int)(raadius*(Math.sin(Math.toRadians(algus+90)))); int punkt_y=(int)(raadius*(Math.cos(Math.toRadians(algus+90)))); g.fillOval(650+punkt_x,150+punkt_y,10,10); g.drawOval(650-(raadius-5),150-(raadius-5),2*raadius, 2*raadius); g.setColor(Color.white); g.drawOval(650+(punkt_x-1),150+(punkt_y-1),10,10); g.setColor(Color.black); } public void run(){ while(true){ repaint(); algus+=kiirus; try{Thread.sleep(10);}catch(Exception erind){} } } public void actionPerformed(ActionEvent e){ kiirus=Integer.parseInt(tf_kiirus.getText()); raadius=Integer.parseInt(tf_raadius.getText()); } public void joonistaTeljed(Graphics g){ Graphics2D g2=(Graphics2D)g; //x telg g.setFont(new Font("arial",Font.PLAIN,9)); g.drawLine(50, 150, 500, 150 ); g.drawLine(500,150,495,145); g.drawLine(500,150,495,155); //y telg g.drawLine(100,75,100,225); g.drawLine(100,75,95,80); g.drawLine(100,75,105,80); //skaala x g.drawString("0",100,160); for(int i=2;i<=36;i+=2){ g.drawString(i+"0",100+(i*10),160); g.drawLine(100+(i*10),148,100+(i*10),152); } //skaala y g.drawString("1",95,100); g.drawString("-1",90,200); } public static void main(String[] args){ JFrame f=new JFrame("Siinus"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(800,400); f.getContentPane().add(new Siinus()); f.setVisible(true); } }