快捷键调整

main
dai_48k 2023-11-21 15:16:34 +08:00
parent b7ea976fa8
commit 7afb82fdf2
3 changed files with 34 additions and 11 deletions

View File

@ -5,6 +5,9 @@ start7410
start7410 start7410
2+ 2+
有关成长的优美散文:在体验中成长生活丰富多彩,探索它也是很有趣的。 有关成长的优美散文:在体验中成长生活丰富多彩,探索它也是很有趣的。
@ -13,6 +16,9 @@ start7410
start7410 start7410
3+ 3+
如今社会步入小康,百姓们再也不用像以前一样担忧粮食了。每当到吃饭时间,父母总是做好饭喊我吃,我就只要乖乖吃饭就可以了。 如今社会步入小康,百姓们再也不用像以前一样担忧粮食了。每当到吃饭时间,父母总是做好饭喊我吃,我就只要乖乖吃饭就可以了。
@ -20,6 +26,9 @@ start7410
start7410 start7410
4+ 4+
买菜。 买菜。
@ -28,3 +37,6 @@ start7410

View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: top.dreamcenter.note.Main

View File

@ -72,6 +72,11 @@ public class Main {
@Override @Override
public void keyReleased(KeyEvent e) { public void keyReleased(KeyEvent e) {
dateList.set(curPage[0], date.getText()); dateList.set(curPage[0], date.getText());
switch (e.getKeyCode()) {
case KeyEvent.VK_ENTER -> textArea.requestFocus();
case KeyEvent.VK_ESCAPE -> exitSystem(jf, contentlist, dateList);
}
} }
}); });
@ -100,22 +105,15 @@ public class Main {
date.setText(dateList.get(curPage[0])); date.setText(dateList.get(curPage[0]));
} }
} }
case KeyEvent.VK_F7 -> { // 保存 case KeyEvent.VK_F7 -> saveData(contentlist, dateList);
saveData(contentlist, dateList); case KeyEvent.VK_ESCAPE -> exitSystem(jf, contentlist, dateList);
}
} }
} }
}); });
jf.addWindowListener(new WindowAdapter() { jf.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
int confirm = JOptionPane.showConfirmDialog(jf, "是否保存并退出?", "保存退出", JOptionPane.YES_NO_CANCEL_OPTION); exitSystem(jf, contentlist, dateList);
if (confirm == JOptionPane.YES_OPTION) {
saveData(contentlist, dateList);
System.exit(0);
} else if (confirm == JOptionPane.NO_OPTION) {
System.exit(0);
}
} }
}); });
@ -129,6 +127,16 @@ public class Main {
jf.setVisible(true); jf.setVisible(true);
} }
private static void exitSystem(JFrame jf, LinkedList<String> contentList, LinkedList<String> dateList) {
int confirm = JOptionPane.showConfirmDialog(jf, "是否保存并退出?", "保存退出", JOptionPane.YES_NO_CANCEL_OPTION);
if (confirm == JOptionPane.YES_OPTION) {
saveData(contentList, dateList);
System.exit(0);
} else if (confirm == JOptionPane.NO_OPTION) {
System.exit(0);
}
}
private static void initList(List<String> contentList, List<String> dateList) { private static void initList(List<String> contentList, List<String> dateList) {
if (!file.exists()) { if (!file.exists()) {
try { try {
@ -179,6 +187,7 @@ public class Main {
} }
} }
private static void saveData(List<String> contentList, List<String> dateList){ private static void saveData(List<String> contentList, List<String> dateList){
try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)))) { try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)))) {
for (int i = 0; i < TOTAL_PAGE; i++) { for (int i = 0; i < TOTAL_PAGE; i++) {
@ -200,7 +209,6 @@ public class Main {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
JOptionPane.showMessageDialog(null, "保存失败:" + e.getMessage(), "错误", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, "保存失败:" + e.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
} }
} }
} }