微信小程序> 随机数生成器-小程序自助生成系统-小程序自助开发

随机数生成器-小程序自助生成系统-小程序自助开发

浏览量:13466 时间: 来源:gamedev’
1.

看主播贴吧楼层抽奖时用了,心想自己也编一个试试

2.

小白去年自己编的随机数生成器,比较简陋,功能也单一,当作练手。

3.

Application.java

packagesrc;publicclassApplication{publicstaticvoidmain(String[]args){WindowBoxLayoutwinnewWindowBoxLayout();win.setBounds(100,200,300,350);win.setTitle("随机数生成器");win.setVisible(true);}}4.

RandomListener.java

packagesrc;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.util.Random;importjavax.swing.*;publicclassRandomListenerimplementsActionListener{JTextFieldtext1;JTextAreatext2;RandomrandomnewRandom();intresult0;publicvoidsetJTextField(JTextFieldt){text1t;}publicvoidsetJTextArea(JTextAreat){text2t;}@OverridepublicvoidactionPerformed(ActionEvente){try{text2.setText("");IntegernumberInteger.parseInt(text1.getText());resultrandom.nextInt(number)+1;text2.append(result+"");}catch(Exceptionexp){text2.append("请输入数字字符");}}}5.

Windowboxlayout.java

packagesrc;importjavax.swing.*;publicclassWindowBoxLayoutextendsJFrame{/****/privatestaticfinallongserialVersionUID1L;BoxbaseBox;JTextFieldtext1;JTextAreatext2;JButtonbutton;RandomListenerrandom;publicWindowBoxLayout(){setLayout(newjava.awt.FlowLayout());init();setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}voidinit(){baseBoxBox.createVerticalBox();baseBox.add(newJLabel("请输入随机数的最大范围值:"));baseBox.add(Box.createVerticalStrut(8));text1newJTextField(5);baseBox.add(text1);baseBox.add(Box.createVerticalStrut(8));buttonnewJButton("确定");baseBox.add(Box.createVerticalStrut(8));baseBox.add(button);text2newJTextArea(6,12);baseBox.add(Box.createVerticalStrut(18));baseBox.add(text2);add(baseBox);randomnewRandomListener();random.setJTextField(text1);random.setJTextArea(text2);button.addActionListener(random);}}6.

类结构图:

7.

效果图:

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

最新资讯

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎