packagecom.java.test1;importjava.applet.Applet;importjava.awt.BorderLayout;importjava.awt.Button;importjava.awt.Graphics;importjava.awt.Label;importjava.awt.event.ActionE...
package com.java.test1;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
public class ChouJiang extends Applet {
private Button btn_control = new Button("开始");//控制按钮
private Label label = new Label();//显示数字
private boolean b = true;//线程控制器,编写UI界面的东西都要用到线程要不然界面会出现死机的样子
public void paint(Graphics g) {
}
public void init() {
this.setLayout(new BorderLayout());
this.add(label,BorderLayout.NORTH);
this.add(btn_control,BorderLayout.SOUTH);
btn_control.addActionListener(new Control());
}
class Control implements ActionListener{
public void actionPerformed(ActionEvent arg0) {
if(btn_control.getLabel().equals("开始")){
b = true;
btn_control.setLabel("停止");
new Thread(new Repaint()).start();
}else{
b = false;
btn_control.setLabel("开始");
}
}
}
class Repaint implements Runnable{
public void run() {
while(b){
try {
repaint();
Random random = new Random();
int i = Math.abs(random.nextInt(100));//i的取值范围0-100,详细的参考J2SE的API
label.setText(""+i);
System.out.println(i);
Thread.sleep(200);//延迟200毫秒
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
无标题文档这个小程序无法在页面显示 说载入java小程序失败。java程序可以在Eclipse下运行。请问哪位高手帮我解决啊 在线等待中
展开