首页 > 其他分享 >计分器

计分器

时间:2023-10-20 11:03:02浏览次数:31  
标签:GridData tmp CENTER 计分 setText new SWT


代码:

public class Sample1 {
	private static Composite container1;
	private static List<String> teamMarks = new ArrayList<String>();
	private static List<CLabel> listTeam = new ArrayList<CLabel>();
	private static List<CLabel> listOrder = new ArrayList<CLabel>();
	private static Timer timer;
	private static CLabel CLabelTimer;

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setText("计分器");
		createArea(shell);
		shell.pack();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}

	private static void createArea(Shell parent) {

		parent.setBackground(new Color(null,173, 223, 237));
		parent.setBackgroundMode(SWT.INHERIT_DEFAULT);
		parent.setLayout(new GridLayout());

		Composite container = new Composite(parent, SWT.NONE);
		container.setLayout(new GridLayout(2, false));
		container.setLayoutData(new GridData(GridData.FILL));

		CLabel cLabel = new CLabel(container, SWT.CENTER | SWT.BORDER);
		cLabel.setText("研发部知识竞赛计分表");
		GridData gridData = new GridData(SWT.CENTER | GridData.FILL_HORIZONTAL);
		gridData.horizontalSpan = 2;
		cLabel.setLayoutData(gridData);
		cLabel.setFont(new Font(null,"新宋体",32,SWT.BOLD));

		container1 = new Composite(container, SWT.BORDER);
		container1.setLayout(new GridLayout(1, true));
		gridData = new GridData(SWT.CENTER | GridData.FILL_HORIZONTAL);
		gridData.verticalSpan = 2;
		container1.setLayoutData(gridData);
		container1.setLayoutData(new GridData(GridData.FILL_BOTH));
		{
			Composite container11 = new Composite(container1, SWT.NONE);
			container11.setLayout(new GridLayout(3, true));
			container11.setLayoutData(new GridData(GridData.FILL_BOTH));

			CLabel CLabel1 = new CLabel(container11, SWT.CENTER | SWT.NONE);
			CLabel1.setText("参赛队");
			CLabel1.setLayoutData(new GridData(SWT.CENTER | GridData.FILL_BOTH));
			CLabel1.setFont(new Font(null,"新宋体",30,SWT.NONE));

			CLabel CLabel11 = new CLabel(container11, SWT.CENTER | SWT.NONE);
			CLabel11.setText("比赛得分");
			CLabel11.setLayoutData(new GridData(SWT.CENTER | GridData.FILL_BOTH));
			CLabel11.setFont(new Font(null,"新宋体",30,SWT.NONE));

			CLabel CLabel2 = new CLabel(container11, SWT.CENTER | SWT.NONE);
			CLabel2.setText("名次");
			CLabel2.setLayoutData(new GridData(SWT.CENTER | GridData.FILL_BOTH));
			CLabel2.setFont(new Font(null,"新宋体",30,SWT.NONE));

			for(int i=0; i<7; i++) {
				addTeam(container1,i);
			}
		}

		Composite container2 = new Composite(container, SWT.BORDER);
		container2.setLayout(new GridLayout(1, true));
		gridData = new GridData(SWT.CENTER | GridData.FILL_VERTICAL);
		gridData.verticalSpan = 1;
		container2.setLayoutData(gridData);
		{
			CLabel CLabel1 = new CLabel(container2, SWT.CENTER | SWT.NONE);
			CLabel1.setText("倒计时");
			CLabel1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

			CLabelTimer = new CLabel(container2, SWT.CENTER | SWT.BORDER);
			CLabelTimer.setFont(new Font(null,"新宋体",60,SWT.NONE));
			CLabelTimer.setText("0");
			CLabelTimer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

			final Text text = new Text(container2, SWT.CENTER | SWT.BORDER);
			text.setText("10");
			text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
			text.addVerifyListener(new VerifyListener() {

				public void verifyText(VerifyEvent e) {
					e.doit = e.text.length() == 0
					|| Character.isDigit(e.text.charAt(0));
				}

			});


			Composite container21 = new Composite(container2, SWT.BORDER);
			container21.setLayout(new GridLayout(2, true));
			container21.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

			Button button1 = new Button(container21, SWT.CENTER | SWT.NONE);
			button1.setText("开始");
			button1.setFont(new Font(null,"新宋体",20,SWT.NONE));
			button1.setLayoutData(new GridData(SWT.CENTER));
			button1.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					CLabelTimer.setText(text.getText());

					if(timer != null) {
						timer.cancel();
					}

					timer = new Timer();
					TimerTask task = new TimerTask(){
						public void run() {
							int tmp = Integer.parseInt(CLabelTimer.getText());
							if(tmp > 0) {
								tmp = tmp - 1;
							}
							final int tmptmp = tmp;
							Display.getDefault().syncExec(new Runnable() {
								public void run() {
									CLabelTimer.setText(tmptmp + "");
								}
							});
							if(tmptmp == 0) {
								timer.cancel();
//								Toolkit toolkit = Toolkit.getDefaultToolkit(); 
//								toolkit.beep();//发出声音
								try {
									FileInputStream fileau = new FileInputStream(new File("src/sound.wav"));
//									FileInputStream("sloop.au");
									AudioStream as=new AudioStream(fileau);
									AudioPlayer.player.start(as);
								}
								catch (Exception e) {}

								Display.getDefault().syncExec(new Runnable() {
									public void run() {
										MessageBox messageBox = new MessageBox(Display.getCurrent().getShells()[0], SWT.YES|SWT.ICON_INFORMATION);
										messageBox.setMessage("时间到!");
										messageBox.setText("提示");
										messageBox.open();
									}
								});
							}
						}
					};

					timer.schedule(task, 1000, 1000);
				}
			});

			Button button2 = new Button(container21, SWT.CENTER | SWT.NONE);
			button2.setText("清零");
			button2.setFont(new Font(null,"新宋体",20,SWT.NONE));
			button2.setLayoutData(new GridData(SWT.RIGHT));
			button2.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					timer.cancel();
					Display.getDefault().syncExec(new Runnable() {
						public void run() {
							CLabelTimer.setText("0");
						}
					});
				}
			});

		}

		Composite xxxx = new Composite(container2, SWT.NONE);
		xxxx.setLayout(new GridLayout(2, false));
		gridData = new GridData(SWT.CENTER | GridData.FILL_VERTICAL);
		gridData.verticalSpan = 1;
		gridData.verticalAlignment = SWT.BOTTOM;
		xxxx.setLayoutData(gridData);

		Composite container22 = new Composite(container2, SWT.BORDER);
		container22.setLayout(new GridLayout(2, false));
		gridData = new GridData(SWT.CENTER | GridData.FILL_HORIZONTAL);
		gridData.verticalSpan = 1;
		gridData.verticalAlignment = SWT.BOTTOM;
		container22.setLayoutData(gridData);

		{
			CLabel CLabel2 = new CLabel(container22, SWT.CENTER | SWT.NONE);
			CLabel2.setText("队号:");

			final Text text1 = new Text(container22, SWT.CENTER | SWT.BORDER);
			text1.setText("1");
			text1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
			text1.addVerifyListener(new VerifyListener() {
				public void verifyText(VerifyEvent e) {
					e.doit = e.text.length() == 0
					|| Character.isDigit(e.text.charAt(0));
				}
			});

			CLabel CLabel3 = new CLabel(container22, SWT.CENTER | SWT.NONE);
			CLabel3.setText("队名:");

			final Text text2 = new Text(container22, SWT.BORDER);
			text2.setText("");
			text2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));


			Button buttonxx = new Button(container22, SWT.CENTER | SWT.NONE);
			buttonxx.setText("改名");
			buttonxx.setVisible(false);
			buttonxx.setLayoutData(new GridData(SWT.CENTER));


			Button button3 = new Button(container22, SWT.CENTER | SWT.NONE);
			button3.setText("改名");
			gridData = new GridData(SWT.CENTER | GridData.FILL_HORIZONTAL);
			gridData.verticalSpan = 1;
			gridData.verticalAlignment = SWT.RIGHT;
			button3.setLayoutData(gridData);
			button3.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					String s1 = text1.getText();
					String s2 = text2.getText();
					if(s1.length()>0 && s2.length()>0) {
						int i = Integer.parseInt(s1);
						if(i>0 && i<8) {
							listTeam.get(i-1).setText(s2);
						}
					}
				}
			});
		}
	}

	private static void addTeam(Composite container1, final int num) {
		teamMarks.add(num, new String("100"));
		final Button button1, button2, button3;

		Composite container11 = new Composite(container1, SWT.NONE);
		container11.setLayout(new GridLayout(3, true));
		container11.setLayoutData(new GridData(GridData.FILL_BOTH));

		CLabel CLabel1 = new CLabel(container11, SWT.CENTER | SWT.NONE);
		CLabel1.setText("第 "+ (num+1) +" 队");
		CLabel1.setLayoutData(new GridData(SWT.CENTER | GridData.FILL_BOTH));
		CLabel1.setFont(new Font(null,"新宋体",30,SWT.NONE));
		listTeam.add(CLabel1);

		Composite container111 = new Composite(container11, SWT.NONE);
		container111.setLayout(new GridLayout(3, true));
		container111.setLayoutData(new GridData(SWT.CENTER | GridData.FILL_BOTH));

		button1 = new Button(container111, SWT.CENTER | SWT.NONE);
		button1.setText("1");
		button1.setFont(new Font(null,"新宋体",30,SWT.NONE));
		button1.setLayoutData(new GridData(SWT.CENTER | GridData.FILL_BOTH));

		button2 = new Button(container111, SWT.CENTER | SWT.NONE);
		button2.setText("0");
		button2.setFont(new Font(null,"新宋体",30,SWT.NONE));
		button2.setLayoutData(new GridData(SWT.CENTER | GridData.FILL_BOTH));
		button2.addMouseListener(new MouseAdapter() {
			public void mouseDown(MouseEvent e) {
				int tmp = Integer.parseInt(teamMarks.get(num));
				if(e.button == 1) {
					if(tmp < 990) {
						tmp = tmp + 10;
					}
				} else {
					if(tmp >= 10) {
						tmp = tmp - 10;
					}
				}
				teamMarks.set(num, tmp + "");

				char[] charTmp = (tmp + "").toCharArray();
				if(tmp >= 100) {
					button1.setText(charTmp[0] + "");
					button2.setText(charTmp[1] + "");
				} else if (tmp >= 10) {
					button1.setText("0");
					button2.setText(charTmp[0] + "");
				} else {
					button1.setText("0");
					button2.setText("0");
				}


				refreshOrder();
			}
		});

		button3 = new Button(container111, SWT.CENTER | SWT.NONE);
		button3.setText("0");
		button3.setFont(new Font(null,"新宋体",30,SWT.NONE));
		button3.setLayoutData(new GridData(SWT.CENTER | GridData.FILL_BOTH));
		button3.addMouseListener(new MouseAdapter() {
			public void mouseDown(MouseEvent e) {
				int tmp = Integer.parseInt(teamMarks.get(num));
				if(e.button == 1) {
					if(tmp < 995) {
						tmp = tmp + 5;
					}
				} else {
					if(tmp > 0) {
						tmp = tmp - 5;
					}
				}
				teamMarks.set(num, tmp + "");

				char[] charTmp = (tmp + "").toCharArray();
				if(tmp >= 100) {
					button1.setText(charTmp[0] + "");
					button2.setText(charTmp[1] + "");
					button3.setText(charTmp[2] + "");
				} else if (tmp >= 10) {
					button1.setText("0");
					button2.setText(charTmp[0] + "");
					button3.setText(charTmp[1] + "");
				} else {
					button1.setText("0");
					button2.setText("0");
					button3.setText(charTmp[0] + "");
				}

				refreshOrder();
			}


		});

		CLabel CLabel2 = new CLabel(container11, SWT.CENTER | SWT.NONE);
		CLabel2.setText("1");
		CLabel2.setLayoutData(new GridData(SWT.CENTER | GridData.FILL_BOTH));
		CLabel2.setFont(new Font(null,"新宋体",30,SWT.NONE));
		listOrder.add(CLabel2);
	}


	private static void refreshOrder() {

		int[] r = new int[7];
		for(int i=0; i<7; i++) {
			r[i] = 1;
		}

		//逐对比较所有元素
		for ( int i = 0; i < 7; i++) {
			for ( int j = i+1; j < 7; j++) {
				int frs = Integer.parseInt(teamMarks.get(i));
				int sec = Integer.parseInt(teamMarks.get(j));
				if (frs < sec) {
					r[i]++;
				}else if (frs > sec) {
					r[j]++;
				}
			}
		}

		for(int i=0; i<7; i++) {
			listOrder.get(i).setText(r[i] + "");

		}

	}
}

 


实现功能:

1,可以修改队名。

2,有倒计时。

3,倒计时到了,显示对话框和声音。

4,分数分百十个,鼠标点击百没用、十加一、个加5,并且依照总分自动排名次。

可以补充的功能:

1,所有的标题文字来自xml,这样便于多语言的支持。

2,参加队的数目可以变。

3,整体布局自适应窗口的变化。

4,设置可以用sash,可以支持隐藏。

。。。
 

标签:GridData,tmp,CENTER,计分,setText,new,SWT
From: https://blog.51cto.com/u_16298170/7947903

相关文章

  • 【后台体验】运营后台订单详情设计分享
    目前大部分运营后台的设计和开发都是由后端同学来做,产品经理对界面标准要求并不高,大多数都是能用就行。其实,只要花些心思,运营后台也可以做的很美,提升运营同学的日常使用体验。下面跟大家分享两个我做的运营后台中的订单详情设计1.共享图书平台运营后台订单详情设计心路历程:产......
  • 【后台体验】运营后台订单详情设计分享 | 京东云技术团队
    目前大部分运营后台的设计和开发都是由后端同学来做,产品经理对界面标准要求并不高,大多数都是能用就行。其实,只要花些心思,运营后台也可以做的很美,提升运营同学的日常使用体验。下面跟大家分享两个我做的运营后台中的订单详情设计1.共享图书平台运营后台订单详情设计心路历程:产品经......
  • TSINGSEE青犀基于AI视频智能分析的客流统计分析场景方案
    随着AI技术的不断发展与人类需求的不断提升,视觉目标的检测识别、智能监控在人们的生活中均有着广泛的应用。其中,智能安防视频监控是计算机视觉的重要应用领域,而AI客流统计则是近年来此领域大家关注热度较高的技术之一。行业痛点传统的客流量统计采用的仍是人工计数方法,对进出商超的......
  • TSINGSEE青犀基于AI视频智能分析的客流统计分析场景方案
    随着AI技术的不断发展与人类需求的不断提升,视觉目标的检测识别、智能监控在人们的生活中均有着广泛的应用。其中,智能安防视频监控是计算机视觉的重要应用领域,而AI客流统计则是近年来此领域大家关注热度较高的技术之一。行业痛点传统的客流量统计采用的仍是人工计数方法,对进出......
  • 一些常见小程序的UI设计分享
    外卖优惠券小程序的UI设计电子商城系统UI分享A B  C ......
  • 统计分数
    已知共有30名学生,每名学生有数学、语文、物理、化学、英语5门功课,班主任需要统计总分在前10名的同学的姓名和学号,另外特别关注这10名同学中有某门功课低于80分的同学,请编写程序实现上述功能。1#include<stdio.h>2#include<string.h>34//定义学生结构体5stru......
  • 设计分页查询我的课程接口
             ......
  • 10个学生成绩统计分析软件网站,你是否知道
    以下是十个学生成绩统计分析软件网站,它们提供了各种功能和工具,用于学生成绩的统计、分析和可视化。1.GradeBook(https://www.gradebook.org/):GradeBook是一个全面的学生成绩管理和分析平台。它提供了成绩输入、计算、报告和个性化学生跟踪等功能,帮助教育者更好地监控和管理......
  • 抖音的互联网架构与系统设计分析
    引言抖音是目前全球最受欢迎的短视频分享平台之一,它能够支持海量用户上传、播放和分享视频。在这篇文章中,我们将深入分析抖音的互联网架构,了解其系统设计和技术实现,并思考在类似场景下如何构建高可用的系统。1.抖音的互联网架构概述抖音的互联网架构是一个典型的大型分布式系统,它......
  • 一套成熟的实验室信息管理系统源码,集前处理、检验、报告、质控、统计分析、两癌等模块
    一套成熟的实验室信息管理系统,集前处理、检验、报告、质控、统计分析、两癌等模块为一体的实验室信息管理系统。在整个检验过程中实时对检验结果监控、评估、分析、统计并对操作规程进行严格规范。它的开发和应用将加快检验科管理的统一化、网络化、标准化的进程。技术架构:ASP.NET......