同题
APPLET程序 要点击按钮能够画正玄曲线 (作图也行)要使用EVENT
------解决方案--------------------
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class animation1 extends Applet implements Runnable,ActionListener
{
Thread hThread;
int xx=0,yy=0;
int x=0;
Label label1;
public void init()
{
this.setBackground(Color.lightGray);
Button myButton1=new Button( "开始 ");
myButton1.addActionListener(this);
this.add(myButton1);
Button myButton2=new Button( "暂停 ");
myButton2.addActionListener(this);
this.add(myButton2);
Button myButton3=new Button( "停止 ");
myButton3.addActionListener(this);
this.add(myButton3);
}
public void start()
{
//创建线程
if(hThread==null)
hThread=new Thread(this);
//启动线程
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand()== "开始 ")
{
hThread.start();
}
if(e.getActionCommand()== "暂停 ")
{
hThread.suspend();
}
if(e.getActionCommand()== "停止 ")
{
hThread.resume();
}
}
public void run()
{
//线程run方法
while(true)
{
repaint();
try
{
//线程睡眠时间
hThread.sleep(20);
}
catch(InterruptedException e)
{}
}
}
public void paint(Graphics g)
{
for(int x1=0;x1 <=x;x1++)
{
double y1=200.0+100.0*Math.sin((double)x1*Math.PI/180.0);
int x11=x1+1;
double y11=200.0+100.0*Math.sin((double)x11*Math.PI/180.0);
g.drawLine(x1,(int)y1,x11,(int)y11);
}
x++;
if(x> 360)x=0;
double y=200.0+100.0*Math.sin((double)x*Math.PI/180.0);
g.drawLine(xx,yy,x,(int)y);
xx=x;
yy=(int)y;
}
public void stop()
{
hThread= null;
}
}
------解决方案--------------------
帮忙顶,