import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;/**
 * Author: fan
 * Date: 2003-6-2
 * Time: 16:44:27
 * Copyright(c) Since 2003 WisdomLeague.
 */
public class Random extends JFrame implements ActionListener {    JButton random = new JButton("Random");
    TextPanel tp = new TextPanel();    public Random () {
        super("Random");
        setSize(248,200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        BorderLayout border = new BorderLayout();
        JPanel pane = new JPanel();
        pane.setLayout(border);        JPanel buttonPanel = new JPanel();
        buttonPanel.setSize(48,200);
        random.addActionListener(this);
        buttonPanel.add(random);        pane.add(buttonPanel, BorderLayout.NORTH);
        pane.add(tp,BorderLayout.CENTER);
        setContentPane(pane);
        show();
    }
    public void actionPerformed(ActionEvent e) {
        Object source = e.getSource();
        if (source == random) {
            tp.RandomNum();
        }
    }    public static void main (String[] arguments) {
        Random ra;
        ra = new Random();
    }
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;/**
 * Author: fan
 * Date: 2003-6-2
 * Time: 17:28:09
 * Copyright(c) Since 2003 WisdomLeague.
 */
public class TextPanel extends JPanel {
    private Thread runner;
    int[] randomList = new int[7];    TextPanel () {
        setSize(200,200);
    }
    void  RandomNum() {
        randomList[0] = (int)(Math.random() * 9 );
        randomList[1] = (int)(Math.random() * 9 );
        randomList[2] = (int)(Math.random() * 9 );
        randomList[3] = (int)(Math.random() * 9 );
        randomList[4] = (int)(Math.random() * 9 );
        randomList[5] = (int)(Math.random() * 9 );
        randomList[6] = (int)(Math.random() * 7 );
    }    void playAnimation() {
        if (runner == null) ; {
            runner= new Thread();
            runner.start();
        }
    }    void stopAnimation() {
        if (runner != null) ;{
            runner = null;
        }
    }    public void run() {
        Thread thisThread = Thread.currentThread();
        while (runner == thisThread) {
            repaint();
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) { }
    }    public void paintComponent(Graphics comp) {
        Graphics2D comp2D = (Graphics2D)comp;
        for (int j = 0; j <= 6; j++) {
            comp2D.drawString(Integer.toString(randomList[j]),50 + 24 * j ,55 );
        }
    }
}
//估计时线程的问题,不改变窗口的大小,数字不变。//请问,如何改成每按一次安扭,号码自己变一次。