效果图:

0818b9ca8b590ca3270a3433284dd417.png

package game;

import java.awt.BorderLayout;

import java.awt.Container;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.Random;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JMenu;

import javax.swing.JMenuBar;

import javax.swing.JMenuItem;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

public class YaoHao extends JFrame {

Container c;

JMenuBar mb;

JMenu JFile,JHelp;

JMenuItem mExit,mCopyright;

JPanel pl;

JLabel num[]=new JLabel[6];

JButton begin,end;

boolean flag=true;

private void init(){

c=this.getContentPane();

c.setLayout(new BorderLayout());

mb=new JMenuBar();

JFile=new JMenu("文件(F)");

JHelp=new JMenu("帮助(H)");

mb.add(JFile);mb.add(JHelp);

mExit=new JMenuItem("退出(E)");

mCopyright=new JMenuItem("版权信息");

JFile.add(mExit);JHelp.add(mCopyright);

c.add(mb,BorderLayout.NORTH);

mCopyright.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

JOptionPane.showMessageDialog(null, "本游戏由暗伤无痕出品", "版权声明", JOptionPane.INFORMATION_MESSAGE);

}

});

mExit.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

YaoHao.this.dispose();

}

});

pl=new JPanel();pl.setLayout(null);

c.add(pl);

for(int i=0;i<6;i++){

num[i]=new JLabel("0");

pl.add(num[i]);

num[i].setBounds((i+2)*25,30,60,30);

}

begin=new JButton("开始");

end=new JButton("结束");

pl.add(begin);pl.add(end);

begin.setBounds(220,30,60,30);

end.setBounds(290,30,60,30);

begin.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

flag=true;

Numble n=new Numble();

n.start();

}

});

end.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

Numble n=new Numble();

flag=false;

}

});

this.setSize(400,300);

this.setVisible(true);

}

public YaoHao(String title){

super(title);

init();

}

class Numble extends Thread{

Random random=new Random();

public void run(){

while(flag){

for(int i=0;i<6;i++){

num[i].setText(Integer.toString(random.nextInt(10)));

}}

try {

sleep(10000);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

public static void main(String[] args) {

YaoHao yh=new YaoHao("彩票摇号器");

}

}

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐