本文原創,禁止轉載!
因爲事情比較多,就想把代待辦事項記錄下來,可是網上找了一圈都不太好用,用java自己寫了一個軟件,運行後會直接貼在屏幕右上角,然後設置開機自啓動,每次都會加載,要修改時點擊三下“更改”(防止錯誤更改)就好了,方便簡單。資料保存在硬盤,斷電關機資料都不會消失。
代碼,就一個類
package EasyNotes; import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JRootPane; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import javax.swing.JButton; import javax.swing.JTextArea; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Toolkit; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.io.File; import java.io.IOException; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class mainFrame extends JFrame { private JPanel contentPane; int lock=0; String filePrefix="D://EasyNotes//data//"; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { mainFrame frame = new mainFrame(); frame.setUndecorated(true); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. * @throws Exception */ public mainFrame() throws Exception { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //setBounds(100, 100, 305, 417); Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screensize = kit.getScreenSize(); int width = screensize.width; int height = screensize.height; if(width-260>0&&height-417>0) { setBounds(width-260, 0, 260, 380); }else { setBounds(600, 0, 260, 380); } contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JButton b1 = new JButton("\u66F4\u6539"); b1.setOpaque(true); b1.setForeground(Color.WHITE); b1.setBackground(Color.BLACK); b1.setFont(new Font("宋體", Font.BOLD, 26)); b1.setBounds(0, 350, 163, 30); contentPane.add(b1); JTextArea t1 = new JTextArea(); t1.setForeground(Color.WHITE); t1.setBackground(Color.BLACK); t1.setBounds(0, 0, 260, 150); t1.setFont(new Font("宋體", Font.BOLD, 26)); contentPane.add(t1); JTextArea t2 = new JTextArea(); t2.setForeground(Color.WHITE); t2.setBackground(Color.GRAY); t2.setBounds(0, 150, 260, 200); t2.setFont(new Font("宋體", Font.BOLD, 26)); contentPane.add(t2); t1.setLineWrap(true); t2.setLineWrap(true); File p=new File(filePrefix); if(!p.exists()) {p.mkdirs();} File f1=new File(filePrefix+"notes1.txt"); File f2=new File(filePrefix+"notes2.txt"); if(!f1.exists()) {f1.createNewFile();} if(!f2.exists()) {f2.createNewFile();} txtOpration t=new txtOpration(); t1.setText(t.readTxt(filePrefix+"notes1.txt")); t2.setText(t.readTxt(filePrefix+"notes2.txt")); JButton b2 = new JButton("\u95DC\u9589"); b2.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { System.exit(0); } }); b2.setForeground(Color.WHITE); b2.setFont(new Font("宋體", Font.BOLD, 26)); b2.setOpaque(true); b2.setBackground(Color.BLACK); b2.setBounds(163, 350, 97, 30); contentPane.add(b2); b1.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if(lock>=3) { txtOpration t=new txtOpration(); try { t.writeTxt(t1.getText(), filePrefix+"notes1.txt"); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { t.writeTxt(t2.getText(), filePrefix+"notes2.txt"); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { t1.setText(t.readTxt(filePrefix+"notes1.txt")); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { t2.setText(t.readTxt(filePrefix+"notes2.txt")); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } lock=0; b1.setText("更改"); } else { b1.setText("再按"+(3-lock)+"下解鎖。"); lock++; } } }); } }