如图,没啥复杂功能,就是学习之余练练手{:soso_e149:}- <p>import java.awt.*;
- import java.awt.event.*;</p><p>import javax.swing.*;</p><p>
- public class Random_lol extends JFrame{</p><p> /**
- *
- */
- private static final long serialVersionUID = 1L;
- public Random_lol(){
- try {
- UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
- } catch (ClassNotFoundException e1) {
- // TODO 自动生成的 catch 块
- e1.printStackTrace();
- } catch (InstantiationException e1) {
- // TODO 自动生成的 catch 块
- e1.printStackTrace();
- } catch (IllegalAccessException e1) {
- // TODO 自动生成的 catch 块
- e1.printStackTrace();
- } catch (UnsupportedLookAndFeelException e1) {
- // TODO 自动生成的 catch 块
- e1.printStackTrace();
- }
- setTitle("英雄联盟solo英雄随机器 by 贺奕凯");
- setLayout(null);
- setBounds(800,300,500,350);
- //setSize(450,250);
- setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
- Container cp=getContentPane();
- //getContentPane().setLayout(new FlowLayout());
- final JTextField jt=new JTextField("安妮",10);
- final JButton jb1=new JButton("随机");
- final JButton jb2=new JButton("退出");
- final JLabel jl=new JLabel("数组中最小的数是:");
- final JTextArea ta=new JTextArea("卢锡安\n"+"剑魔\n"+"丽桑卓\n"+"扎克\n"+"奎因\n"+"锤石\n"+"蔚\n"+"娜美\n"+"劫\n"
- +"伊莉丝\n"+"卡'兹克\n"+"辛德拉\n"+"雷恩加尔\n"+"黛安娜\n"+"婕拉\n"+"杰斯\n"+"德莱文\n"+"德莱厄斯\n"+"赫卡里姆\n"
- +"韦鲁斯\n"+"璐璐\n"+"菲奥娜\n"+"诺提勒斯\n"+"瑟庄妮\n"+"吉格斯\n"+"维克托\n"+"阿狸\n"+"沃利贝尔\n"+"菲兹\n"
- +"特朗德尔\n"+"拉克丝\n"+"布兰德\n"+"希瓦娜\n"+"格雷福斯\n"+"泽拉斯\n"+"图奇\n"+"锐雯\n"+"泰隆\n"+"斯卡纳\n"
- +"孙悟空\n"+"蕾欧娜\n"+"约里克\n"+"瑞兹\n"+"卡特琳娜\n"+"裟娜\n"+"斯维因\n"+"乐芙兰\n"+"艾瑞莉娅\n"+"卡西奥佩娅\n"
- +"卡西奥佩娅\n"+"凯特琳\n"+"雷克顿\n"+"卡尔玛\n"+"茂凯\n"+"嘉文四世\n"+"魔腾\n"+"李青\n"+"兰博\n"+"薇恩\n"
- +"奥莉安娜\n"+"科'加斯\n"+"努努\n"+"阿木木\n"+"维迦\n"+"辛吉德\n"+"泰达米尔\n"+"蒙多\n"+"普朗克\n"+"墨菲特\n"
- +"希维尔\n"+"费德提克\n"+"凯尔\n"+"艾尼维亚\n"+"提莫\n"+"艾希\n"+"安妮\n"+"崔丝塔娜\n"+"贾克斯\n"+"易\n"
- +"库奇\n"+"阿利斯塔\n"+"布里茨\n"+"索拉卡\n"+"内瑟斯\n"+"沃里克\n"+"莫甘娜\n"+"拉莫斯\n"+"卡萨丁\n"+"赛恩\n"
- +"塔里克\n"+"迦娜\n"+"基兰\n"+"伊芙琳\n"+"卡尔萨斯\n"+"萨科\n"+"黑默丁格\n"+"阿卡丽\n"+"乌迪尔\n"+"盖伦\n"
- +"塔里克\n"+"凯南\n"+"克格'莫\n"+"玛尔扎哈\n"+"莫德凯撒\n"+"奈德丽\n"+"伊泽瑞尔\n"+"古拉加斯\n"+"奥拉夫\n"+"潘森\n"
- +"波比\n"+"慎\n"+"赵信\n"+"赵信\n"+"弗拉基米尔\n"+"加里奥\n"+"厄加特\n"+"厄运小姐\n",150,1);
-
- JScrollPane sp=new JScrollPane(ta);
- final JTextArea ta2=new JTextArea(10,1);
- JScrollPane sp2=new JScrollPane(ta2);
- final JPanel jp1=new JPanel(new BorderLayout());
- final JPanel jp3=new JPanel(new BorderLayout());
- final JPanel jp2=new JPanel(new GridLayout(2,1,0,20));
- jp1.setBounds(15,15,180,250);
- jp1.setBorder(BorderFactory.createTitledBorder("英雄列表"));
- jp2.setBounds(390,165,80,100);
- jp2.setBorder(BorderFactory.createTitledBorder(" "));
- jp3.setBounds(200,15,180,250);
- jp3.setBorder(BorderFactory.createTitledBorder("随机结果"));
-
-
- jp1.add(jt,(BorderLayout.NORTH));
- jp1.add(sp,(BorderLayout.CENTER));
- jp3.add(sp2,(BorderLayout.CENTER));
- jp2.add(jb1);
- jp2.add(jb2);
-
- cp.add(jp1);
- cp.add(jp2);
- cp.add(jp3);
- //cp.add(jt);
- //cp.add(jb1);
- //cp.add(jb2);
- cp.add(jl);
- jt.addKeyListener(new KeyAdapter(){
- public void keyPressed(KeyEvent e) {
- if(e.getKeyChar()!='\n')
- return;
- String name=jt.getText();
- if(name.isEmpty())
- return;
- ta.append(name+"\n");
- jt.selectAll();
- }
- });
- jb1.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e) {
- String perstring=ta.getText();
- String[] ta=perstring.split("\n{1,}");
- int index=(int)(Math.random()*ta.length);
- int index2=(int)(Math.random()*ta.length);
-
- String formatArg="本次抽取结果:\n\n\nA玩家: %s\n\nB玩家: %s\n";
-
- String info=String.format(formatArg, ta[index],ta[index2]);
- ta2.setText(info);
-
- }
- });
- setVisible(true);
-
-
- jb2.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
-
-
-
- }
- public static void main(String[] args) {
- new Random_lol();
- }
- }
- </p><p> </p>
复制代码 |
|