抽签 java_「抽签软件」基于Javafx制作的随机抽签软件 – seo实验室

抽签软件

基于javafx制作的随机抽签软件

最近刚学习英语课的时候刚看见英语老师用复古界面的抽签软件(用C语言写的)点名让同学回答问题,UI界面美观值真的是让人汗颜- -,在 上好像也搜不到用javafx做的抽签软件,swing写的倒是挺多的,觉得好玩自己便做了一个类似的抽签软件,希望对javafx感兴趣的新手有点帮助。

软件下载地址

盘:https://pan.baidu.com/s/1W0_KgdJXId2__gth16UzEQ

jar包(源码):链接:https://pan.baidu.com/s/1tvscoLZkO4X7VQu4G5QD1g 提取码:99s5

使用的知识

软件所使用的知识点其实是大多都是UI组件和属性绑定 ,时间相应,监听 ,ArrayList 容器,Iterator迭代器等都是基础的东西,不涉及ODBC数据库和服务器,代码量在1300行左右。Timeline 用来实现名字随机动画的设置 播放

动画的定义和绑定

`eventhandlercolors = e4->{

tf.setFill(Color.color((int)Math.random()*255,(int)Math.random()*255,(int)Math.random()*255));

};

Timeline colorPlay = new Timeline(new KeyFrame(Duration.millis(300),colors));

colorPlay.setCycleCount(Timeline.INDEFINITE);`.

配置文件 (如果没有,则自己创建 ,Eclipse项目中 “save_Data.properties”表示文件在project工程目录下,”srcprivXiaocclasssave_Data.properties”则在.class目录下)

//保存用户配置

public static String save(String URL,ArrayList waitInsertData,ArrayList waitInsertDataValue) {

String ERROR_details =”保存成功!!”;

URL = “save.properties”;

Properties saveFile = new Properties();

try {

Fileoutputstream cin = new FileOutputStream(URL);

for(int i = 0;i

saveFile.setProperty(waitInsertData.get(i).toString(),waitInsertDataValue.get(i).toString()); //save relative Value

}

try {

saveFile.store(cin, null);

} catch (IOException e) {

error_details = “读写成功,保存失败”;

}

try {

cin.close();

} catch (IOException e) {

error_details = “读写成功,保存成功 但关闭失败”;

}

} catch (filenotfoundException e) {

error_details = “文件读写失败”;

}

return error_details;

}

}

//加载用户配置 返回的是名字 和值(键值)的动态字符串数组

public static ArrayList[] load(String URL){

Properties loadFile = new Properties();

Iterator it,value0;

ArrayList names[] = new ArrayList[2];

for(int y=0;y

names[y] = new ArrayList();

}

try {

fileinputstream fis = new FileInputStream(URL);

BufferedInputStream bfis = new BufferedInputStream(fis);

InputStream is = bfis;

try {

loadFile.load(is);

it = loadFile.stringPropertyNames().iterator();

value0= loadFile.stringPropertyNames().iterator();

while(it.hasNext()) { //Get name

names[0].add(it.next());

}

while(value0.hasNext()) { // Get Key Value

names[1].add(loadFile.getProperty(value0.next()));

}

is.close();

bfis.close();

fis.close();

return names;

} catch (IOException e) {

//System.out.println(“加载失败”);

return null;

}

} catch (FileNotFoundException e) {

//System.out.println(“打开文件失败”);

}

return null;

}

读取文件所用到的输入流 输出流 I/O流

//URLFile 是ChooseFile文件选择框选择的文件 ,code是读取的时候的编码 ,默认是UTF-8,我的设置成GBK才不会乱码。。

public ArrayList getFileDetails(File URLFile) { // to get student name;

ArrayList temp = new ArrayList();

FileInputStream cin;

try {

inputstreamreader fr = new InputStreamReader(new FileInputStream(URLFile),code);

BufferedReader bf = new BufferedReader(fr);

String s= null;

while((s = bf.readLine())!=null) {

temp.add(s); //读取每一行学生的名字

}

bf.close();

fr.close();

}catch(Exception e) {};

return temp; //返回所有学生的名字

}

颜色选择器中的颜色十六进制值转RBG

//colorSelect 是颜色选择器实体化的对象

color_name_r = colorselect.getValue().getRed()*255;//R

color_name_g = colorselect.getValue().getGreen()*255; //G

color_name_b = colorselect.getValue().getBlue()*255; //B

color_name = “rgb(“+color_name_r+”,”+color_name_g+”,”+color_name_b+”);”;

mainPane.setStyle(“-fx-background-color:”+color_name);//css设置面板背景颜色

多线程(默认是Javafx-APPlication Thread,如果这时我们要去干其他事情,那么原来的UI界面就会停止响应,界面就会奔溃,直到新任务Task完成才会回到原来的界面,这时我们就应该新建线程,这样就不会阻塞,并发性)

// we start new Thread

Thread ui = new Thread() {

public void run() {

ani2.play();

try {

for(int i = 0;i

this.currentThread().sleep(30);

show.appendText(stu.get(i).toString()+”n”);//一行一行的在文本域中添加学生名字,这样就看起来比较舒畅,而不是一打开文件就直接给你加载完毕,感觉有点快

}

}catch(Exception e) {

tip_m2.settext(e.getmessage());}

} //run

};

ui.start();//新开的线程运行

事件响应,比如Button,Check 等组件的响应

clear.setOnAction(e->{ //清空文本按钮 点击时的处理事件

if(end.getText().length() == 0) {

dosclick.play();

tip_m.setText(“已经空啦”);

}

else

end.setText(“”);

});

事件的监听,当要求输入值得时候,我们往往会给TextFiled文本输入框添加监听事件,例如我们让用户在输入框只能输入数字,数字以外的符 包括字母不准输入,否则一旦输入则立即出现alert之类的错误提示。

//cinextract 是TextFiled的具体化的实例化对象

cinExtract.textProperty().addListener((observation,oldValueLast,newValueNow)->{

try {

if(cinExtract.getText().length()>0)

for(int i = 0;i

if(cinExtract.getText().toString().charAt(i)

cinExtract.getText().toString().charAt(i)>’9′) {

tip_m.setText(“只能输入数字哦”);

cinExtract.setText(“”);

}

}

else {

cinExtract.setText(“1”);

}

if(cinExtract.getText().length()>0) //当学生人数为30人 ,但我们输入了35人,这时cinExtract就会取最大值30,自动改变

if(integer.parseInt(cinExtract.getText())>stu.size()) {

tip_m.setText(“错误 输入数据大于所具有的人数”);

cinExtract.setText(string.format(“%d”,stu.size()));//排版 SDF

}

}catch(Exception error) {

tip.setcontentText(“输入有错误啦 请重新输入吧#_#”);

tip.showAndWait();

};

});

关于Button数组问题

如果一个软件需要用到很多很多按钮,那么设置个Button数组统一对他们操作会比较好点。比如

//一个个

Button select = new Button(“select”);

Button reselect = new Button(“extract”);

Button clear = new Button(“清空”);

Button recover = new Button(“recover”);

Button color = new Button(“color”);

Button cancel =new Button(“pause”);

Button modify_code = new Button(“code”);

Button colorPicker_b = new Button(“colorPickerSelect”);

//数组

Button mainPane_button[] = new Button[8];

for(int i = 0;i

if(i == 0)

mainPane_button[i] = new Button(name);

else

mainPane_button[i] = new Button(otherName);

}

3f569b93a95c6f15bd78763bf59dd01e.png

软件使用exe4j打包,因为用的是开源免费软件,所以打包好的软件在电脑上运行需要有JRE环境,不然将会打不开软件。

相关阅读

##0x00 背景知识ASLR(Address Space Layout Randomization)在2005年被引入到Linux的内核 kernel 2.6.12 中,当然早在2004年就以pat

上关于12306图片验证码的吐槽已经是铺天盖地,当然,现在的12306图片验证码已经不像以前那么变态了。不过鹏哥心里一直有个心结,纵使

在SEO的道路上,白帽SEO人员是孤独的,理由很简单:它需要你在SEO的道路上不断的实践与测试,没有一套完美的普世之路,除非你是深度研究搜

真正意义上的随机数,随机数列是源于随机实验的结果,均匀分布且生成不能重现。例如,使用离子辐射事件的脉冲检测器气体放电管和带泄露

在C语言中,ANSIC C程序库提供rand()函数来产生随机数。但事实上,rand()是并不是一个真正的随机数产生器,即可以预测随机序列的顺序,在

相关资源:ios签名软件-iOS工具类资源

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年1月8日
下一篇 2021年1月8日

相关推荐