import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
public class MyGraphic5 extends java.applet.Applet implements ActionListener
{
boolean go =false;
int x, oldx, y, oldy;
double angle;
Button drawButton =new Button("Draw");
public void init()
{
add(drawButton);
drawButton.addActionListener(this);
}
public void paint(Graphics screen)
{
resize(500,500);
int x,y, oldx, oldy;
double i=0;
double a=0;
double b=0;
oldx=250;
oldy=250;
double ang=0;
//oldx=(int)(a*Math.cos(i)+250);
//oldy=(int)(b*Math.sin(i)+250);
double angle;
x=1;
if (go==true)
{
for (i=0; i<800; i=i+1)
{
//screen.drawOval(175-i,80,i*2+10,10+i); //(x1,y1,width,height)
a=a+.5;
b=b+.5;
ang=ang+.8;
x=(int)(a*Math.cos(ang)+250);
y=(int)(b*Math.sin(ang)+250);
screen.drawLine(x,y, oldx, oldy);
oldx=x;
oldy=y;
pause(1);
}
}
}
public void actionPerformed(ActionEvent event)
{
Object source = event.getSource();
if (source.equals(drawButton))
{
System.out.println("hi");
go=true;
repaint();
}
}
void pause(int time)
{
try {
Thread.sleep(time);
} catch (InterruptedException e) { }
}
}
答案 0 :(得分:2)
该代码甚至不包含任何可能引发IOException
的内容。
答案 1 :(得分:1)
我按原样复制了你的代码,并且能够在没有I / O异常的appletviewer中编译和运行它...所以我不知道问题出在哪里......