Java做的一个小程序,随机点名器
Java做的一个小程序-随机点名器
Java做的一个小程序-随机点名器介绍随机点名器是一款使用Java编写的小程序,它主要用于在学生课堂上随机抽取学生姓名进行点名。
该程序可以通过命令行方式运行,而且它的使用非常简单,不需要任何的专业技能与知识。
功能特点随机点名器的主要功能是在学生课堂上进行学生姓名的随机抽取,以帮助老师完成课堂管理工作。
程序的具体功能特点如下:•支持添加学生姓名:程序可以通过用户输入学生姓名的方式,将其添加到学生库中。
•支持删除学生姓名:用户可以对已存在的学生进行删除操作。
•支持随机点名:程序可以随机抽取学生姓名,以完成点名的操作。
•支持列表显示:程序可以展示所有的学生姓名列表,以供用户查看。
使用说明系统要求随机点名器使用Java语言编写,因此用户需要先安装Java运行环境。
具体要求如下:•操作系统:Windows、Linux、MacOS等•Java版本:JRE 1.8或以上版本安装方法1.下载程序压缩包。
2.解压缩到用户指定的目录。
3.运行“run.bat”文件(Windows平台)或“run.sh”文件(Linux/MacOS平台)。
使用方法1.添加学生姓名:在命令行窗口中输入“add”命令,然后输入学生姓名进行添加。
2.删除学生姓名:在命令行窗口中输入“delete”命令,然后输入需要删除的学生姓名。
3.随机点名:在命令行窗口中输入“random”命令,程序将随机抽取一个学生姓名进行点名。
4.显示学生列表:在命令行窗口中输入“list”命令,程序将展示所有已经添加的学生姓名。
技术实现技术框架随机点名器采用Java语言编写,主要使用了JDK中的标准库,使用了Collection接口中的List、Set集合类、Random类等。
算法实现随机点名的算法实现主要通过Java中的Random类实现,随机整数范围为0到学生数量-1,通过集合类的索引访问随机抽取的学生姓名。
代码实现```Java import java.util.*;public class RandomPicker { private List students;public RandomPicker() {students = new ArrayList<String>();}public void add(String name) {students.add(name);}public void delete(String name) {students.remove(name);}public String random() {Random random = new Random();int index = random.nextInt(students.size());return students.get(index);}public void list() {int n = 1;for(String student : students) {System.out.println((n++) + \。
生成随机中文姓名的java程序
原生JavaScript实现随机点名表
原⽣JavaScript实现随机点名表本⽂实例为⼤家分享了JavaScript随机点名表的具体代码,供⼤家参考,具体内容如下效果:代码:<!DOCTYPE html><html><head><meta charset="UTF-8"><title></title><style>.box{width:300px;height:200px;border:1px solid #ccc;/*position: absolute;left:0;right:0;top:0;bottom:0;margin: auto;*/margin: 100px auto;text-align: center;}h1{width:150px;height:60px;line-height: 60px;text-align: center;font-size: 30px;background-color: red;margin: 10px auto;}button{width:100px;height:40px;background-color: dodgerblue;border:0;font-size: 24px;color:#fff;}</style></head><body><div class="box"><h1></h1><button>开始</button><button>停⽌</button></div><script>var h1=document.getElementsByTagName('h1')[0];var btn=document.getElementsByTagName("button");var arr=["苏晨旭","张志阳","⼩明","社会坤哥","药","敬珍","锦涛","⽹管","社会⾠哥","渣男","雪","宝贝曼","⼤个","睡神","龙爷","英⼉","东北娃","珂珂","黄花⼤闺⼥","狗蛋","狗⼦","天娇","志强","晋玮","海涛","迈姐","新凤","环姐","⼆狗"]; var ind=ranFun(0,arr.length-1)h1.innerHTML=arr[ind];var timer;btn[0].onclick=function(){clearInterval(timer)timer=setInterval(function(){h1.innerHTML=arr[ranFun(0,arr.length-1)]},100)}btn[1].onclick=function(){clearInterval(timer)}function ranFun(a,b){return Math.floor(Math.random()*(b-a+1)+a)}</script></body></html>以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
Java基础-day09-重构随机点名器
Java基础-day09-重构随机点名器Java基础-day09-重构随机点名器1.案例介绍与演示随机点名的案例由之前简单的Person对象,重构为相对完整的Person对象并使用。
2.案例回顾在全班同学中随机地打印出一名同学名字。
共三个步骤:(1)存储全班同学(Person对象)(2)打印全班同学每一个人的名字(3)在班级总人数范围内,随机产生一个随机数索引,查找该随机数索引所对应的同学(Person对象),并通过该对象访问name属性3.重构内容分析将原来使用的简单Person类,封装为包装成员变量和成员方法的相对完整的Person类,并将所有访问属性的地方改为通过get/set方法访问。
代码实现:package StudentJavaSEday09; /*自定义类型人类属性姓名 String年龄 int性别 String身高 double是否热爱java boolean*/public class Person {// 姓名String name;// 年龄int age;// 性别String sex;// 身高double height;// 是否喜欢javaboolean isLoveJava;public String getName() {return name;}public void setName(String name) { = name;}public int getAge() {return age;}public void setAge(int age) { this.age = age;}public String getSex() {return sex;}public void setSex(String sex) { this.sex = sex;}public double getHeight() {return height;}public void setHeight(double height) {this.height = height;}public boolean isLoveJava() {return isLoveJava;}public void setLoveJava(boolean isLoveJava) {this.isLoveJava = isLoveJava;}}package StudentJavaSEday09;/*随机点名器用集合存储所有同学总览全班同学姓名随机点名其中一人,打印到控制台1.定义一个集合用来存储所有同学导包创建对象存储的是Person调用方法2.向集合中添加人3.遍历集合,依次获取每个人,打印每个人的名字4.随机点名生成一个最大不超过集合最大索引的随机数 0 - 集合最大索引的一个随机数依据随机数得到集合中相对应的人,打印其名字*///导入集合ArrayListimport java.util.ArrayList;import java.util.Random;;public class RandomName {public static void main(String[] args) {// 定义一个集合用来存储所有人ArrayList<Person> list = new ArrayList<Person>();// 向集合中添加人创建Person对象将Person添加到集合中Person p = new Person();p.setName("柳岩");Person p2 = new Person();p2.setName("唐嫣");Person p3 = new Person();p3.setName("金莲");list.add(p);list.add(p2);list.add(p3);System.out.println("-----------------------");// 遍历集合,依次获取每个人,打印每个人的名字for (int i = 0; i < list.size(); i++) {Person thisP = list.get(i);// 调用getName方法获取每个人的名字System.out.println(thisP.getName());}System.out.println("-----------------------");// 随机点名Random r = new Random();// 生成一个最大不超过集合最大索引的随机数0 - 集合最大索引的一个随机数int randomIndex = r.nextInt(list.size());// 依据随机数得到集合中相对应的人Person person = list.get(randomIndex);System.out.println("今天你答题:" + person.getName()); }}运行结果:。
JavaScript实现随机点名小程序
JavaScript实现随机点名⼩程序本⽂实例为⼤家分享了JavaScript实现随机点名⼩程序的具体代码,供⼤家参考,具体内容如下导⼊jar包将jquery-3.3.1.min.js包导⼊到web⽬录下的js包代码实现<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>点名器</title><style>body{background-color: gray;}.box{width: 1000px;height: 280px;margin: 0 auto;margin-top: 100px;clear: both;}#btn,#btn2,#btn3,#btnStop{width: 150px;height: 50px;margin-top: 50px;font-size: 18px;}.name{width: 100px;height: 30px;float: left;background-color: antiquewhite;margin-left: 10px;margin-top: 10px;text-align: center;line-height: 30px;}#span{float: right;position: relative;top: 55px;right: 185px;}h1{text-align: center;}.high{background-color: #FFDEAD;font-weight:500;}</style></head><body><h1>随机点名系统</h1><span id="span"></span><div class="box" id="box"></div><div style="text-align: center"><input type="button" id="btn" value="点名"/><input type="button" id="btnStop" value="停⽌"/></div></body><script type="text/javascript" src="js/jquery-3.3.1.min.js"></script><script type="text/javascript">var arr = [ "张恒","李伟","⽂⼦昂","李彦松","廖彬","⾦鑫","夏华伶","邓洪","陈紫桥","罗继财","陈治豪","李坤耀","母天鑫","冯思皓","⾕康杰","李辉","李先进","⽶俊杰","彭⼩平","唐旭","万云松","向星宇","张全鑫","邬建科","徐江涛","李连辉","肖云龙","徐浪","马俊杰","欧阳平","周⾬凡"];//⽣成数组中的名单div并添加到box中let boxNode = document.getElementById("box");boxNode.innerHTML = "";//循环遍历数组for(let i = 0;i< arr.length;i++){//创建div元素let divNode = document.createElement("div");//设置div内容divNode.innerHTML = arr[i];//设置div样式divNode.className = "name";//添加到box元素中boxNode.appendChild(divNode);}let time = null//点击开始点名,开启⼀个循环定时器,绑定⿏标单击事件$("#btn").click(function () {time = setInterval(function () {//随机被选中的div设置背景颜⾊为红⾊let index = Math.floor(Math.random()*arr.length);//清除之前的颜⾊$("#box div").css("background-color","");//找到⽣成的名单divlet mySelector = "#box div:eq("+ index+")";$(mySelector).css("background-color","red");},50);});//点击停⽌按钮清除定时器$("#btnStop").click(function () {clearInterval(time);})</script></html>⼩结1.div元素使⽤循环动态⽣成,循环长度是名单数组的长度2.div⽣成后要添加box到⽗元素中3.Math.random()随机数为0-10以内的⼩数.随机范围为数组的长度4.在⽣成名单颜⾊时需要清除之前的颜⾊以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
java编写一个花名随机抽取器的实现示例
java编写⼀个花名随机抽取器的实现⽰例⼀.程序效果还记得以前上课的时候,⽼师会⽤⾃⼰写的⼀个抽取器抽取同学回答问题,当时想着我也要做⼀个,假期没事⼲,⾃学了java,闲来⽆聊,我也写⼀个,但是写的没有⽼师好,哈哈,好了说⼀下思路,先把界⾯布置好,然后逐⼀实现每个按钮的功能,其实也没什么难的。
⼆.需要⽤到的包import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.io.*;import java.util.*;三.代码1.相关实例对象,所以对象均为全局对象private static JLabel jl= new JLabel("⽂件:");private static JTextField jt =new JTextField();private static JButton OpenButton =new JButton("选择⽂件");private static JTextField jt2 =new JTextField();//⽂本框显⽰抽取名单private static JButton StartButton =new JButton("开始抽取");private static JLabel ClassjL= new JLabel("班级:");private static JTextField ClassjT =new JTextField();//显⽰班级private static JLabel NumjL= new JLabel("⼈数:");private static JTextField NumjT =new JTextField();//显⽰⼈数private static JLabel jl2= new JLabel("抽取模式:");private static JComboBox jc= new JComboBox();//下拉列表框private static JButton AboutButton =new JButton("关于");private static JOptionPane jo =new JOptionPane();//弹出⼀个提⽰框private static String[]s ;//⽤来存放⼈名private static Font font = new Font("宋体",Font.BOLD,18); //设置字体对象private static int Number=0;//⽤来存放抽取⼈数2.建⽴窗体,并完成组件的初始化private void windows() {JFrame jf =new JFrame ("花狗抽取器本⼈博客:");jf.setIconImage(new ImageIcon("Icon.jpg").getImage());Container c=jf.getContentPane();c.setLayout(new GridLayout(4,2,10,10));OpenButton.setFocusPainted(false);StartButton.setFocusPainted(false);AboutButton.setFocusPainted(false);//去掉按钮⽂字旁边的虚线框JPanel jp1 =new JPanel();JPanel jp2 =new JPanel(new BorderLayout());JPanel jp3 =new JPanel();JPanel jp4 =new JPanel();//添加⾯板jt.setColumns(10);ClassjT.setColumns(6);NumjT.setColumns(4);jt2.setHorizontalAlignment(JTextField.CENTER);jc.addItem("--请选择--");jc.addItem("抽取⼀⼈");jc.addItem("抽取三⼈");jc.addItem("抽取五⼈");jp1.add(jl);jp1.add(jt);jp1.add(OpenButton);jp2.add(jt2,BorderLayout.CENTER);jp3.add(ClassjL);jp3.add(ClassjT);jp3.add(NumjL);jp3.add(NumjT);jp3.add(jl2);jp3.add(jc);jp4.add(StartButton);jp4.add(AboutButton);c.add(jp1);c.add(jp2);c.add(jp3);c.add(jp4);jf.setVisible(true);jf.setBounds(800, 200, 400, 500);jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);getOpenButton(); //下⾯三个⽅法是⽤来监听按钮事件⽅法getAboutButton();getSrartButton();}3.添加“打开⽂件”按钮监听事件:private void getOpenButton() {OpenButton.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {JFileChooser fc =new JFileChooser();//这个对象就是我们点击打开⽂件,出来的⽂件选择器fc.setCurrentDirectory(new File("."));//指定当前默认⽬录fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);//可以选择只打开⽂件或者⽂件夹 fc.setMultiSelectionEnabled(false);//是否允许多选⽂件int i =fc.showOpenDialog(getContentPane());if(i==JFileChooser.APPROVE_OPTION) {//判断是否打开File file =fc.getSelectedFile();//显⽰选中内容jt.setText(fc.getSelectedFile().getName());try{FileReader fr =new FileReader(file);BufferedReader in =new BufferedReader (fr);String line= in.readLine();//读取txt⽂件中的内容s =line.split(" ");//以空格为分隔符,存储⼈名NewMessage(); //监听事件getjcomboBox();//监听事件}catch(Exception e1) {e1.printStackTrace();}}}});}4.“关于”按钮监听事件private void getAboutButton() {AboutButton.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {jo.showMessageDialog(null, "可建⽴txt⽂件:\n写⼊班级名字然后空格学⽣名字\n名字和名字之间必须要⽤空格隔开\n即可识别班级名称和⼈数以及名单"); }});}5.下拉列表框选择监听事件private void getjcomboBox() {jc.addItemListener(new ItemListener() {public void itemStateChanged(ItemEvent e) {if(e.getStateChange() == ItemEvent.SELECTED) {String itemSize = (String) e.getItem();if(itemSize=="抽取⼀⼈") {Number =1;}if(itemSize=="抽取三⼈") {Number =3;}if(itemSize=="抽取五⼈") {Number =5;}}}});}6.“开始抽取”按钮监听事件private void getSrartButton() {StartButton.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {switch(Number) {case 1:int num1 =(int)1+(int)(Math.random()*(s.length-1-1));jt2.setText(s[num1]);break;case 3:int []num3=new int[100];for(int i=0;i<100;i++) {num3[i]=(int)1+(int)(Math.random()*(s.length-1-1));}for(int i=0;i<98;i++) {if(num3[i]!=num3[i+1] && num3[i]!=num3[i+2] && num3[i+1]!=num3[i+2]) {String strtext1= s[num3[i]]+" "+s[num3[i+1]]+" "+s[num3[i+2]];jt2.setText(strtext1);break;}}break;case 5:int []num5=new int[100];for(int i=0;i<100;i++) {num5[i]=(int)1+(int)(Math.random()*(s.length-1-1));}for(int i=0;i<95;i++) {if(num5[i]!=num5[i+1] && num5[i]!=num5[i+2] && num5[i]!=num5[i+3] && num5[i]!=num5[i+4]&& num5[i+1]!=num5[i+2] && num5[i+1]!=num5[i+3] && num5[i+1]!=num5[i+4]&&num5[i+2]!=num5[i+3] && num5[i+2]!=num5[i+4]&&num5[i+3]!=num5[i+4]) {String strtext1= s[num5[i]]+" "+s[num5[i+1]]+" "+s[num5[i+2]]+" "+s[num5[i+3]]+" "+s[num5[i+4]];jt2.setText(strtext1);break;}}break;}}});}7.如果成功打开⽂件并读取,⽂本框显⽰内容private void NewMessage() {ClassjT.setText(s[0]);String s1="";s1=""+(s.length-1);NumjT.setText(s1);jt2.setFont(font);jt2.setForeground(Color.blue);jt2.setText("已就绪,请开始抽取。
04_Java基础语法_第4天(方法、数组)_讲义
04_Java基础语法_第4天(⽅法、数组)_讲义第4天Java基础语法今⽇内容介绍◆随机点名器案例◆库存管理案例封装◆其他知识点今⽇内容学习⽬标◆能独⽴完成“随机点名器”案例源代码编写、编译及运⾏操作◆能独⽴完成“库存管理”案例源代码编写、编译及运⾏操作◆能够完成在源代码中使⽤⽅法进⾏运算操作◆能够完成在源代码中使⽤数组进⾏运算操作第1章随机点名器案例1.1案例介绍随机点名器,即在全班同学中随机的打印出⼀名同学名字。
要做的随机点名器,它具备以下3个内容:●存储所有同学姓名●总览全班同学姓名●随机点名其中⼀⼈,打印到控制台在编写案例前,我们先来学习下本案例中所涉及到的知识点:●⽅法●数组1.2案例学习⽬标●能独⽴完成“随机点名器”案例源代码编写、编译及运⾏操作●能够完成在源代码中使⽤⽅法进⾏运算操作●能够完成在源代码中使⽤数组进⾏运算操作1.3⽅法今天我们来详细聊聊Java中的⽅法,那么,⽅法是什么呢?假设有⼀个游戏程序,程序在运⾏过程中,要不断地发射炮弹。
发射炮弹的动作需要编写100⾏的代码,在每次实现发射炮弹的地⽅都需要重复地编写这100⾏代码,这样会导致程序变得很臃肿,可读性也⾮常差。
那么,为了解决代码重复编写的问题,我们可以将发射炮弹的代码提取出来放在⼀个{}中,并为这段代码起个名字,这样在每次发射炮弹的地⽅通过这个名字来调⽤发射炮弹的代码就可以了。
上述过程中,所提取出来的代码可以被看作是程序中定义的⼀个⽅法,程序在需要发射炮弹时调⽤该⽅法即可。
接下来通过⼀些案例来介绍⽅法在程序中起到的作⽤,先来看⼀下在不使⽤⽅法时如何实现打印三个长宽不同的矩形,如下所⽰。
MethodDemo01.javapublic class MethodDemo01 {public static void main(String[] args) {// 下⾯的循环是使⽤*打印⼀个宽为5、⾼为3的矩形for (int i = 0; i < 3; i++) {for (int j = 0; j < 5; j++) {System.out.print("*");}System.out.println("");}System.out.println("");// 下⾯的循环是使⽤*打印⼀个宽为4、⾼为2的矩形for (int i = 0; i < 2; i++) {for (int j = 0; j < 4; j++) {System.out.print("*");}System.out.println();}System.out.println();// 下⾯的循环是使⽤*打印⼀个宽为10、⾼为6的矩形for (int i = 0; i < 6; i++) {for (int j = 0; j < 10; j++) {System.out.print("*");}System.out.println();}System.out.println();}}运⾏结果如下图所⽰。
随机点名器的设计
右边按钮的“点击”事件代码为
thisform.timer2.enabled=.t. bel1.caption=" "
Timer1的Timer事件代码
s=thisform.edit1.value &&读取编辑框到字符串s n=occurs(chr(13),s) &&统计编辑框中的总行数 k=int(rand()*n)+1 &&产生随机数k:1...n if k>1
左边按钮的“点击”事件代码为
if this.caption=="开始(\<S)" thisform.timer1.enabled=.t. this.caption="停止(\<S)"
else thisform.timer1.enabled=.f. this.caption="开始(\<S)" endif
thisform.edit1.setfocus
mand1.enabled=.f.
endif
else
if thisform.width>370 &&设表单收拢到宽度370
thisform.width=thisform.width-10 &&收拢窗体右边
else
this.enabled=.f.
&&收拢停止
this.tag="0"
&&设已收拢标志
mand2.caption="输入名单"
s=thisform.edit1.value &&读取编辑框到字符串s
n=occurs(chr(13),s) &&统计编辑框ed=.t.
小案例之随机点名系统
⼩案例之随机点名系统 随机点名系统 近⽇,本⼈学习了对象和计时器,就想写⼀个⼩案例随机点名系统,这个⼩案例其实很简单只需要⽣成随机下标,从数组中取值并运⽤innerHTML⽅法将获取到的信息显⽰到⽹页上(这⾥有⼈会提出疑问,字符串也可以遍历为什么不⽤字符串呢?原因很简单字符串⽆法分隔每个名字。
)话不多说直接上代码。
<!DOCTYPE html><html><head><meta charset="utf-8"><title></title><script src="public.js" type="text/javascript" charset="utf-8"></script><style>#name{font-size: 60px;text-align: center;margin: 100px auto;}#start{width: 180px;height: 60px;border: none;background: dodgerblue;display: block;margin: 0 auto;color: #fff;font-size: 30px;border-radius: 6px;text-align: center;line-height: 60px;cursor: pointer;}#start:active{background-color: hotpink;}</style></head><body><div class="main"><div id="name">随机点名系统</div><span id="start">点击开始</span></div></body><script type="text/javascript">var oName = document.getElementById("name");var oStart = document.getElementById("start");var names = "霍⾦,⽜顿,爱因斯坦,达尔⽂,门捷列夫,⽡特,普希⾦,孔⼦,⽼⼦,庄⼦";var arr = names.split(",");// 设置函数var time = 1;var begin = null;oStart.onclick = function() {if (time == 1) {begin = setInterval(function() {oName.innerHTML = arr[random(0, arr.length - 1)];}, 50)oStart.innerHTML = "点击结束";time = 2;} else {clearInterval(begin);oStart.innerHTML = "点击开始";time = 1;}}</script></html> 这⾥就是随机点名系统的所有代码,接下来就为⼤家讲解⼀下代码: 开始我们先设置DOM结构,很简单的⼀个⼤div⾥⾯嵌套⼀个⼩的div⽤来放着名字,⼀个span标签⽤来设置按钮,关于DOM结构的css,代码中写的很详细可以⾃⼰看,这⾥就不多讲解了。
1122 java点名程序说明文档 ALL
用java编写点名程序效果图:一、使用方法按开始,开始点名,按停止人名停止闪动。
二、步骤首先用swing组件制作界面,主体使用boderlayout布局,北部为一个默认流布局的Jpanel,上面有两个按钮,中间部分是一个自定义面板,并在其中添加了一个线程使其可以闪动。
程序第一部分为组件定义,定义各个按钮文本框与计算变量。
第二部分通过构造函数初始化各个组件,为各个组件设置显示内容,添加事件监听者(类name),并注册监听,构造函数最后是设置界面大小显示等。
第三部分是设定事件(actionPerformed),name类本身作为监听者,开始与停止两个按钮的点击为事件,开始按钮创建线程并开始循环,停止按钮通过调用stoprun方法修改while循环控制参数run来停止线程。
第四部分是自定义面板mypanel,继承了Jpanel类,重写了其中的paint函数,使其可以绘制人名。
并将mypanel类做成线程,实现runable接口,其run方法就是使用while循环反复重绘mypanel面板来实现名字闪烁,闪烁间隔为0.1s,重绘内容为通过getname类获得的hashmap中的人名,通过随机生成的整数作为key值来获取value值,并将其绘制在mypanel上。
线程的开始于停止通过两个自定义方法startrun和stoprun来实现,具体方法是控制while循环条件来开始和停止循环。
第五部分是文件读取类getame,通过读取txt文件name,来获得人名,并保存读取的行数。
,创建hashmap将行数作为key值,人名作为value值保存起来。
第四部分是在主函数创建对象na。
三、编写代码import java.awt.FlowLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileInputStream;import java.io.FileWriter;import java.io.InputStreamReader;import java.util.Random;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;public class N02RollCall {JFrame fr=new JFrame("研究生点名");JPanel jp=new JPanel();public static String LuckyName;public void RollCall(){fr.setSize(600, 380);jp.setLayout(null);JButton jButton1=new JButton("点名");jButton1.setBounds(100, 100, 100, 50);jButton1.setFont(new java.awt.Font("黑体",1,22));JLabel jLabel1=new JLabel("杨晨");jLabel1.setBounds(100, 200, 500, 50);jLabel1.setFont(new java.awt.Font("黑体",1,25));JLabel jLabel2=new JLabel("恭喜你,被点到了!");jLabel2.setBounds(200, 300, 200, 50);jLabel2.setFont(new java.awt.Font("黑体",1,20));jp.add(jButton1);fr.add(jLabel1);fr.add(jLabel2);fr.add(jp);fr.setVisible(true);jButton1.addActionListener(newActionListener(){public void actionPerformed(ActionEvent e){N02RollCall you=new N02RollCall();you.dianMing();jLabel1.setText(LuckyName);// System.out.println(LuckyName);}});fr.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});}public void dianMing() {long randomNum = System.currentTimeMillis();int randomNumber = (int) randomNum%(43-1)+1;String PostStu[];PostStu=new String[45];int i;i=0;System.out.println(randomNumber);try { // 防止文件建立或读取失败,用catch捕捉错误并打印,也可以throw/* 读入TXT文件 */String pathname = "D:\\student.txt"; // 绝对路径或相对路径都可以,这里是绝对路径,写入文件时演示相对路径 File filename = new File(pathname); // 要读取以上路径的input。
随机点名器java课程设计
随机点名器java课程设计一、课程目标知识目标:1. 让学生掌握Java基本语法和编程结构,特别是数组、循环和条件语句的使用。
2. 使学生了解随机数生成在程序设计中的应用,理解其原理和实现方式。
3. 帮助学生掌握面向对象编程的基本概念,包括类的定义、对象的使用及构造方法。
技能目标:1. 培养学生运用Java编程解决问题的能力,特别是设计小型应用程序的实际操作技能。
2. 通过设计随机点名器,让学生学会如何将实际问题转化为程序逻辑,提高编程思维和逻辑分析能力。
3. 让学生能够使用集成开发环境(IDE)进行代码编写、调试和运行,具备基本的编程实践技能。
情感态度价值观目标:1. 培养学生对于编程的兴趣和热情,鼓励他们主动探索新知识,敢于面对编程挑战。
2. 增强学生的团队协作意识,通过分组讨论、合作完成项目,提高沟通能力和团队精神。
3. 引导学生认识到编程在现实生活中的应用价值,激发他们将所学知识服务于社会、解决实际问题的责任感。
本课程针对初中或高中年级的学生设计,结合其认知水平和学习特点,旨在通过实践性强的课程活动,使学生将理论知识与实践操作相结合。
课程要求学生在理解基本概念的基础上,能够动手编写程序,培养解决实际问题的能力,同时注重培养学生积极的学习态度和良好的价值观。
通过本课程的学习,学生应能够独立完成一个具有实用价值的随机点名器Java程序,并在过程中获得成就感,激发进一步学习的动力。
二、教学内容1. Java基本语法和编程结构复习:涵盖变量声明、数据类型、运算符、数组、循环结构(for、while)和条件语句(if-else、switch)。
- 教材章节:第2章《Java基础语法》- 教学安排:2课时2. 随机数生成器的原理与实现:- 教材章节:第6章《Java数组》中的随机数部分- 教学安排:1课时3. 面向对象基础:- 类的定义、对象的创建与使用、构造方法- 教材章节:第7章《面向对象编程基础》- 教学安排:2课时4. 随机点名器程序设计:- 设计思路分析、代码编写、调试与优化- 教材章节:综合应用案例- 教学安排:3课时5. 项目实践:- 分组进行项目实践,包括需求分析、设计、编码、测试和总结- 教学安排:4课时6. 课程总结与展示:- 各小组展示作品,分享编程经验,总结学习收获- 教学安排:1课时教学内容的选择和组织遵循由浅入深、循序渐进的原则,确保学生能够扎实掌握基础知识,逐步过渡到复杂的应用程序设计。
JavaScript实现抖音较火的随机点名系统
JavaScript实现抖⾳较⽕的随机点名系统前段时间刷抖⾳,发现⼀个⽐较好玩的随机抽查系统,⽼师可以⽤它抽查到的名字回答问题,提⾼课堂活跃度和专注度。
今天我⽤javaScript实现了⼀个,代码如下可直接粘贴1 <!DOCTYPE html>2 <html lang="en">34 <head>5 <meta charset="UTF-8">6 <meta name="viewport" content="width=device-width, initial-scale=1.0">7 <meta http-equiv="X-UA-Compatible" content="ie=edge">8 <title>点名/抽奖系统</title>9 <style>10 body {11 user-select: none;12 }1314 .showBox {15 margin: 50px auto;16 width: 620px;17 height: auto;18 overflow: hidden;19 text-align: center;20 }2122 .showBox .title {23 text-align: left;24 font-size: 26px;25 line-height: 100px;26 text-decoration: underline;27 font-style: oblique;28 color: #c06;29 }3031 .showBox .showName {32 height: 400px;33 font-size: 40px;34 line-height: 400px;35 border-radius: 20px;36 box-shadow: 2px 2px 5px #333;37 }3839 .showBox .btn {40 margin-top: 20px;41 display: inline-block;42 padding: 10px 15px;43 cursor: pointer;44 color: #fff;45 background-color: #c06;46 border-radius: 5px;47 box-shadow: 1px 1px 1px #333;48 }49 </style>50 </head>5152 <body>53 <div class="showBox">54 <div class="title">点名/抽奖系统</div>55 <div class="showName">ready</div>56 <div class="btn">开始</div>57 </div>58 <script>59var oShowName = document.querySelector(".showName"),60 oBtn = document.querySelector(".btn"),61 bol = true, //通过判断true/false完成开始/结束的效果62 timer; //定时器6364// 封装函数65function myFun() {66var aName = ["⼆哈", "忆梓", "松果林", "松果菊", "⽆为", "万章", "默契", "胖贼", "孟亚兰", "张⼤胖", "奢望", "西奥"], //此数组放置姓名,⽤英⽂分号包裹,英⽂逗号分隔67 ranNum = parseInt(Math.random() * aName.length);68 oShowName.innerHTML = aName[ranNum];69 }70 oBtn.onclick = function() {71if (bol) {72 bol = false;73 oBtn.innerHTML = "结束";74 oShowName.style.color = "#099";75 timer = setInterval("myFun()", 200); //bol为true时开启定时器76 } else {77 bol = true;78 oBtn.innerHTML = "开始";79 oShowName.style.color = "#fc3";80 clearInterval(timer); //bol为false时结束定时器81 }82 }83 </script>84 </body>8586 </html>效果图如下:当然也可以实现简单的抽奖,,欢迎⼤佬批评教育。
Java实现简单随机点名器
Java实现简单随机点名器2-3随机点名器/*随机点名器*1.储存所有同学的名字*2.总览全班同学的姓名*3.随机点取⼀⼈的姓名*/package Chap2Gramma.chooseperson;import java.util.Random;import java.util.Scanner;public class demo {//放全部⼈的名字static String[] name=new String[100];//计算⽬前的⼈数static int count=0;public static void main(String[] args) {Scanner scanner=new Scanner(System.in);show();int number=scanner.nextInt();while (number!=0){switch (number){case(1):add(name);break;case(2):query(name);break;case(3):choose(name);break;}show();number=scanner.nextInt();}}static void add(String[] name){System.out.println("请输⼊你要添加同学的姓名");Scanner scanner=new Scanner(System.in);name[count]=scanner.nextLine();count++;}static void query(String[] name){System.out.println("⽬前⼈输为"+count);System.out.println("名单");if(count==100){System.out.println("⼈数已达到最⼤值,不能再添加");return;}for(int i=0;i< count;i++){System.out.println(name[i]);}}static void choose(String[] name){int choice= new Random().nextInt(count);System.out.println("被点到的同学是"+name[choice]);}static void show(){System.out.println("请选择功能");System.out.println("1.输⼊名字");System.out.println("2.看全班同学的名字");System.out.println("3.随机点名");System.out.println("0.退出");}}。
JAVA做的一个小程序 随机点名器
Java做的一个小程序,随机点名器1.import java.io.*;2.import java.awt.*;3.import java.awt.event.*;4.import java.util.List;5.import java.util.ArrayList;6.7.public class DianName extends Frame{8.9.private String fileName="a.txt";10.private File f;11.private FileReader fr;12.private BufferedReader br;13.private List<String>names=new ArrayList<String>();14.private String strName;15.16.private Label labelName;17.private Button btOK;18.19.public static void main(String[]args){20.DianName dn=new DianName();21.dn.newFrame();22.dn.read();23.}24.25.public void newFrame(){belName=new Label("显示姓名");27.btOK=new Button("开始");28.29.this.setLocation(300,300);30.this.setResizable(false);31.this.setSize(500,400);32.this.add(labelName,BorderLayout.NORTH);33.this.add(btOK,BorderLayout.SOUTH);34.this.pack();35.this.setVisible(true);36.this.addWindowListener(new WindowAdapter(){37.public void windowClosing(WindowEvent e){38.System.exit(0);39.}40.});41.btOK.addActionListener(new ButtonAction());42.}43.44.public void read(){45.try{46.f=new File(fileName);47.if(!f.exists()){48. f.createNewFile();49.}50.fr=new FileReader(f);51.br=new BufferedReader(fr);52.String str=br.readLine();53.while(str!=null){s.add(str);55.str=br.readLine();56.}57.}catch(Exception e){58. e.printStackTrace();59.}60.61.}62.63.public void write(){64.try{65.int index=(int)(Math.random()*names.size());66.strName=names.get(index);67.}catch(Exception e){68. e.printStackTrace();69.}70.71.}72.73.private class ButtonAction implements ActionListener{74.public void actionPerformed(ActionEvent e){75.write();belName.setText(strName);77.}78.}79.}。
基于java的学生点名系统
软件系统设计---基于java的学生考勤系统学院:通信与电子工程学院班级:学号:姓名:同组成员:指导老师:日期: 2013年12月20日摘要在计算机和手机技术广泛推广的今天,应用计算机已经大大的提高了社会的各方面的效率。
而作为学校,社会知识的高度集中区,计算机已经成为一种必需品。
有了计算机,那么我们就应该在方方面面想到用它来提高我们的效率。
对于大学生的考勤方面,现在越来越显示出重要性。
虽然大学生都已经步入成年,但是有些时候会出现小小的偷懒也情有可原。
很多方面还需要代课老师和学校的监督,当然对于上课考勤很占用时间,而且效果不好,老师也不能对学生每次考勤情况都有明确的了解,所以一个可视化的考勤系统称为必须。
本课程设计采用java web技术,利用SSH框架,以JSP页面的形式与网络进行连接,设计了基于Java的考勤系统,该系统不仅解决了现存考勤方式的不足,还可以实现按班级、按科目、按时间、按学生姓名查询学生的考勤请假情况,能够提升课堂效率,增进师生关系,有利于老师了解缺席的特殊情况并即时知晓教学效果,避免错点或漏点现象。
关键词:javaweb技术; SSH框架;考勤系统; JSP页面目录摘要 (I)第1章绪论................................................................................................ 错误!未定义书签。
1.1 概述 (2)1.2 系统分析 (1)1.2.1 传统与计算机考勤的比较 (1)1.2.2 C/S模式与B/S模式的比较分析 (1)1.2.3 java web中的SSH框架 (1)1.3 国内外现存考勤方式 (2)1.3.1 基于Flash的随机考勤系统 (2)1.3.2 基于指纹的考勤系统 (3)1.2.3 基于C#的语音考勤系统 (3)第2章基本模块设计 (4)2.1 主要类创建与数据表的创建 (4)2.1.1 类创建分析 (4)2.1.2 数据表创建 (4)2.2 页面显示及服务器选择 (5)2.2.1 tomcat服务器介绍 (5)2.2.2 JSP网页语言的优势 (5)2.3 mvc设计模式的介绍 (6)第3章实现的主要功能 (8)3.1 学生模块功能设计 (8)3.1.1 学生模块功能具体设计 (8)3.2 教师模块功能设计 (10)3.2.1 教师模块功能具体设计 (10)3.3 管理员模块功能设计 (12)3.3.1 管理员模块功能具体设计 (12)第4章实现的主要功能 (14)4.1 对出现的bug进行统一分析 (14)结论 (15)参考文献 (16)第1章绪论1.1 概述现今,高校老师为检查同学的出勤率,主要通过学生名单进行抽点或进行学生即时提交作业及签到的方式,这些方式难免会出现浪费时间,代考勤等现象。
教学点名神器-随机点名器
教学点名神器——随机点名器3.0随机点名器功能又一大提升,而且之前若干bug均已修复。
修复内容:1.当默认开启的txt文本文件被删除或的文件名被更改或由于某种未知的原因不能访问时,程序不会报错,而是将一些提示信息以学生名导入。
例如:程序默认访问“电科一班.txt”:如果在可执行文件的路径下有“电科一班.txt”文件,则运行正常。
如果在可执行文件的路径下没有找到“电科一班.txt”文件,则运行提示信息。
在这种非正常情况下,如果仍然点击正式记录,则弹出提示帮助信息窗口。
这样,用户在看到提示信息后,会自行修复该问题。
修复2:若读取的文件中存在空行,则程序在读取文件内容的时候会自动删除空行。
现在,我把先前文件名“电科一班121314.txt”修改为“电科一班.txt”,然后在文件内容中加两个空行,如下图所示:程序在运行的时候再也不会出现空姓名。
程序运行一圈后,会给出提示信息。
功能提升:1.可以选择班级,班级内容自定义。
现在,我又新建了一个班级文件“1班.txt”,文件内容如下:现在可以选择班级,我就把“1班.txt”选进来。
一般,“选择班级...”,在程序打开后只会用一次,点击“打开”后,“选择班级...”按钮被隐藏。
2.增加出勤记录,答问记录功能。
若没有点击“正式记录”按钮,抽取信息不会被记录,也没有弹出出勤相关的选择按钮。
功能与旧版一样。
一旦点击正式记录,由于这个记录涉及到学生的平时成绩,因此非常重要,所以弹出是否确定选择对话框。
点击确定后,”正式记录“按钮被隐藏。
再次抽取后,会弹出“缺勤”和“差评”两个选择按钮,并自动在该班级目录下新建一个“班级名+点名记录清单”文本文件。
文本内容自动记录第一次被点到的学生,并创建时间,原创者,班级信息相关信息。
如下所示:若点击差评或缺勤,记录会自动加一,而且,一旦选择之后,该两个按钮即被隐藏,防止误操作。
当然你也可以不行,直接抽下一个人,但选择按钮照样被隐藏,同样该学生的点名信息也会被记录。
java实现课堂随机点名小程序
java实现课堂随机点名⼩程序通过jdbc连接数据库实现读取学⽣花名册进⾏随机点名! ~jdbc连接mysql数据库 || 注释部分代码可通过读取.txt⽂档实现显⽰学⽣信息 ~通过点击开始按钮实现界⾯中间标签不断更新学⽣信息,当按下停⽌时显⽰唯⼀学⽣信息,并调⽤random对象函数实现随机抽取数据库学⽣信息 ~界⾯功能简单,主要实现事件监听和线程实现与销毁。
//Menu.javapackage a1;import javax.swing.JFrame;public class Menu {public static void main(String[] args) { //主程序randoms n = new randoms();FromEx f=new FromEx();n.AListener(f);n.setResizable(false);n.setTitle("学号点名⼩程序");n.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);n.setBounds(700, 200, 100, 200);n.setSize(400, 300);n.setVisible(true);}}//randoms.javapackage a1;import java.awt.*;import javax.swing.*;import javax.swing.JFrame;public class randoms extends JFrame{JLabel num;//显⽰标题JButton start,stop; // 开始、停⽌按钮JLabel rs; //显⽰结果JPanel jp1,jp2;ExListener listener;static boolean isSotp = true; //判断当前状态public randoms() {init();}void init(){num = new JLabel("<<玩的就是⼼跳>>");num.setFont(new Font("⿊体", 2, 40));start = new JButton("开始");stop = new JButton("停⽌");rs = new JLabel("0");jp1 = new JPanel();jp2 = new JPanel();this.add(num,BorderLayout.NORTH);jp1.add(rs);this.add(jp1,BorderLayout.CENTER);FlowLayout layout = new FlowLayout();//⾯板布局layout.setAlignment(FlowLayout.CENTER);jp1.setLayout(layout);jp2.setLayout(layout);jp2.add(start);jp2.add(stop);rs.setFont(new Font("宋体", 1, 30));//设置结果样式rs.setForeground(Color.RED);this.add(jp2,BorderLayout.SOUTH);}void AListener(ExListener listener){this.listener=listener;listener.set(start, stop, rs, isSotp);start.addActionListener(listener); //添加监听stop.addActionListener(listener);//添加监听}}//Exlistener.javapackage a1;import java.awt.event.ActionListener;import javax.swing.*;public interface ExListener extends ActionListener{public void set(JButton J1,JButton J2,JLabel rs,boolean isSotp); }//ExThead.java 线程的实现package a1;import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;import java.util.ArrayList;import java.util.Random;import java.util.Vector;import javax.swing.*;public class ExThread extends Thread{private JLabel rs;boolean isSotp;int n;String a="";//ArrayList<String> array=new ArrayList<String>();Vector vector=new Vector();int getn;/*ExThread(JLabel rs,int n,boolean a){this.rs = rs;this.n = n;isSotp=a;}*/void setbool(boolean a){isSotp=a;};void setint(int a){n=a;};ExThread(JLabel rs) throws IOException{this.rs = rs;v(vector);//m(array);/* //注释部分读取.txt⽂档获取花名册信息BufferedReader m=new BufferedReader(new FileReader("a.txt"));while ((a = m.readLine()) != null) {array.add(a);}getn=array.size();*/}public void v(Vector a){a=vector;try{Class.forName("com.mysql.jdbc.Driver");//加载 MySQL 驱动程序//建⽴与数据库的连接String url = "jdbc:mysql://localhost:3306/conarry";Connection cn = DriverManager.getConnection(url,"root","guoxiaotong");Statement cmd = cn.createStatement();//创建 Statement 对象System.out.println("123");String sql="select * from student";ResultSet r=cmd.executeQuery(sql);while(r.next()){String n1=r.getString(1);//获取数据库第⼀⾏第⼀列String n2=r.getString(2); //获取数据库第⼀⾏第⼆列String n3=n1+" "+n2; //连接学号和姓名a.add(n3);}getn=a.size();} catch (Exception e) {e.printStackTrace();}}/*public void m(ArrayList<String> array){this.array=array;try{Class.forName("com.mysql.jdbc.Driver");//加载 MySQL 驱动程序//建⽴与数据库的连接String url = "jdbc:mysql://localhost:3306/conarry";Connection cn = DriverManager.getConnection(url,"root","guoxiaotong");Statement cmd = cn.createStatement();//创建 Statement 对象System.out.println("123");String sql="select * from student";ResultSet r=cmd.executeQuery(sql);while(r.next()){String n1=r.getString(1);String n2=r.getString(2);String n3=n1+" "+n2;array.add(n3);}getn=array.size();} catch (Exception e) {e.printStackTrace();}}*/@Overridepublic void run() {while(isSotp){try {Thread.sleep(500);rs.setText((String) vector.get(getnumber(getn)));System.out.println("1232");} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}public static int getnumber(int n){ //根据你输⼊的总⼈数返回随机在⼈数范围内的⼀个学号Random r = new Random();int r1 = r.nextInt(n);return r1;}}//FromEx.java 事件监听接⼝实现重写两个⽅法package a1;import java.awt.event.ActionEvent;import java.io.IOException;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JTextField;public class FromEx implements ExListener {JButton start,stop;JLabel rs;static boolean isSotp;ExThread t;public void set(JButton J1,JButton J2,JLabel rs,boolean isSotp){ start=J1;stop=J2;this.rs=rs;this.isSotp=isSotp;try {t= new ExThread(rs);} catch (IOException e) {// TODO ⾃动⽣成的 catch 块e.printStackTrace();}}public void actionPerformed(ActionEvent e){Object o = e.getSource();//获取触发事件对象实现监听映射。
Java随机产生中文昵称
Java随机产⽣中⽂昵称有时候我们注册⼀个⽹站第⼀次登陆系统会产⽣⼀个随机昵称供⽤户选择,在项⽬测试阶段遇到了这个问题,因为注册时没有让⽤户填写昵称,于是找了两种产⽣随机中⽂昵称的⽅法:代码如下package com.util;import java.io.UnsupportedEncodingException;import java.util.HashSet;import java.util.Iterator;import java.util.Random;/*** @Title: randomName* @Description: 随机取名字* @param simple 是否单姓* @param len ⽣成姓名长度* @return String 名字*/public class RandomName {public static void main(String[] args) {/**随机产⽣100个昵称*/HashSet<String> set = new HashSet<String>();for (int i = 0; i < 100; i++) {String chineseName = randomName(true,3);if (!set.contains(chineseName)) {set.add(chineseName);}}Iterator<String> iterator = set.iterator();while (iterator.hasNext()) {System.err.print(iterator.next() + "\n");}}/**⽅法1*/public static String getRandomJianHan(int len) {String randomName = "";for (int i = 0; i < len; i++) {String str = null;int hightPos, lowPos; // 定义⾼低位Random random = new Random();hightPos = (176 + Math.abs(random.nextInt(39))); // 获取⾼位值lowPos = (161 + Math.abs(random.nextInt(93))); // 获取低位值byte[] b = new byte[2];b[0] = (new Integer(hightPos).byteValue());b[1] = (new Integer(lowPos).byteValue());try {str = new String(b, "GBK"); // 转成中⽂} catch (UnsupportedEncodingException ex) {ex.printStackTrace();}randomName += str;}return randomName;}/**⽅法2*/public static String randomName(boolean simple, int len) {String surName[] = { "赵","钱","孙","李","周","吴","郑","王","冯","陈","楮","卫","蒋","沈","韩","杨", "朱","秦","尤","许","何","吕","施","张","孔","曹","严","华","⾦","魏","陶","姜", "戚","谢","邹","喻","柏","⽔","窦","章","云","苏","潘","葛","奚","范","彭","郎", "鲁","韦","昌","马","苗","凤","花","⽅","俞","任","袁","柳","酆","鲍","史","唐", "费","廉","岑","薛","雷","贺","倪","汤","滕","殷","罗","毕","郝","邬","安","常", "乐","于","时","傅","⽪","卞","齐","康","伍","余","元","⼘","顾","孟","平","黄","和","穆","萧","尹","姚","邵","湛","汪","祁","⽑","禹","狄","⽶","贝","明","臧", "计","伏","成","戴","谈","宋","茅","庞","熊","纪","舒","屈","项","祝","董","梁", "杜","阮","蓝","闽","席","季","⿇","强","贾","路","娄","危","江","童","颜","郭", "梅","盛","林","刁","锺","徐","丘","骆","⾼","夏","蔡","⽥","樊","胡","凌","霍", "虞","万","⽀","柯","昝","管","卢","莫","经","房","裘","缪","⼲","解","应","宗", "丁","宣","贲","邓","郁","单","杭","洪","包","诸","左","⽯","崔","吉","钮","龚", "程","嵇","邢","滑","裴","陆","荣","翁","荀","⽺","於","惠","甄","麹","家","封", "芮","羿","储","靳","汲","邴","糜","松","井","段","富","巫","乌","焦","巴","⼸", "牧","隗","⼭","⾕","车","侯","宓","蓬","全","郗","班","仰","秋","仲","伊","宫", "宁","仇","栾","暴","⽢","斜","厉","戎","祖","武","符","刘","景","詹","束","龙", "叶","幸","司","韶","郜","黎","蓟","薄","印","宿","⽩","怀","蒲","邰","从","鄂", "索","咸","籍","赖","卓","蔺","屠","蒙","池","乔","阴","郁","胥","能","苍","双", "闻","莘","党","翟","谭","贡","劳","逄","姬","申","扶","堵","冉","宰","郦","雍", "郤","璩","桑","桂","濮","⽜","寿","通","边","扈","燕","冀","郏","浦","尚","农", "温","别","庄","晏","柴","瞿","阎","充","慕","连","茹","习","宦","艾","鱼","容", "向","古","易","慎","⼽","廖","庾","终","暨","居","衡","步","都","耿","满","弘", "匡","国","⽂","寇","⼴","禄","阙","东","欧","⽎","沃","利","蔚","越","夔","隆", "师","巩","厍","聂","晁","勾","敖","融","冷","訾","⾟","阚","那","简","饶","空", "曾","⽏","沙","乜","养","鞠","须","丰","巢","关","蒯","相","查","后","荆","红", "游","竺","权","逑","盖","益","桓","公","晋","楚","阎","法","汝","鄢","涂","钦", "岳","帅","缑","亢","况","后","有","琴","商","牟","佘","佴","伯","赏","墨","哈", "谯","笪","年","爱","阳","佟"};String doubleSurName[] = {"万俟","司马","上官","欧阳","夏侯","诸葛","闻⼈","东⽅","赫连","皇甫","尉迟","公⽺","澹台","公冶","宗政","濮阳","淳于","单于","太叔","申屠","公孙","仲孙","轩辕","令狐","锺离","宇⽂","长孙","慕容","鲜于","闾丘","司徒","司空","丌官","司寇","仉","督","⼦车","颛孙","端⽊","巫马","公西","漆雕","乐正","壤驷","公良","拓拔","夹⾕","宰⽗","⾕梁","段⼲","百⾥","东郭","南门","呼延","归","海","⽺⾆","微⽣","梁丘","左丘","东门","西门","南宫"};String[] word = {"⼀","⼄","⼆","⼗","丁","⼚","七","⼘","⼈","⼊","⼋","九","⼏","⼉","了","⼒","乃","⼑","⼜", "三","于","⼲","亏","⼠","⼯","⼟","才","⼨","下","⼤","丈","与","万","上","⼩","⼝","⼱","⼭", "千","乞","川","亿","个","勺","久","凡","及","⼣","丸","么","⼴","亡","门","义","之","⼫","⼸", "⼰","已","⼦","卫","也","⼥","飞","刃","习","叉","马","乡","丰","王","井","开","夫","天","⽆", "元","专","云","扎","艺","⽊","五","⽀","厅","不","太","⽝","区","历","尤","友","匹","车","巨", "⽛","屯","⽐","互","切","⽡","⽌","少","⽇","中","冈","贝","内","⽔","见","午","⽜","⼿","⽑", "⽓","升","长","仁","什","⽚","仆","化","仇","币","仍","仅","⽄","⽖","反","介","⽗","从","今", "凶","分","乏","公","仓","⽉","⽒","勿","⽋","风","丹","匀","乌","凤","勾","⽂","六","⽅","⽕", "为","⽃","忆","订","计","户","认","⼼","尺","引","丑","巴","孔","队","办","以","允","予","劝", "双","书","幻","⽟","刊","⽰","末","未","击","打","巧","正","扑","扒","功","扔","去","⽢","世", "古","节","本","术","可","丙","左","厉","右","⽯","布","龙","平","灭","轧","东","卡","北","占", "业","旧","帅","归","且","旦","⽬","叶","甲","申","叮","电","号","⽥","由","史","只","央","兄", "叼","叫","另","叨","叹","四","⽣","失","⽲","丘","付","仗","代","仙","们","仪","⽩","仔","他", "斥","⽠","乎","丛","令","⽤","甩","印","乐","句","匆","册","犯","外","处","冬","鸟","务","包", "饥","主","市","⽴","闪","兰","半","汁","汇","头","汉","宁","⽳","它","讨","写","让","礼","训", "必","议","讯","记","永","司","尼","民","出","辽","奶","奴","加","召","⽪","边","发","孕","圣", "对","台","⽭","纠","母","幼","丝","式","刑","动","扛","寺","吉","扣","考","托","⽼","执","巩", "圾","扩","扫","地","扬","场","⽿","共","芒","亚","芝","朽","朴","机","权","过","⾂","再","协", "西","压","厌","在","有","百","存","⽽","页","匠","夸","夺","灰","达","列","死","成","夹","轨", "邪","划","迈","毕","⾄","此","贞","师","尘","尖","劣","光","当","早","吐","吓","⾍","曲","团", "同","吊","吃","因","吸","吗","屿","帆","岁","回","岂","刚","则","⾁","⽹","年","朱","先","丢", "⾆","⽵","迁","乔","伟","传","乒","乓","休","伍","伏","优","伐","延","件","任","伤","价","份", "华","仰","仿","伙","伪","⾃","⾎","向","似","后","⾏","⾈","全","会","杀","合","兆","企","众", "爷","伞","创","肌","朵","杂","危","旬","旨","负","各","名","多","争","⾊","壮","冲","冰","庄", "庆","亦","刘","齐","交","次","⾐","产","决","充","妄","闭","问","闯","⽺","并","关","⽶","灯", "州","汗","污","江","池","汤","忙","兴","宇","守","宅","字","安","讲","军","许","论","农","讽", "设","访","寻","那","迅","尽","导","异","孙","阵","阳","收","阶","阴","防","奸","如","妇","好", "她","妈","戏","⽻","观","欢","买","红","纤","级","约","纪","驰","巡","寿","弄","麦","形","进", "戒","吞","远","违","运","扶","抚","坛","技","坏","扰","拒","找","批","扯","址","⾛","抄","坝", "贡","攻","⾚","折","抓","扮","抢","孝","均","抛","投","坟","抗","坑","坊","抖","护","壳","志", "扭","块","声","把","报","却","劫","芽","花","芹","芬","苍","芳","严","芦","劳","克","苏","杆", "杠","杜","材","村","杏","极","李","杨","求","更","束","⾖","两","丽","医","⾠","励","否","还", "歼","来","连","步","坚","旱","盯","呈","时","吴","助","县","⾥","呆","园","旷","围","呀","吨", "⾜","邮","男","困","吵","串","员","听","吩","吹","呜","吧","吼","别","岗","帐","财","针","钉", "告","我","乱","利","秃","秀","私","每","兵","估","体","何","但","伸","作","伯","伶","佣","低", "你","住","位","伴","⾝","皂","佛","近","彻","役","返","余","希","坐","⾕","妥","含","邻","岔", "肝","肚","肠","龟","免","狂","犹","⾓","删","条","卵","岛","迎","饭","饮","系","⾔","冻","状", "亩","况","床","库","疗","应","冷","这","序","⾟","弃","冶","忘","闲","间","闷","判","灶","灿","弟","汪","沙","汽","沃","泛","沟","没","沈","沉","怀","忧","快","完","宋","宏","牢","究","穷", "灾","良","证","启","评","补","初","社","识","诉","诊","词","译","君","灵","即","层","尿","尾", "迟","局","改","张","忌","际","陆","阿","陈","阻","附","妙","妖","妨","努","忍","劲","鸡","驱", "纯","纱","纳","纲","驳","纵","纷","纸","纹","纺","驴","纽","奉","玩","环","武","青","责","现", "表","规","抹","拢","拔","拣","担","坦","押","抽","拐","拖","拍","者","顶","拆","拥","抵","拘", "势","抱","垃","拉","拦","拌","幸","招","坡","披","拨","择","抬","其","取","苦","若","茂","苹", "苗","英","范","直","茄","茎","茅","林","枝","杯","柜","析","板","松","枪","构","杰","述","枕", "丧","或","画","卧","事","刺","枣","⾬","卖","矿","码","厕","奔","奇","奋","态","欧","垄","妻", "轰","顷","转","斩","轮","软","到","⾮","叔","肯","齿","些","虎","虏","肾","贤","尚","旺","具", "果","味","昆","国","昌","畅","明","易","昂","典","固","忠","咐","呼","鸣","咏","呢","岸","岩", "帖","罗","帜","岭","凯","败","贩","购","图","钓","制","知","垂","牧","物","乖","刮","秆","和", "季","委","佳","侍","供","使","例","版","侄","侦","侧","凭","侨","佩","货","依","的","迫","质", "欣","征","往","爬","彼","径","所","舍","⾦","命","斧","爸","采","受","乳","贪","念","贫","肤", "肺","肢","肿","胀","朋","股","肥","服","胁","周","昏","鱼","兔","狐","忽","狗","备","饰","饱", "饲","变","京","享","店","夜","庙","府","底","剂","郊","废","净","盲","放","刻","育","闸","闹", "郑","券","卷","单","炒","炊","炕","炎","炉","沫","浅","法","泄","河","沾","泪","油","泊","沿", "泡","注","泻","泳","泥","沸","波","泼","泽","治","怖","性","怕","怜","怪","学","宝","宗","定", "宜","审","宙","官","空","帘","实","试","郎","诗","肩","房","诚","衬","衫","视","话","诞","询", "该","详","建","肃","录","⾪","居","届","刷","屈","弦","承","孟","孤","陕","降","限","妹","姑", "姐","姓","始","驾","参","艰","线","练","组","细","驶","织","终","驻","驼","绍","经","贯","奏", "春","帮","珍","玻","毒","型","挂","封","持","项","垮","挎","城","挠","政","赴","赵","挡","挺", "括","拴","拾","挑","指","垫","挣","挤","拼","挖","按","挥","挪","某","甚","⾰","荐","巷","带", "草","茧","茶","荒","茫","荡","荣","故","胡","南","药","标","枯","柄","栋","相","查","柏","柳", "柱","柿","栏","树","要","咸","威","歪","研","砖","厘","厚","砌","砍","⾯","耐","耍","牵","残", "殃","轻","鸦","皆","背","战","点","临","览","竖","省","削","尝","是","盼","眨","哄","显","哑", "冒","映","星","昨","畏","趴","胃","贵","界","虹","虾","蚁","思","蚂","虽","品","咽","骂","哗", "咱","响","哈","咬","咳","哪","炭","峡","罚","贱","贴","⾻","钞","钟","钢","钥","钩","卸","缸", "拜","看","矩","怎","牲","选","适","秒","⾹","种","秋","科","重","复","竿","段","便","俩","贷", "顺","修","保","促","侮","俭","俗","俘","信","皇","泉","⿁","侵","追","俊","盾","待","律","很", "须","叙","剑","逃","⾷","盆","胆","胜","胞","胖","脉","勉","狭","狮","独","狡","狱","狠","贸", "怨","急","饶","蚀","饺","饼","弯","将","奖","哀","亭","亮","度","迹","庭","疮","疯","疫","疤", "姿","亲","⾳","帝","施","闻","阀","阁","差","养","美","姜","叛","送","类","迷","前","⾸","逆", "总","炼","炸","炮","烂","剃","洁","洪","洒","浇","浊","洞","测","洗","活","派","洽","染","济", "洋","洲","浑","浓","津","恒","恢","恰","恼","恨","举","觉","宣","室","宫","宪","突","穿","窃", "客","冠","语","扁","袄","祖","神","祝","误","诱","说","诵","垦","退","既","屋","昼","费","陡", "眉","孩","除","险","院","娃","姥","姨","姻","娇","怒","架","贺","盈","勇","怠","柔","垒","绑", "绒","结","绕","骄","绘","给","络","骆","绝","绞","统","耕","耗","艳","泰","珠","班","素","蚕", "顽","盏","匪","捞","栽","捕","振","载","赶","起","盐","捎","捏","埋","捉","捆","捐","损","都", "哲","逝","捡","换","挽","热","恐","壶","挨","耻","耽","恭","莲","莫","荷","获","晋","恶","真", "框","桂","档","桐","株","桥","桃","格","校","核","样","根","索","哥","速","逗","栗","配","翅", "辱","唇","夏","础","破","原","套","逐","烈","殊","顾","轿","较","顿","毙","致","柴","桌","虑", "监","紧","党","晒","眠","晓","鸭","晃","晌","晕","蚊","哨","哭","恩","唤","啊","唉","罢","峰", "圆","贼","贿","钱","钳","钻","铁","铃","铅","缺","氧","特","牺","造","乘","敌","秤","租","积", "秧","秩","称","秘","透","笔","笑","笋","债","借","值","倚","倾","倒","倘","俱","倡","候","俯", "倍","倦","健","臭","射","躬","息","徒","徐","舰","舱","般","航","途","拿","爹","爱","颂","翁", "脆","脂","胸","胳","脏","胶","脑","狸","狼","逢","留","皱","饿","恋","桨","浆","衰","⾼","席", "准","座","脊","症","病","疾","疼","疲","效","离","唐","资","凉","站","剖","竞","部","旁","旅", "畜","阅","羞","瓶","拳","粉","料","益","兼","烤","烘","烦","烧","烛","烟","递","涛","浙","涝", "酒","涉","消","浩","海","涂","浴","浮","流","润","浪","浸","涨","烫","涌","悟","悄","悔","悦", "害","宽","家","宵","宴","宾","窄","容","宰","案","请","朗","诸","读","扇","袜","袖","袍","被", "祥","课","谁","调","冤","谅","谈","谊","剥","恳","展","剧","屑","弱","陵","陶","陷","陪","娱", "娘","通","能","难","预","桑","绢","绣","验","继","球","理","捧","堵","描","域","掩","捷","排", "掉","堆","推","掀","授","教","掏","掠","培","接","控","探","据","掘","职","基","著","勒","黄", "萌","萝","菌","菜","萄","菊","萍","菠","营","械","梦","梢","梅","检","梳","梯","桶","救","副", "票","戚","爽","聋","袭","盛","雪","辅","辆","虚","雀","堂","常","匙","晨","睁","眯","眼","悬", "野","啦","晚","啄","距","跃","略","蛇","累","唱","患","唯","崖","崭","崇","圈","铜","铲","银", "甜","梨","犁","移","笨","笼","笛","符","第","敏","做","袋","悠","偿","偶","偷","您","售","停", "偏","假","得","衔","盘","船","斜","盒","鸽","悉","欲","彩","领","脚","脖","脸","脱","象","够", "猜","猪","猎","猫","猛","馅","馆","凑","减","毫","⿇","痒","痕","廊","康","庸","⿅","盗","章", "竟","商","族","旋","望","率","着","盖","粘","粗","粒","断","剪","兽","清","添","淋","淹","渠", "渐","混","渔","淘","液","淡","深","婆","梁","渗","情","惜","惭","悼","惧","惕","惊","惨","惯", "寇","寄","宿","窑","密","谋","谎","祸","谜","逮","敢","屠","弹","随","蛋","隆","隐","婚","婶", "颈","绩","绪","续","骑","绳","维","绵","绸","绿","琴","斑","替","款","堪","搭","塔","越","趁", "趋","超","提","堤","博","揭","喜","插","揪","搜","煮","援","裁","搁","搂","搅","握","揉","斯", "期","欺","联","散","惹","葬","葛","董","葡","敬","葱","落","朝","辜","葵","棒","棋","植","森", "椅","椒","棵","棍","棉","棚","棕","惠","惑","逼","厨","厦","硬","确","雁","殖","裂","雄","暂", "雅","辈","悲","紫","辉","敞","赏","掌","晴","暑","最","量","喷","晶","喇","遇","喊","景","践", "跌","跑","遗","蛙","蛛","蜓","喝","喂","喘","喉","幅","帽","赌","赔","⿊","铸","铺","链","销",。
随机点名小程序----JAVA版本
随机点名⼩程序----JAVA版本话不多少,直接上代码 ⼀个能够直接运⾏的随机点名的⼩程序,⼀个界⾯化的⼩程序。
望⼴⼤⽹友多多⽀持!1.创建⼀个随机点名的类1public class ProcessRandomName {23 JFrame rFrame;4 JLabel name;5 JButton btn;6 Random rd;78 ArrayList<String> nameList = new ArrayList<>();910public ProcessRandomName() {11 rFrame = new JFrame("随机点名");12 name = new JLabel();13 btn = new JButton("开始点名");14 rd = new Random();15 }1617public void init() {18 SetName(nameList);19 JLabel jLabel = new JLabel("随机点名器");20 jLabel.setHorizontalAlignment(0);21 jLabel.setFont(new Font("开始点名了", 0, 35));2223 name.setHorizontalAlignment(0);24 btn.addActionListener(new ActionListener() {2526final ProcessRandomName this$0;2728public void actionPerformed(ActionEvent paramActionEvent) {29 String curindex = getRandomName();30 name.setText(curindex);31 name.setFont(new Font(curindex, 0, 35));32 name.setForeground(Color.red);33 }3435 {36this$0 = ProcessRandomName.this;37// super();38 }39 });4041 Container p = rFrame.getContentPane();42 p.setLayout(new BorderLayout(3, 1));43 p.add(jLabel, "North");44 p.add(name, "Center");45 p.add(btn, "South");46// p.setBackground(Color.black);4748 rFrame.pack();49 rFrame.setVisible(true);50 rFrame.setSize(300,300);51 rFrame.setDefaultCloseOperation(0);52 rFrame.setResizable(true);53 rFrame.setLocationRelativeTo(null);54 rFrame.addWindowListener(new WindowListener() {5556 @Override57public void windowOpened(WindowEvent paramWindowEvent) {58 paramWindowEvent.getComponent();59 rFrame.isShowing();60 }6162 @Override63public void windowIconified(WindowEvent paramWindowEvent) {64// TODO Auto-generated method stub6566 }6768 @Override69public void windowDeiconified(WindowEvent paramWindowEvent) {70// TODO Auto-generated method stub7172 }7374 @Override75public void windowDeactivated(WindowEvent paramWindowEvent) {76// TODO Auto-generated method stub7778 }7980 @Override81public void windowClosing(WindowEvent paramWindowEvent) {82 System.exit(0);83 }8485 @Override86public void windowClosed(WindowEvent paramWindowEvent) {87// TODO Auto-generated method stub8889 }9091 @Override92public void windowActivated(WindowEvent paramWindowEvent) {93// TODO Auto-generated method stub9495 }96 });97 }9899public void SetName(ArrayList<String> nameList) {100 nameList.add("张三");101 nameList.add("李四");102 nameList.add("王五");103 nameList.add("代雪");104105 }106107public String getRandomName() {108int index = 1;109 index = rd.nextInt(nameList.size());110 String nameIndex= nameList.get(index);111return nameIndex;112 }113 }2.创建⼀个运⾏的类1public static void main(String[] args) {2 ProcessRandomName test = new ProcessRandomName();3 test.init();45 }简单的做了以上两个步骤Ctrl+C,Ctrl+V就能创建⼀个随机点名的⼩程序,如果想要⽣成⼀个可运⾏的exe⽂件,。
java点名签到功能实现方法
java点名签到功能实现方法在Java中实现一个点名签到功能,你需要考虑几个关键的步骤。
以下是一个简单的实现方法:1. 设计数据库结构:首先,你需要一个数据库来存储学生的信息。
这个数据库至少应该包含学生的姓名和是否已经签到的信息。
2. 建立数据库连接:使用Java的JDBC(Java Database Connectivity)库来连接你的数据库。
3. 编写签到逻辑:当学生尝试签到时,你需要检查他们是否已经签到。
如果已经签到,则不做任何事情;如果尚未签到,则更新数据库中的状态并标记他们已签到。
下面是一个简单的代码示例,这个示例使用Java和JDBC来连接到MySQL 数据库,并实现一个基本的点名签到功能:```javaimport ;import ;import ;import ;public class AttendanceSystem {private static final String DB_URL = "jdbc:private static final String USER = "root";private static final String PASS = "password";public static void main(String[] args) {String studentName = "John Doe"; // 学生姓名checkAttendance(studentName);}public static void checkAttendance(String studentName) {try {Connection conn = (DB_URL, USER, PASS);String query = "SELECT FROM students WHERE name = ?"; PreparedStatement pstmt = (query);(1, studentName);ResultSet rs = ();if (()) {boolean isPresent = ("is_present");if (!isPresent) {updateAttendance(studentName);} else {(studentName + " has already checked in.");}} else {("Student not found in the system.");}();();();} catch (Exception e) {();}}public static void updateAttendance(String studentName) { try {Connection conn = (DB_URL, USER, PASS);String query = "UPDATE students SET is_present = true WHERE name = ?";PreparedStatement pstmt = (query);(1, studentName);int rowsAffected = ();if (rowsAffected > 0) {(studentName + " has been marked present.");} else {("No rows were affected.");}();();} catch (Exception e) {();}}}```在这个示例中,我们假设有一个名为`students`的表,其中包含学生的姓名和是否已经签到的信息。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Java做的一个小程序,随机点名器
1.import java.io.*;
2.import java.awt.*;
3.import java.awt.event.*;
4.import java.util.List;
5.import java.util.ArrayList;
6.
7.public class DianName extends Frame{
8.
9.private String fileName="a.txt";
10.private File f;
11.private FileReader fr;
12.private BufferedReader br;
13.private List<String> names=new ArrayList<String>();
14.private String strName;
15.
16.private Label labelName;
17.private Button btOK;
18.
19.public static void main(String[] args){
20. DianName dn=new DianName();
21. dn.newFrame();
22. dn.read();
23. }
24.
25.public void newFrame(){
26. labelName=new Label("显示姓名");
27. btOK=new Button("开始");
28.
29.this.setLocation(300,300);
30.this.setResizable(false);
31.this.setSize(500,400);
32.this.add(labelName,BorderLayout.NORTH);
33.this.add(btOK,BorderLayout.SOUTH);
34.this.pack();
35.this.setVisible(true);
36.this.addWindowListener(new WindowAdapter(){
37.public void windowClosing(WindowEvent e){
38. System.exit(0);
39. }
40. });
41. btOK.addActionListener(new ButtonAction());
42. }
43.
44.public void read(){
45.try{
46. f=new File(fileName);
47.if(!f.exists()){
48. f.createNewFile();
49. }
50. fr=new FileReader(f);
51. br=new BufferedReader(fr);
52. String str=br.readLine();
53.while(str!=null){
54. names.add(str);
55. str=br.readLine();
56. }
57. }catch(Exception e){
58. e.printStackTrace();
59. }
60.
61. }
62.
63.public void write(){
64.try{
65.int index=(int)(Math.random()*names.size());
66. strName=names.get(index);
67. }catch(Exception e){
68. e.printStackTrace();
69. }
70.
71. }
72.
73.private class ButtonAction implements ActionListener{
74.public void actionPerformed(ActionEvent e){
75. write();
76. labelName.setText(strName);
77. }
78. }
79.}。