代码:
package luckyDraw;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
public class LuckyDraw {
public static void main(String[] args) {
test t = new test();
}
}
class test extends JFrame implements Runnable{
Thread t1;//创建线程对象
ImageIcon img1 = new ImageIcon("D:\\java\\MyThread\\img\\1.png");//创建三个图片
ImageIcon img2 = new ImageIcon("D:\\java\\MyThread\\img\\2.png");
ImageIcon img3 = new ImageIcon("D:\\java\\MyThread\\img\\3.png");
ImageIcon[] array = { img1,img2,img3};//将三个图片放入数组
JLabel l1 = new JLabel(img1);//将图片放入标签
JLabel l2 = new JLabel(img2);
JLabel l3 = new JLabel(img3);
JLabel result = new JLabel("看看你的运气");//结果
JButton start = new JButton("开始");//定义开始按钮
JButton stop = new JButton("停止");//定义停止按钮
test(){
t1 = new Thread(this);