安卓期末大作业 (安卓期末大作业源代码)

安卓期末大作业 (安卓期末大作业源代码)

本文目录导航:

安卓期末大作业-记账app(含源码+导出app+运转截图)

开发软件:Android Studio开发言语:Java名目:2023年上半年移动开发期末大作业记账app效果:95调配置:1. 记载各类账目,包含支出与支出2. 账目存储于数据库3. 账目暗藏配置4. 支出与支出图表剖析5. 清空一切数据选项界面展现:1. 界面展现各类账目支出2. 支出记载界面展现3. 账目记载界面展现4. 账目暗藏配置操作5. 底部配置按钮界面展现6. 清空数据配置操作代码主要局部:1. 设置ListView长按监听2. 显示删除记载对话框3. 成功删除记载操作4. 减少ListView头部规划5. 初始化日期显示6. onResume方法加载与降级数据代码细节复杂度高,成功配置片面,操作直观,便于了解和经常使用。

此记账运行不只提供了基本的账目记载与治理配置,还进一步提供了数据可视化剖析与操作方便性提升,为用户提供了良好的记账体验。

须要一份500行的java程序,期末大作业,最好带具体注释。

* Java生成CSV文件

public class CSVUtil {

* 生成为CVS文件

* @param exportData

*源数据List

* @param map

*csv文件的列表头map

* @param outPutPath

*文件门路

* @param fileName

*文件称号

@SuppressWarnings(rawtypes)

public static File createCSVFile(List exportData, LinkedHashMap map,

String outPutPath, String fileName) {

File csvFile = null;

BufferedWriter csvFileOutputStream = null;

File file = new File(outPutPath);

// 定义文件名格局并创立

csvFile = (fileName, ,

new File(outPutPath));

// UTF-8使正确读取分隔符,

csvFileOutputStream = new BufferedWriter(new OutputStreamWriter(

new FileOutputStream(csvFile), GBK), 1024);

// 写入文件头部

for (Iterator propertyIterator = ()(); propertyIterator

propertyEntry = () propertyIterator

csvFileOutputStream

(\ + (String) () != null ? (String) propertyEntry

// 写入文件内容

for (Iterator iterator = (); ();) {

Object row = (Object) ();

for (Iterator propertyIterator = ()(); propertyIterator

propertyEntry = () propertyIterator

//以下局部依据不同业务做出相应的更改

StringBuilder sbContext = new StringBuilder();

if (null != (row,(String) ())) {

if(证件号码(())){

//防止:身份证号码 ,读取时变换为迷信记数 - 处置方法:加 \t(用Excel关上时,证件号码超越15位后会智能自动迷信记数)

((row,(String) ()) + \t);

((row,(String) ()));

} catch (Exception e) {

} catch (IOException e) {

return csvFile;

* 下载文件

* @param response

* @param csvFilePath

*文件门路

* @param fileName

*文件称号

* @throws IOException

public static void exportFile(HttpServletRequest request,

HttpServletResponse response, String csvFilePath, String fileName)

throws IOException {

(application/csv;charset=GBK);

(Content-Disposition, attachment; filename=

+ new String((GB2312), ISO8859-1));

InputStream in = null;

in = new FileInputStream(csvFilePath);

byte[] buffer = new byte[1024];

OutputStream out = ();

while ((len = (buffer)) > 0) {

(buffer, 0, len);

} catch (FileNotFoundException e1) {

if (in != null) {

} catch (Exception e1) {

throw new RuntimeException(e1);

* 删除该目录filePath下的一切文件

* @param filePath

*文件目录门路

public static void deleteFiles(String filePath) {

File file = new File(filePath);

File[] files = ();

for (int i = 0; i < ; i++) {

if (files[i]()) {

files[i]();

* 删除单个文件

* @param filePath

*文件目录门路

* @param fileName

*文件称号

public static void deleteFile(String filePath, String fileName) {

File file = new File(filePath);

File[] files = ();

for (int i = 0; i < ; i++) {

if (files[i]()) {

if (files[i]()(fileName)) {

files[i]();

@SuppressWarnings({ unchecked, rawtypes })

public void createFileTest() {

List exportData = new ArrayList<Map>();

Map row1 = new LinkedHashMap<String, String>();

row1 = new LinkedHashMap<String, String>();

LinkedHashMap map = new LinkedHashMap();

(1, 第一列);

(2, 第二列);

(3, 第三列);

(4, 第四列);

String path = d:/export;

String fileName = 文件导出;

File file = (exportData, map, path, fileName);

String fileNameNew = ();

String pathNew = ();

(文件称号: + fileNameNew );

(文件门路: + pathNew );

//注(row,(String) ()) + \t ,只为处置数字格局超越15位后,在Excel中打展开现迷信记数疑问。

java源代码编辑器 设计用于编写Java源代码的编辑器,基本要求:可以成功源程序的文件关上,编辑和文件保留

一. 高亮的内容:须要高亮的内容有:1. 主要字, 如 public, int, true 等. 2. 运算符, 如 +, -, *, /等3. 数字4. 高亮字符串, 如 example of string5. 高亮单行注释6. 高亮多行注释二. 成功高亮的外围方法(int offset, int length, AttributeSet s, boolean replace) 三. 文本编辑器选用中提供的多行文本编辑器有: JTextComponent, JTextArea, JTextPane, JEditorPane等, 都可以经常使用. 然而由于语法着色中文本要经常使用多种格调的样式, 所以这些文本编辑器的document要经常使用StyledDocument. JTextArea经常使用的是PlainDocument, 此document不能启动多种格局的着色, JEditorPane经常使用的是StyledDocument, 自动就可以经常使用. 为了成功语法着色, 可以承袭自DefaultStyledDocument, 设置其为这些文本编辑器的documet, 或许也可以间接经常使用JTextPane, JEditorPane来做. 为了繁难, 这里就间接经常使用JTextPane了.四. 何时启动着色.当文本编辑器中有字符被拔出或许删除时, 文本的内容就出现了变动, 这时审核, 启动着色.为了监督到文本的内容出现了变动, 要给document减少一个DocumentListener监听器, 在他的removeUpdate和insertUpdate中启动着色处置.而changedUpdate方法在文本的属性例如前风景, 背风景, 字体等格调扭转时才会被调用. @Override public void changedUpdate(DocumentEvent e) { } @Override public void insertUpdate(DocumentEvent e) {try { colouring((StyledDocument) (), (), ());} catch (BadLocationException e1) { ();} } @Override public void removeUpdate(DocumentEvent e) {try { // 由于删除后光标紧接着影响的单词两头, 所以长度就不须要了 colouring((StyledDocument) (), (), 0);} catch (BadLocationException e1) { ();} }五. 着色范畴: pos: 指变动前光标的位置: 指变动的字符数.例如无主要字public, int单词publicint, 在public和int中拔出一个空格后变成public int, 一个单词变成了两个, 这时对public 和 int启动着色.着色范畴是public中p的位置和int中t的位置加1, 即是pos前面单词开局的下标和pos+len开局单词完结的下标. 所以上例中要着色的范畴是public int. 提供了方法indexOfWordStart来取得pos前单词开局的下标, 方法indexOfWordEnd来取得pos后单词完结的下标. public int indexOfWordStart(Document doc, int pos) throws BadLocationException {// 从pos开局向前找到第一个非单词字符 (; pos > 0 && isWordCharacter(doc, pos - 1); --pos);return pos; } public int indexOfWordEnd(Document doc, int pos) throws BadLocationException {// 从pos开局向前找到第一个非单词字符 (; isWordCharacter(doc, pos); ++pos);return pos; }一个字符是单词的有效字符: 是字母, 数字, 下划线. public boolean isWordCharacter(Document doc, int pos) throws BadLocationException {char ch = getCharAt(doc, pos); // 取得在文档中pos位置处的字符if ((ch) || (ch) || ch == _) { return true; }return false; }所以着色的范畴是[start, end] : int start = indexOfWordStart(doc, pos); int end = indexOfWordEnd(doc, pos + len);六. 主要字着色.从着色范畴的开局下标起启动判别, 假设是以字母开或许下划线扫尾, 则说明是单词, 那么先取得这个单词, 假设这个单词是主要字, 就启动主要字着色, 假设不是, 就启动个别的着色. 着色完这个单词后, 继续前面的着色处置. 曾经着色过的字符, 就不再启动着色了. public void colouring(StyledDocument doc, int pos, int len) throws BadLocationException {// 取得拔出或许删除后影响到的单词.// 例如public在b后拔出一个空格, 就变成了:pub lic, 这时就有两个单词要处置:pub和lic// 这时要取得的范畴是pub中p前面的位置和lic中c前面的位置int start = indexOfWordStart(doc, pos);int end = indexOfWordEnd(doc, pos + len);char ch;while (start < end) { ch = getCharAt(doc, start); if ((ch) || ch == _) {// 假设是以字母或许下划线扫尾, 说明是单词// pos为处置后的最后一个下标start = colouringWord(doc, start); } else {//(new ColouringTask(doc, pos, wordEnd - pos, normalStyle));++start; }} }public int colouringWord(StyledDocument doc, int pos) throws BadLocationException {int wordEnd = indexOfWordEnd(doc, pos);String word = (pos, wordEnd - pos); // 要启动着色的单词if ((word)) { // 假设是主要字, 就启动主要字的着色, 否则经常使用个别的着色. // 这里有一点要留意, 在insertUpdate和removeUpdate的方法调用的环节中, 不能修正doc的属性. // 但咱们又要到达能够修正doc的属性, 所以把此义务放到这个方法的外面去口头. // 成功这一目标, 可以经常使用新线程, 但放到swing的事情队列里去处置更轻巧一点. (new ColouringTask(doc, pos, wordEnd - pos, keywordStyle));} else { (new ColouringTask(doc, pos, wordEnd - pos, normalStyle));}return wordEnd; }由于在insertUpdate和removeUpdate方法中不能修正document的属性, 所以着色的义务放到这两个方法外面, 所以经常使用了来成功. private class ColouringTask implements Runnable {private StyledDocument doc;private Style style;private int pos;private int len;public ColouringTask(StyledDocument doc, int pos, int len, Style style) { = doc; = pos; = len; = style;}public void run() { try {// 这里就是对字符启动着色(pos, len, style, true); } catch (Exception e) {}} }七: 源码主要字着色的成功代码如下, 可以间接编译运转. 关于数字, 运算符, 字符串等的着色处置在以后的教程中会继续启动详解 ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;public class HighlightKeywordsDemo { public static void main(String[] args) {JFrame frame = new JFrame();JTextPane editor = new JTextPane();()(new SyntaxHighlighter(editor));()(editor);(_ON_CLOSE);(500, 500);(true); }}/** * 当文本输入区的有字符拔出或许删除时, 启动高亮. * * 要启动语法高亮, 文本输入组件的document要是styled document才行. 所以不要用JTextArea. 可以经常使用JTextPane. * * @author Biao * */class SyntaxHighlighter implements DocumentListener { private Set<String> keywords; private Style keywordStyle; private Style normalStyle; public SyntaxHighlighter(JTextPane editor) {// 预备着色经常使用的样式keywordStyle = ((StyledDocument) ())(Keyword_Style, null);normalStyle = ((StyledDocument) ())(Keyword_Style, null);(keywordStyle, );(normalStyle, );// 预备主要字keywords = new HashSet<String>();(public);(protected);(private);(_int9);(float);(double); } public void colouring(StyledDocument doc, int pos, int len) throws BadLocationException {// 取得拔出或许删除后影响到的单词.// 例如public在b后拔出一个空格, 就变成了:pub lic, 这时就有两个单词要处置:pub和lic// 这时要取得的范畴是pub中p前面的位置和lic中c前面的位置int start = indexOfWordStart(doc, pos);int end = indexOfWordEnd(doc, pos + len);char ch;while (start < end) { ch = getCharAt(doc, start); if ((ch) || ch == _) {// 假设是以字母或许下划线扫尾, 说明是单词// pos为处置后的最后一个下标start = colouringWord(doc, start); } else {(new ColouringTask(doc, start, 1, normalStyle));++start; }} } /*** 对单词启动着色, 并前往单词完结的下标.* * @param doc* @param pos* @return* @throws BadLocationException*/ public int colouringWord(StyledDocument doc, int pos) throws BadLocationException {int wordEnd = indexOfWordEnd(doc, pos);String word = (pos, wordEnd - pos);if ((word)) { // 假设是主要字, 就启动主要字的着色, 否则经常使用个别的着色. // 这里有一点要留意, 在insertUpdate和removeUpdate的方法调用的环节中, 不能修正doc的属性. // 但咱们又要到达能够修正doc的属性, 所以把此义务放到这个方法的外面去口头. // 成功这一目标, 可以经常使用新线程, 但放到swing的事情队列里去处置更轻巧一点. (new ColouringTask(doc, pos, wordEnd - pos, keywordStyle));} else { (new ColouringTask(doc, pos, wordEnd - pos, normalStyle));}return wordEnd; } /*** 取得在文档中下标在pos处的字符.* * 假设pos为(), 前往的是一个文档的完结符, 不会抛出意外. 假设pos<0, 则会抛出意外.* 所以pos的有效值是[0, ()]* * @param doc* @param pos* @return* @throws BadLocationException*/ public char getCharAt(Document doc, int pos) throws BadLocationException {return (pos, 1)(0); } /*** 取得下标为pos时, 它所在的单词开局的下标. ±wor^d± (^示意pos, ±示意开局或完结的下标)* * @param doc* @param pos* @return* @throws BadLocationException*/ public int indexOfWordStart(Document doc, int pos) throws BadLocationException {// 从pos开局向前找到第一个非单词字符 (; pos > 0 && isWordCharacter(doc, pos - 1); --pos);return pos; } /*** 取得下标为pos时, 它所在的单词完结的下标. ±wor^d± (^示意pos, ±示意开局或完结的下标)* * @param doc* @param pos* @return* @throws BadLocationException*/ public int indexOfWordEnd(Document doc, int pos) throws BadLocationException {// 从pos开局向前找到第一个非单词字符 (; isWordCharacter(doc, pos); ++pos);return pos; } /*** 假设一个字符是字母, 数字, 下划线, 则前往true.* * @param doc* @param pos* @return* @throws BadLocationException*/ public boolean isWordCharacter(Document doc, int pos) throws BadLocationException {char ch = getCharAt(doc, pos);if ((ch) || (ch) || ch == _) { return true; }return false; } @Override public void changedUpdate(DocumentEvent e) { } @Override public void insertUpdate(DocumentEvent e) {try { colouring((StyledDocument) (), (), ());} catch (BadLocationException e1) { ();} } @Override public void removeUpdate(DocumentEvent e) {try { // 由于删除后光标紧接着影响的单词两头, 所以长度就不须要了 colouring((StyledDocument) (), (), 0);} catch (BadLocationException e1) { ();} } /*** 成功着色义务* * @author Biao* */ private class ColouringTask implements Runnable {private StyledDocument doc;private Style style;private int pos;private int len;public ColouringTask(StyledDocument doc, int pos, int len, Style style) { = doc; = pos; = len; = style;}public void run() { try {// 这里就是对字符启动着色(pos, len, style, true); } catch (Exception e) {}} }}

你可能想看:
« 上一篇
下一篇 »

相关推荐

java中什么是冒泡,冒泡算法

2026年09月06日

27阅读

java中冒号,java双冒号

2026年09月06日

24阅读

java中的->,java中的是什么意思

2026年09月06日

24阅读

java中的super用法,Java中super的说明

2026年09月06日

27阅读

java中反射的应用,java中反射的应用场景

2026年09月06日

23阅读

java中开关的定义,Java关键字有哪些

2026年09月06日

25阅读