search
HomeWeChat AppletMini Program DevelopmentShare a small program that counts the amount of code

直接可以运行:选择好src文件夹,直接点“统计行数”就可以啦

import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
 
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
 
@SuppressWarnings("serial")
public class CountRows extends JFrame {
 
    private JPanel contentPane;
    private JTextField absolutePath;
 
    private int num; // 用来存储行数的
    private String path;
 
    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    CountRows frame = new CountRows();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
 
    /**
     * Create the frame.
     */
    public CountRows() {
        setTitle("\u7EDF\u8BA1\u4EE3\u7801\u884C\u6570");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 384, 185);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);
 
        absolutePath = new JTextField();
        absolutePath.setBounds(67, 39, 200, 31);
        contentPane.add(absolutePath);
        absolutePath.setColumns(10);
 
        JLabel lblSrc = new JLabel("src\u8DEF\u5F84");
        lblSrc.setFont(new Font("宋体", Font.PLAIN, 15));
        lblSrc.setBounds(10, 39, 64, 31);
        contentPane.add(lblSrc);
 
        JButton result = new JButton("\u7EDF\u8BA1\u884C\u6570");
        result.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                String path = absolutePath.getText();
                File file = new File(path);
                try {
                    nums(file);
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
                JOptionPane
                        .showMessageDialog(contentPane, "代码一共有:" + num + "行");
            }
        });
        result.setFont(new Font("宋体", Font.PLAIN, 14));
        result.setBounds(48, 100, 93, 37);
        contentPane.add(result);
 
        JButton exit = new JButton("\u9000\u51FA");
        exit.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.exit(1);
            }
        });
        exit.setFont(new Font("宋体", Font.PLAIN, 14));
        exit.setBounds(270, 100, 93, 37);
        contentPane.add(exit);
 
        JButton view = new JButton("\u6D4F\u89C8");
        view.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                JFileChooser jfc = new JFileChooser("c:\\");
                jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                jfc.setDialogTitle("请选择要统计的src文件夹");
                int result = jfc.showOpenDialog(contentPane);
                if (result == JFileChooser.APPROVE_OPTION) {
                    path = jfc.getSelectedFile().getAbsolutePath();
                    absolutePath.setText(path);
                }
            }
        });
        view.setBounds(277, 36, 81, 37);
        contentPane.add(view);
 
    }
 
    /**
     * 写一个方法,用来计算代码量
     * 
     * @throws IOException
     */
    private void nums(File file) throws IOException {
 
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (int i = 0; i 

The above is the detailed content of Share a small program that counts the amount of code. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)