import javax.swing.*;
import java.awt.*;
class KanvasAnimasi extends Canvas
{
public void paint(Graphics g)
{
g.setColor(Color.black);
g.drawLine(10,10,10,210);
g.drawLine(5,110,380,110);
g.drawString("1",2,14);
g.drawString("-1",14,210);
g.drawString("0",13,123);
g.drawString("90",100,123);
g.drawString("180",190,123);
g.drawString("270",280,123);
g.drawString("360",370,123);
g.setColor(Color.red);
for(int i=0; i<360; i+=1)
{
int y=(int) (Math.sin(i*Math.PI/180)*100)*-1;
g.drawOval(i+10,y+110,1,1);
try
{
Thread.sleep(10);
}
catch(Exception e)
{
}
}
g.setColor(Color.blue);
for(int i=0; i<360; i+=1)
{
int y=(int) (Math.cos(i*Math.PI/180)*100)*-1;
g.drawOval(i+10,y+110,1,1);
try
{
Thread.sleep(10);
}
catch(Exception e)
{
}
}
}
}
class Animasi extends JFrame
{
KanvasAnimasi gambar=new KanvasAnimasi();
Animasi()
{
setTitle("Plotting Fungsi Sinus dan Cosinus ");
setLocation(200,100);
setSize(400,260);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void KomponenVisual()
{
getContentPane().setLayout(new BorderLayout());
getContentPane().add(gambar, BorderLayout.CENTER);
setVisible(true);
}
public static void main (String[] args)
{
Animasi anime=new Animasi();
anime.KomponenVisual();
}
}
0 comments:
Post a Comment