資源簡(jiǎn)介
編寫(xiě)一個(gè)Applet內(nèi)部顯示一個(gè)藍(lán)色反彈球的程序,通過(guò)一個(gè)事件使該球開(kāi)始運(yùn)動(dòng),在該球撞擊Applet邊框時(shí),它應(yīng)從邊框彈回并以相反的方向運(yùn)動(dòng)。
代碼片段和文件信息
/**
?*?@(#)實(shí)驗(yàn)六2_線程.java
?*
?*?Sample?applet?application
?*
?*?@author?
?*?@version?1.00?09/11/20
?*/
?
import?java.awt.*;
import?java.applet.*;
import?java.awt.event.*;
public?class?Thread2?extends?applet?implements?RunnableActionListener
{
Label?prompt;
TextField?text;
Color?blueColor=new?Color(00255);
Button?btn1btn2;
Thread?thread1;
int?X=0;int?Y=0;
public?void?init()?
{
prompt=new?Label(“速度選擇“);
text=new?TextField(10);
btn1=new?Button(“開(kāi)始“);
add(prompt);
add(text);
add(btn1);
btn1.addActionListener(this);
btn2=new?Button(“停止“);
add(btn2);
btn2.addActionListener(this);
}
public?void?paint(Graphics?g)?
{
g.setColor(blueColor);
g.fillOval(XY5050);
}
public?void?actionPerformed(ActionEvent?e)
{
if(e.getSource()==btn1)
{
???thread1=new?Thread(this);
???thread1.start();
}
if(e.getSource()==btn2)
{
if(thread1.isAlive())
??????thread1.stop();
}
}
評(píng)論
共有 條評(píng)論