模拟文字接龙,班里一天几个接龙真的烦死啦(仅供娱乐)


布局设计

在这里插入图片描述

JFormDesigner布局插件下载,30天限免,常用的自行破解
在这里插入图片描述


功能

  1. Setting导入组织名单(默认路径D:/md.txt)
  2. 在信息头处输入待接龙的信息
  3. 输入成员接龙信息(默认是收到)
  4. 点击Get按钮即可在左侧生成完整模拟接龙

展示主要代码:

Get按钮监听函数(主功能代码写在这,可以独立出去)

private void GetActionPerformed(ActionEvent e) {
        // 得到班级名单
        File file = new File(filePath);
        Reader input = null;
        try {
            input = new FileReader(file);
        } catch (FileNotFoundException fileNotFoundException) {
            fileNotFoundException.printStackTrace();
        }
        BufferedReader in = new BufferedReader(input);
        // 将名单中名字存进数组
        List<String> list = new ArrayList<String>();
        String name = new String();
        while (true){
            try {
                if (!((name = in.readLine()) != null)) break;
            } catch (IOException ioException) {
                ioException.printStackTrace();
            }
            list.add(name);
        }
        // 乱序处理,合并接龙信息头输出
        Collections.shuffle(list);
        Object[] res = list.toArray();
        outputFantan.setText("#接龙\n");
        outputFantan.setText(outputFantan.getText() + inputHeader.getText() + "\n");
        for (int i = 0; i < res.length; i++) {
            outputFantan.setText(outputFantan.getText() + "\n" + (i + 1) + ". " + res[i] + " " + type.getText());
        }
    }

导入名单(JFileChooser)

    private void menuItem1ActionPerformed(ActionEvent e) {
        JFileChooser jf = new JFileChooser();
        jf.showOpenDialog(this);//显示打开的文件对话框
        File f =  jf.getSelectedFile();//使用文件类获取选择器选择的文件
        String s = f.getAbsolutePath();//返回路径名
        //JOptionPane弹出对话框类,显示绝对路径名
        JOptionPane.showMessageDialog(this, s, "Successfully",JOptionPane.INFORMATION_MESSAGE);
        filePath = s;
        System.out.println(filePath);
    }

在这里插入图片描述

技术交流、完整代码请联系微信:13168162412


效果图

请添加图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

莉妮可丝的猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值