import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import javax.swing.*;
public class Three extends JFrame implements ActionListener, Runnable {
/**
*
*/
private static final long serialVersionUID = -8560277451929244119L;
JTextField tf = new JTextField();
JButton b1 = new JButton("开始");
JButton b2 = new JButton("停止");
JButton b3 = new JButton("END");
boolean isGo = false;
String path = "three.jpg";
ImageIcon background = new ImageIcon(path);
JTextArea jiang1= new JTextArea();
int choujiangcishu=1;
public Three() {
this.getContentPane().setLayout(null);
Dimension srcDim = Toolkit.getDefaultToolkit().getScreenSize();
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.getContentPane().add(tf);
ImageIcon background = new ImageIcon(path);// 背景图片
JLabel jlbg = new JLabel(background);// 把背景图片显示在一个标签里面
jlbg.setBounds(0, 0, srcDim.width, srcDim.height);// 把标签的大小位置设置为图片刚好填充整个面板
JPanel imagePanel = (JPanel) this.getContentPane();
imagePanel.setOpaque(false);//设置透明
this.getLayeredPane().add(jlbg, new Integer(Integer.MIN_VALUE));
/*tf.setFont(new Font("Courier", Font.PLAIN, 35));
tf.setHorizontalAlignment(JLabel.LEFT);
tf.setOpaque(false);
tf.setBackground(Color.red);// 按钮红色背景
tf.setEditable(false);//不可编辑
//tf.setBorder(BorderFactory.createEmptyBorder());//无边框
tf.setBounds(80, 80, srcDim.width/6, srcDim.height/22);
*/
tf.setFont(new Font("Courier", Font.PLAIN, 35));
tf.setHorizontalAlignment(JLabel.LEFT);
tf.setOpaque(false);
tf.setBackground(Color.red);// 按钮红色背景
tf.setEditable(false);//不可编辑
//tf.setBorder(BorderFactory.createEmptyBorder());//无边框
*************** tf.setBounds(80, 200,200,200);
b1.setBounds(1,100,10,10);
b2.setBounds(1,200,10,10);
b3.setBounds(1,300,10,10);
this.getContentPane().add(tf);
this.getContentPane().add(b1);
this.getContentPane().add(b2);
this.getContentPane().add(b3);
b1.setActionCommand("start");
b2.setActionCommand("end");
b3.setActionCommand("over");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
SymListener sy = new SymListener();
b1.registerKeyboardAction(sy,KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
b2.registerKeyboardAction(sy,KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
b3.registerKeyboardAction(sy,KeyStroke.getKeyStroke(KeyEvent.VK_Q, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
//jButton.setMnemonic(KeyEvent.VK_ENTER);
b2.setEnabled(false);
super.setUndecorated(true);// 无标题栏
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocation(0, 0);
Cursor cu = new Cursor(Cursor.HAND_CURSOR);
this.setCursor(cu);
this.setVisible(true);
tf.setText("888888");
operdata geshu=new operdata();
go(geshu.getCount());
}
public void go(int p) {
while (true) {
if (isGo == true) {
String s = "";
for (int j = 1; j <= 1; j++) {
int i = (int) (Math.random()*p+1);//设定奖项总数
if (i < 10) {
s = s + "00000" + i;
} else if(i<100 & i>=10)
{
s = s + "0000" + i;
}else if(i<1000 & i>=100)
{
s = s + "000" + i;
}else if(i<10000 & i>=1000)
{
s = s + "00" + i;
}else if(i<100000 & i>=10000)
{
s = s + "0" + i;
}else
{
s = s + i;
}
}
tf.setText(s);
}
try {
Thread.sleep(10);
} catch (java.lang.InterruptedException e) {
e.printStackTrace();
}
}
}
public void actionPerformed(ActionEvent e) {
/* String s = e.getActionCommand();
if (s.equals("start")) {
isGo = true;
b1.setEnabled(false);
b2.setEnabled(true);
}
if (s.equals("end")){
isGo = false;
operdata aaa =new operdata();
String bb= aaa.getuserdata(tf.getText());
jiang1.setText(jiang1.getText()+"\n"+""+(choujiangcishu++)+": "+tf.getText()+bb);
b2.setEnabled(false);
b1.setEnabled(true);
}*/
}
public static void main(String[] args) {
//Dimension srcDim = Toolkit.getDefaultToolkit().getScreenSize();
// ImgUtil image =new ImgUtil();
//image.createThumb("3.png", "223.jpg",(int)srcDim.getWidth(), (int)srcDim.getHeight());
new Three();
}
class SymListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
Object obj = e.getSource();
if (obj == b1) {
isGo = true;
b1.setEnabled(false);
b2.setEnabled(true);
} else if (obj == b2) {
isGo=false;
b2.setEnabled(false);
b1.setEnabled(true);
}else if (obj == b3) {
dispose();
}
}
}
@Override
public void run() {
// TODO Auto-generated method stub
}
//@Override
/*public void run() {
this.yunyingzhongxingo();
}*/
}