圖書館管理系統
- 未完成部分:
- [ ] 申請延期
- [ ] 查看詳情
- [ ] 個人簽名
-
個人覺得有意義的部分
- “記住密碼”功能
- 講展示tip變成一個獨立的工具類
- 使用TreeTable,其歸檔作用用在這里十分合適
-
學到的東西
- RandomAcessFile 就是C的文件指針,超好用,可以同時讀寫還可以跳,除了無法實現刪除,定位修改什么的都十分容易
- JavaFx的定位系統Point2D
- JavaFX的控件TreeTable,DatePicker
-
部分展示
- 頭像顯示不正常,因為資源的路徑沒辦法正確編譯進去
- 頭像顯示不正常,因為資源的路徑沒辦法正確編譯進去
-
數據存儲部分
- 數據文件並未加密
- signedAdmin 存放注冊管理員相關
- signedUser 存放注冊用戶相關
- Books 存放所有書籍
public void saveBooks(){
File file = new File(fileName);
try {
PrintWriter out = new PrintWriter(fileName+".bak");
Scanner in = new Scanner(file);
while(in.hasNextLine()){
String line = in.nextLine();
ArrayList<String> each = new ArrayList<>();
each.addAll(Arrays.asList(line.split(" ")));
if (each.get(0).equals(name)){
if (each.indexOf("<Books>")==-1){
out.print(line+" ");
}else {
for (int i = 0; i < each.indexOf("<Books>"); i++) {
out.print(each.get(i) + " ");
}
}
out.print("<Books> ");
hadBooks.forEach(i -> out.print(i+" "));
out.println("</Books>");
}else out.println(line);
}
in.close();
out.close();
Files.delete(Paths.get(fileName));
new File(fileName+".bak").renameTo(file);
} catch (IOException e) {
System.out.println("文件寫入出錯");
e.printStackTrace();
}
}
- 書店存書
Store.saveBooks
查看源文件
static void saveBooks() {
try {
PrintWriter in = new PrintWriter("Books");
//in.append(each); Attention:FileWriter.append不是追加內容,是流操作
Controller.showAll.forEach(in::println);
in.close();
} catch (IOException e) {
System.out.println("文件寫入出錯");
e.printStackTrace();
}
}
- 書店取書(讀出書店所有的存書)查看源文件
static ArrayList<Book> importBooks() {
addedBooks = new ArrayList<>();
ArrayList<Book> allBooks = new ArrayList<>();
if(!Paths.get("Books").toFile().exists()) {
return allBooks;
}
try {
Files.readAllLines(Paths.get("Books")).stream().map(line -> {
String[] each = line.split(",");
return new Book(each[0], each[1], each[2], parseInt(each[3]));
}).forEach(allBooks::add);
} catch (IOException e) {
e.printStackTrace();
}
return allBooks;
}
Git鏈接:https://github.com/dongmingchao/LibrarySystem
最好clone下來感受,或者在github上有jar包,細節比較多