{
flag = false;
}
}
else
{
codeLines++;
}
}
//将结果保存到output
output+=("代码行数:" + codeLines+"\n"+"注释行数:" + commentLines+"\n"
+"空白行数:" + blankLines+"\n"+"总行数:" + (codeLines+commentLines+blankLines));
//将统计的结果在txa里面显示
txa.setText(output);
}
catch (FileNotFoundException ex)
{
ex.printStackTrace();
}
catch (IOException ex)
{
ex.printStackTrace();
}
finally
{
if (br != null)
{
try {
br.close();
br = null;
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
}
}
}
});
}
//Frame主程序
public static void main(String[] args)
{
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); //windows界面风格
} catch (Exception e) {
e.printStackTrace();
}
CodeCounterFrame frame = new CodeCounterFrame();
frame.setTitle("统计代码的小工具");
frame.setSize(300,200);
frame.setVisible(true);
frame.setLocationRelativeTo(null);//窗体居中显示
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
运行的窗口:
输出的结果:
