博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java第六次作业
阅读量:7072 次
发布时间:2019-06-28

本文共 1508 字,大约阅读时间需要 5 分钟。

import java.awt.*;import java.awt.event.*;import javax.swing.*;public class GoodLucky extends JFrame implements ActionListener{  JTextField tf = new JTextField(); JButton b1 = new JButton("开始"); JButton b2 = new JButton("停止"); boolean isGo = false; public GoodLucky(){  b1.setActionCommand("start");    JPanel p = new JPanel();  p.add(b1);  p.add(b2);      b1.addActionListener(this);  b2.addActionListener(this);  b2.setEnabled(false);    this.getContentPane().add(tf,"North");  this.getContentPane().add(p,"South");  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  this.setSize(300,200);  this.setLocation(300,300);  Cursor cu = new Cursor(Cursor.HAND_CURSOR);  this.setCursor(cu);  this.setVisible(true);  tf.setText("welcome you!                  ");  this.go();   }  public void go(){  while(true){   if(isGo == true){    String s = "";    for(int j = 1; j <= 7;j++){     int i = (int)(Math.random() * 33) + 1;     if(i < 10){      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);  }else{   isGo = false;   b2.setEnabled(false);   b1.setEnabled(true);  }   }    public static void main(String[] args){  new GoodLucky();   }}

 

转载于:https://www.cnblogs.com/MAJIAO/p/5470962.html

你可能感兴趣的文章
ADO.NET操作数据库(一)
查看>>
指针与引用的本质区别
查看>>
Auto Layout 使用心得(五)—— 根据文字、图片自动计算 UITableViewCell
查看>>
M3U8在线视频文件下载合成MP4视频(自己想看电影)
查看>>
HTML5的布局的使用
查看>>
hdu 1068 二分图的最大匹配匈牙利算法
查看>>
一个IT人的非典型职场十年 (4)
查看>>
Netty之Recycler实现对象池
查看>>
Netty5入门学习笔记004-使用Netty传输POJO对象(上)
查看>>
Eclipse的快捷键总结
查看>>
RandomAccessFile相关(读写文件) --本文的正确性有待您验证。
查看>>
实现SPF垃圾邮件防护功能
查看>>
Slave IO: Yes Slave SQL: No Seconds Behind Mast...
查看>>
eclipse 使用Maven deploy命令部署构建到Nexus上
查看>>
大型系统中使用JMS优化技巧–Sun OpenMQ
查看>>
正则表达式-断言
查看>>
用git合并分支时,如何保持某些文件不被合并
查看>>
局部代码块、构造代码块、静态代码块
查看>>
聚类分析 ---- K-Means算法
查看>>
C語言最新標準-C11 「轉」
查看>>