如何让chatgpt给我们实现一个桌面便签?

news2024/10/5 0:29:30

我: 用Java开发一款桌面便签软件。功能需求:1、便签可以钉在桌面任意角落;2、便签内容实时保存到本地;3、有新增按钮,点击新增时清除当前面板上的内容,新建一条新的便签内容,并保存到本地;4、有查看便签历史功能,点击查看历史,可以查看之前新建的每一条便签内容(因为便签内容保存到本地了,所以是可以查看历史内容的);根据以上4点要求,请帮我写出完整代码。

chatgpt: 以下是一个简单的Java代码示例,实现了您所描述的便签软件的功能需求:

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class DesktopNoteApp extends JFrame {
    private List<String> notes;
    private JTextArea noteTextArea;

    public DesktopNoteApp() {
        notes = new ArrayList<>();
        loadNotes();

        setTitle("桌面便签");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setResizable(false);
        setLayout(new BorderLayout());

        noteTextArea = new JTextArea();
        noteTextArea.setLineWrap(true);
        noteTextArea.setFont(new Font("Arial", Font.PLAIN, 14));

        JScrollPane scrollPane = new JScrollPane(noteTextArea);
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        add(scrollPane, BorderLayout.CENTER);

        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

        JButton newButton = new JButton("新增");
        newButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String note = noteTextArea.getText();
                notes.add(note);
                saveNotes();
                noteTextArea.setText("");
            }
        });
        buttonPanel.add(newButton);

        JButton historyButton = new JButton("查看历史");
        historyButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                StringBuilder history = new StringBuilder();
                for (String note : notes) {
                    history.append(note).append("\n");
                }
                JOptionPane.showMessageDialog(null, history.toString(), "便签历史", JOptionPane.INFORMATION_MESSAGE);
            }
        });
        buttonPanel.add(historyButton);

        add(buttonPanel, BorderLayout.SOUTH);

        pack();
        setLocationRelativeTo(null);
        setVisible(true);
    }

    private void loadNotes() {
        try {
            File file = new File("notes.txt");
            if (file.exists()) {
                BufferedReader reader = new BufferedReader(new FileReader(file));
                String line;
                while ((line = reader.readLine()) != null) {
                    notes.add(line);
                }
                reader.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void saveNotes() {
        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter("notes.txt"));
            for (String note : notes) {
                writer.write(note);
                writer.newLine();
            }
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new DesktopNoteApp();
            }
        });
    }
}

请注意,此代码仅为示例,可能需要根据您的具体需求进行修改和完善。

运行效果

窗口太小、不是置于顶层、无法拖动。新增和查看历史倒是实现了。
在这里插入图片描述

我: 窗口需要可以拖动,并且置于顶层,还有窗口大小调整为400*500

chatgpt: 以下是修改后的代码,实现了窗口可以拖动、置于顶层以及窗口大小调整为400*500的功能:

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class DesktopNoteApp extends JFrame {
    private List<String> notes;
    private JTextArea noteTextArea;
    private Point initialClick;

    public DesktopNoteApp() {
        notes = new ArrayList<>();
        loadNotes();

        setTitle("桌面便签");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setResizable(false);
        setLayout(new BorderLayout());
        setSize(400, 500);

        JPanel titleBar = new JPanel();
        titleBar.setBackground(Color.GRAY);
        titleBar.setLayout(new BorderLayout());

        JLabel titleLabel = new JLabel("桌面便签");
        titleLabel.setForeground(Color.WHITE);
        titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
        titleBar.add(titleLabel, BorderLayout.CENTER);

        titleBar.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                initialClick = e.getPoint();
                getComponentAt(initialClick);
            }
        });

        titleBar.addMouseMotionListener(new MouseAdapter() {
            public void mouseDragged(MouseEvent e) {
                int thisX = getLocation().x;
                int thisY = getLocation().y;

                int xMoved = e.getX() - initialClick.x;
                int yMoved = e.getY() - initialClick.y;

                int x = thisX + xMoved;
                int y = thisY + yMoved;

                setLocation(x, y);
            }
        });

        add(titleBar, BorderLayout.NORTH);

        noteTextArea = new JTextArea();
        noteTextArea.setLineWrap(true);
        noteTextArea.setFont(new Font("微软雅黑", Font.PLAIN, 14));

        JScrollPane scrollPane = new JScrollPane(noteTextArea);
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        add(scrollPane, BorderLayout.CENTER);

        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

        JButton newButton = new JButton("新增");
        newButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String note = noteTextArea.getText();
                notes.add(note);
                saveNotes();
                noteTextArea.setText("");
            }
        });
        buttonPanel.add(newButton);

        JButton historyButton = new JButton("查看历史");
        historyButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                StringBuilder history = new StringBuilder();
                for (String note : notes) {
                    history.append(note).append("\n");
                }
                JOptionPane.showMessageDialog(null, history.toString(), "便签历史", JOptionPane.INFORMATION_MESSAGE);
            }
        });
        buttonPanel.add(historyButton);

        add(buttonPanel, BorderLayout.SOUTH);

        pack();
        setLocationRelativeTo(null);
        setAlwaysOnTop(true);
        setVisible(true);
    }

    private void loadNotes() {
        try {
            File file = new File("notes.txt");
            if (file.exists()) {
                BufferedReader reader = new BufferedReader(new FileReader(file));
                String line;
                while ((line = reader.readLine()) != null) {
                    notes.add(line);
                }
                reader.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void saveNotes() {
        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter("notes.txt"));
            for (String note : notes) {
                writer.write(note);
                writer.newLine();
            }
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new DesktopNoteApp();
            }
        });
    }
}

在这个修改后的代码中,我添加了一个标题栏titleBar,并在标题栏上添加了一个JLabel用于显示标题。我还添加了鼠标事件监听器,以实现窗口的拖动功能。最后,我调用了setAlwaysOnTop(true)方法,将窗口置于顶层。

运行效果
置顶了,但是大小没起作用

在这里插入图片描述

我: setSize(400, 500);不起作用

chatgpt: 抱歉,我之前的回答有误。在这种情况下,您可以使用setPreferredSize(new Dimension(400, 500))方法来设置窗口的大小。请将以下代码添加到构造函数的setSize(400, 500)之后:

setPreferredSize(new Dimension(400, 500));
pack();

这将确保窗口的大小为400x500像素。

运行效果

在这里插入图片描述


我: titleLabel这里高度调高一点,因为现在这样不好看,而且可拖动区域太小了

chatgpt: 要调整titleLabel的高度,您可以在titleBar的布局中添加一个BorderLayout.NORTH约束,并将titleLabel添加到该约束中。然后,您可以使用setPreferredSize(new Dimension(400, 30))方法来设置titleLabel的高度。请将以下代码添加到构造函数的titleBar设置之后:

titleBar.add(titleLabel, BorderLayout.NORTH);
titleLabel.setPreferredSize(new Dimension(400, 30));

这将使titleLabel的高度为30像素,并将其放置在titleBar的顶部。

运行效果

在这里插入图片描述

我: 然后文本区域我希望有一点内外边距,这样文字就不是紧挨着边框了

chatgpt: 要为文本区域添加内外边距,您可以使用setMargin(new Insets(top, left, bottom, right))方法来设置边距。请将以下代码添加到构造函数的noteTextArea设置之后:

noteTextArea.setMargin(new Insets(10, 10, 10, 10));

这将为文本区域的上、左、下、右边添加10像素的边距。您可以根据需要调整边距的大小。

运行效果
在这里插入图片描述

我: 我想把titleLabel去掉,因为窗口title是桌面便签,现在又额外加个label显示桌面便签,感觉很多余

chatgpt: 如果您想要去掉titleLabel,您可以直接将titleBar设置为窗口的标题栏。请将以下代码添加到构造函数的titleBar设置之后:

setUndecorated(true);

这将去掉窗口的标题栏,并使titleBar成为窗口的顶部区域。这样,您就不需要额外的titleLabel来显示标题了。

运行效果
在这里插入图片描述


我: 右键titleBar,弹出右键菜单,右键菜单项有”关闭“

chatgpt: 要将右键菜单添加到titleBar上,并在菜单中添加一个"关闭"菜单项,您可以使用JPopupMenu和JMenuItem来实现。请将以下代码添加到构造函数的titleBar设置之后:


JPopupMenu popupMenu = new JPopupMenu();
JMenuItem closeMenuItem = new JMenuItem("关闭");
closeMenuItem.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        dispose();
    }
});
popupMenu.add(closeMenuItem);

titleBar.addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
        if (e.isPopupTrigger()) {
            popupMenu.show(e.getComponent(), e.getX(), e.getY());
        }
    }

    public void mouseReleased(MouseEvent e) {
        if (e.isPopupTrigger()) {
            popupMenu.show(e.getComponent(), e.getX(), e.getY());
        }
    }
});

这将在titleBar上添加一个右键菜单,并在菜单中添加一个"关闭"菜单项。当用户右键单击titleBar时,将显示右键菜单,并且当用户选择"关闭"菜单项时,窗口将被关闭。

运行效果


我: 启动后,点击查看历史按钮,整个窗口卡住了不能点了。

chatgpt: 这是因为在点击"查看历史"按钮时,您使用了JOptionPane.showMessageDialog来显示历史弹窗,但是由于该方法是阻塞的,它会阻止用户与窗口进行交互。为了解决这个问题,您可以使用JDialog来创建一个非阻塞的自定义弹窗。请将以下代码添加到构造函数的historyButton的ActionListener中:

historyButton.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        JDialog historyDialog = new JDialog();
        historyDialog.setTitle("便签历史");
        historyDialog.setModal(true);
        historyDialog.setResizable(false);
        historyDialog.setLayout(new BorderLayout());
        historyDialog.setPreferredSize(new Dimension(500, 400));

        JTextArea historyTextArea = new JTextArea();
        historyTextArea.setEditable(false);
        historyTextArea.setFont(new Font("微软雅黑", Font.PLAIN, 14));
        historyTextArea.setMargin(new Insets(15, 15, 15, 15));

        JScrollPane scrollPane = new JScrollPane(historyTextArea);
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        historyDialog.add(scrollPane, BorderLayout.CENTER);

        StringBuilder history = new StringBuilder();
        for (String note : notes) {
            history.append(note).append("\n");
        }
        historyTextArea.setText(history.toString());

        historyDialog.pack();
        historyDialog.setAlwaysOnTop(true);
        historyDialog.setLocationRelativeTo(null);
        historyDialog.setVisible(true);
    }
});

这将创建一个非阻塞的自定义弹窗,其中包含一个JTextArea用于显示历史内容。当用户点击"查看历史"按钮时,将显示该弹窗,并将历史内容显示在JTextArea中。这样,用户就可以同时与窗口进行交互和查看历史内容。

运行效果
在这里插入图片描述
。。。。。。

之后,我又让它给我设置窗口透明度,增加系统托盘(右键托盘弹出close菜单,退出应用程序);

然后继新增、查看历史按钮后,又分别让它加了清空、删除两个按钮。其中清空是清空当前面板中的内容,就像新增,点击新增也会清空当前面板内容,只不过新增会先将内容保存再清空。删除则不仅是清空当前面板中的内容,还会将历史内容给全部清空。

在这里插入图片描述

在这里插入图片描述

经过多次询问和调整,最后的效果感觉还可以哈哈哈

最后,我将代码打包,然后用工具转成了exe程序,我发现程序一运行,任务栏会有图标显示(这个图标不是指的托盘图标),如下图:

在这里插入图片描述

这样肯定不行啊,我想让窗口一直显示在桌面,但是任务栏我不想让它显示这个图标,只显示托盘图标,我去问gpt,可是我发现我不知道该怎么给它描述,导致它给的答案牛头不对马嘴。后面我尝试把 JFrame 改成 JDialog 完美解决😎😎

下面是最后的完整代码

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class DesktopNoteApp extends JDialog {
    private List<String> notes;
    private JTextArea noteTextArea;
    private Point initialClick;

    public DesktopNoteApp() {
        notes = new ArrayList<>();
        loadNotes();// 先加载txt文件
        setUndecorated(true);// 去掉外面的边框修饰。
        //setTitle("桌面便签");
        //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setResizable(false);
        setLayout(new BorderLayout());
        setSize(300, 300);
        setPreferredSize(new Dimension(300, 300));
        setOpacity(0.6f);
        pack();

        // 标题栏面板
        JPanel titleBar = new JPanel();
        titleBar.setBackground(Color.decode("#6c768a"));
        titleBar.setLayout(new BorderLayout());

        JLabel titleLabel = new JLabel("桌面便签");
        titleLabel.setForeground(Color.WHITE);
        titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
        titleBar.add(titleLabel, BorderLayout.NORTH);
        titleLabel.setPreferredSize(new Dimension(300, 30));

        titleBar.addMouseListener(new MouseAdapter() {
            // 鼠标按下事件
            public void mousePressed(MouseEvent e) {
                initialClick = e.getPoint();
                getComponentAt(initialClick);
            }
        });

        // 鼠标动作监听器
        titleBar.addMouseMotionListener(new MouseAdapter() {
            // 鼠标拖动
            public void mouseDragged(MouseEvent e) {
                int thisX = getLocation().x;
                int thisY = getLocation().y;

                int xMoved = e.getX() - initialClick.x;
                int yMoved = e.getY() - initialClick.y;

                int x = thisX + xMoved;
                int y = thisY + yMoved;

                setLocation(x, y);
            }
        });

        // 关闭菜单
        JPopupMenu popupMenu = new JPopupMenu();
        JMenuItem closeMenuItem = new JMenuItem("关闭");
        closeMenuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();// 释放窗口
                System.exit(0);// 关闭程序
            }
        });
        popupMenu.add(closeMenuItem);

        // 当标题栏面板右键时,弹出关闭菜单
        titleBar.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                if (e.isPopupTrigger()) {
                    popupMenu.show(e.getComponent(), e.getX(), e.getY());
                }
            }
            public void mouseReleased(MouseEvent e) {
                if (e.isPopupTrigger()) {
                    popupMenu.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        });
        add(titleBar, BorderLayout.NORTH);

        // 文本域
        noteTextArea = new JTextArea();
        noteTextArea.setLineWrap(true);
        noteTextArea.setFont(new Font("微软雅黑", Font.PLAIN, 14));
        noteTextArea.setMargin(new Insets(10, 20, 10, 20));

        // 文本域的滚动条
        JScrollPane scrollPane = new JScrollPane(noteTextArea);
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        add(scrollPane, BorderLayout.CENTER);

        // 下方的按钮面板
        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

        buttonPanel.add(newButton()); // 新增按钮和它的事件
        buttonPanel.add(historyButton()); // 查看历史按钮和它的事件
        buttonPanel.add(clearButton()); // 清空所有便签内容按钮和它的事件
        buttonPanel.add(deleteButton()); // 删除所有历史便签内容和它的事件

        add(buttonPanel, BorderLayout.SOUTH);

        pack();
        setLocationRelativeTo(null);
        setAlwaysOnTop(true);
        if (SystemTray.isSupported()) {
            addTrayIcon();
        }
        setVisible(true);
    }

    /**
     * 新增按钮和它的事件
     */
    private JButton newButton(){
        JButton newButton = new JButton("新增");
        newButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String note = noteTextArea.getText();
                if (note.length()>0){
                    Date date = new Date();
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String format = sdf.format(date);
                    note = format + ":" + note;
                    notes.add(note);
                    saveNotes();
                    noteTextArea.setText("");
                }
            }
        });
        return newButton;
    }

    /**
     * 查看历史按钮和它的事件和它的事件
     */
    private JButton historyButton(){
        JButton historyButton = new JButton("历史");
        historyButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 创建一个JDialog模态框
                JDialog historyDialog = new JDialog();
                historyDialog.setTitle("便签历史");
                historyDialog.setModal(true);// 设置为模态对话框,这样就不允许与其他窗口交互,只能先关闭这个窗口才能操作其他窗口
                historyDialog.setResizable(false);
                historyDialog.setLayout(new BorderLayout());
                historyDialog.setPreferredSize(new Dimension(400, 300));
                // 显示历史内容的文本域
                JTextArea historyTextArea = new JTextArea();
                historyTextArea.setEditable(false);
                historyTextArea.setFont(new Font("微软雅黑", Font.PLAIN, 14));
                historyTextArea.setMargin(new Insets(15, 15, 15, 15));
                // 文本域的滚动条
                JScrollPane scrollPane = new JScrollPane(historyTextArea);
                scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
                historyDialog.add(scrollPane, BorderLayout.CENTER);
                // 读取历史内容并设置到文本域中
                StringBuilder history = new StringBuilder();
                for (String note : notes) {
                    history.append(note).append("\n");
                }
                historyTextArea.setText(history.toString());

                historyDialog.pack();
                historyDialog.setAlwaysOnTop(true);// 历史模态框置顶
                historyDialog.setLocationRelativeTo(null);
                historyDialog.setVisible(true);
            }
        });
        return historyButton;
    }

    /**
     * 清空当前面板内容按钮和它的事件
     */
    private JButton clearButton(){
        JButton clearButton = new JButton("清空");
        clearButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JDialog dialog = new JDialog();
                dialog.setTitle("清空当前内容");
                dialog.setModal(true);
                dialog.setAlwaysOnTop(true);// 历史模态框置顶
                JOptionPane optionPane = new JOptionPane("是否要清空当前面板内容?\n\n清空后将不保存到历史记录中。", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
                dialog.setContentPane(optionPane);
                optionPane.addPropertyChangeListener(new PropertyChangeListener() {
                    @Override
                    public void propertyChange(PropertyChangeEvent evt) {
                        String prop = evt.getPropertyName();
                        if (dialog.isVisible() && (evt.getSource() == optionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
                            int result = (Integer) optionPane.getValue();
                            if (result == JOptionPane.YES_OPTION) { // 执行清空操作
                                noteTextArea.setText("");
                            }
                            dialog.dispose(); // 关闭对话框
                        }
                    }
                });
                dialog.pack();
                dialog.setLocationRelativeTo(null);
                dialog.setVisible(true);
            }
        });
        return clearButton;
    }

    /**
     * 删除所有历史便签内容和它的事件
     */
    private JButton deleteButton(){
        JButton deleteButton = new JButton("删除");
        deleteButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JDialog dialog = new JDialog();
                dialog.setTitle("删除所有内容,包括历史记录");
                dialog.setModal(true);
                dialog.setAlwaysOnTop(true);// 历史模态框置顶
                JOptionPane optionPane = new JOptionPane("是否要删除所有便签内容?\n\n其中包括历史记录内容。", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
                dialog.setContentPane(optionPane);
                optionPane.addPropertyChangeListener(new PropertyChangeListener() {
                    @Override
                    public void propertyChange(PropertyChangeEvent evt) {
                        String prop = evt.getPropertyName();
                        if (dialog.isVisible() && (evt.getSource() == optionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
                            int result = (Integer) optionPane.getValue();
                            if (result == JOptionPane.YES_OPTION) { // 执行清空操作
                                noteTextArea.setText("");
                                notes.clear();
                                clearNotes();
                            }
                            dialog.dispose(); // 关闭对话框
                        }
                    }
                });
                dialog.pack();
                dialog.setLocationRelativeTo(null);
                dialog.setVisible(true);
            }
        });
        return deleteButton;
    }

    /**
     * 添加系统托盘
     */
    private void addTrayIcon(){
        SystemTray tray = SystemTray.getSystemTray();
        Image image = Toolkit.getDefaultToolkit().getImage("icon.png");
        PopupMenu menu = new PopupMenu();
        MenuItem exitMenuItem = new MenuItem("exit");
        exitMenuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        menu.add(exitMenuItem);

        TrayIcon trayIcon = new TrayIcon(image, "桌面便签", menu);
        trayIcon.setImageAutoSize(true);

        try {
            tray.add(trayIcon);
        } catch (AWTException e) {
            e.printStackTrace();
        }
    }

    /**
     * 加载保存的文件
     */
    private void loadNotes() {
        try {
            File file = new File("notes.txt");
            if (file.exists()) {
                BufferedReader reader = new BufferedReader(new FileReader(file));
                String line;
                while ((line = reader.readLine()) != null) {
                    notes.add(line);
                }
                reader.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 将内容保存到txt文件中
     */
    private void saveNotes() {
        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter("notes.txt"));
            for (String note : notes) {
                writer.write(note);
                writer.newLine();
            }
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 将txt文件中的内容全部清空
     */
    private void clearNotes() {
        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter("notes.txt"));
            writer.write("");
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new DesktopNoteApp();
            }
        });
    }
}

这样我们就通过gpt实现了一个简易的桌面便签😎这个自己用用还是可以的,虽然界面简陋了点,但是基本功能还是有的。

给个我自己的使用效果:

在这里插入图片描述

打包的exe我放到这里了:下载

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/699412.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

通往AGI之路:揭秘英伟达A100、A800、H800、V100在高性能计算与大模型训练中的霸主地位

AGI | NLP | A100 | H100 | Nvidia | Aurora GPT| LLM | A800 | V100 | Intel | ChatGPT 日前&#xff0c;随着深度学习、高性能计算、大模型训练等技术的保驾护航&#xff0c;通用人工智能时代即将到来。各个厂商也都在紧锣密鼓的布局&#xff0c;如英伟达前段时间发布GH 200…

C3.ai:一个即将“破灭”的人工智能泡沫

来源&#xff1a;猛兽财经 作者&#xff1a;猛兽财经 C3.ai仅适用于能承受高风险波动的投资者 猛兽财经曾在之前分析过C3.ai&#xff08;AI&#xff09;这家公司&#xff0c;认为C3.ai可能在借助人工智能热潮炒作自己。截止撰写本文时&#xff0c;C3.ai的股价已跌到了到2…

使用ganymed-ssh2连接linux报错 Cannot negotiate, proposals do not match

ganymed-ssh2连接linux报错 背景报错信息解决方案&#xff1a;运行成功 背景 最近有个项目&#xff0c;需要在Linux下的服务器内写了一部分Python脚本&#xff0c;业务处理却是在Java内&#xff0c;那么就想能不能在Java里面&#xff0c;来远程执行Linux下的Python脚本&#x…

chatgpt赋能python:使用Python连接网络摄像头

使用Python连接网络摄像头 网络摄像头是现代生活中不可或缺的设备之一&#xff0c;其允许用户在远程位置查看实时视频流。Python语言提供了强大的工具来连接和控制网络摄像头。本文将向您展示如何使用Python连接网络摄像头以及如何将视频流数据流式传输到本地计算机。 环境设…

【AUTOSAR】BMS开发实际项目讲解(十九)----电池管理系统系统设计电池单体过放后再充电保护

电池单体过放后再充电保护 关联的系统需求 TSR-BMS-2101、TSR-BMS-2102、TSR-BMS-2103、TSR-BMS-2104、TSR-BMS-2105、TSR-BMS-2106、TSR-BMS-2107、TSR-BMS-2108、TSR-BMS-2109、TSR-BMS-2110、TSR-BMS-2111、TSR-BMS-2112、TSR-BMS-2113、TSR-BMS-2114、TSR-BMS-2115、TSR-B…

七年老Android推荐 : 日常开发中好用的工具 (一)

1. 前言 作为一名拥有七年经验的Android开发工程师&#xff0c;在日常开发中&#xff0c;总希望能提升自己的开发效率&#xff0c;对此也积累了一些工具&#xff0c;本文对此总结了一些好用的工具。 2. 视频转GIF工具 我们在写博客的时候&#xff0c;常常要录屏&#xff0c;…

leetcode:2000. 反转单词前缀(python3解法)

难度&#xff1a;简单 给你一个下标从 0 开始的字符串 word 和一个字符 ch 。找出 ch 第一次出现的下标 i &#xff0c;反转 word 中从下标 0 开始、直到下标 i 结束&#xff08;含下标 i &#xff09;的那段字符。如果 word 中不存在字符 ch &#xff0c;则无需进行任何操作。…

智云通CRM:在谈判中如何避免被客户利用的陷阱?

智云通CRM系统是一款专业的客户关系管理系统&#xff0c;帮助企业实现客户管理的数字化转型。在日常销售工作中&#xff0c;销售人员经常会面临各种问题和质疑&#xff0c;良好的应对技巧和回答方法对于维护好客户关系、促成交易非常重要。下面将介绍一些经常会被客户问到的问题…

从源码全面解析 dubbo 服务端服务调用的来龙去脉

&#x1f44f;作者简介&#xff1a;大家好&#xff0c;我是爱敲代码的小黄&#xff0c;独角兽企业的Java开发工程师&#xff0c;CSDN博客专家&#xff0c;阿里云专家博主&#x1f4d5;系列专栏&#xff1a;Java设计模式、Spring源码系列、Netty源码系列、Kafka源码系列、JUC源码…

echatrs-地图,根据数据进行点状显示和指向

echarts地址&#xff1a;https://www.makeapie.cn/echarts var data2 [{ name: 海门, value: 9 },{ name: 鄂尔多斯, value: 12 },{ name: 招远, value: 12 },{ name: 舟山, value: 12 },{ name: 齐齐哈尔, value: 14 },{ name: 盐城, value: 15 },{ name: 赤峰, value: 16 },…

JMeter 后置处理器之JSON提取器

目录 前言&#xff1a; 测试环境 插件介绍 插件参数 插件使用示例 JSON-PATH表达式介绍 操作符 函数 过滤器操作符 JSON PATH示例 前言&#xff1a; JMeter是一个功能强大的性能测试工具&#xff0c;它提供了许多后置处理器来处理和提取测试结果。其中一个常用的后…

【强化学习】常用算法之一 “PPO”

作者主页&#xff1a;爱笑的男孩。的博客_CSDN博客-深度学习,活动,python领域博主爱笑的男孩。擅长深度学习,活动,python,等方面的知识,爱笑的男孩。关注算法,python,计算机视觉,图像处理,深度学习,pytorch,神经网络,opencv领域.https://blog.csdn.net/Code_and516?typeblog个…

Android 操作系统日历完成提醒功能 附带开关闹钟 适配高版本安卓

Android 操作系统日历完成提醒功能 附带开关闹钟 如果想要一个稳定且不用担心生命周期的提醒方式&#xff0c;可以试试利用系统日历去完成任务的提醒或某个活动的预约。 项目仓库地址在文末 环境 Java 11 Android sdk 30 Gredle 7.1 minSdkVersion 23 targetSdkVersion 30测…

js 纯前端实现 重新部署 通知用户刷新网页

需求&#xff1a;有时候上完线&#xff0c;用户还停留在老的页面&#xff0c;用户不知道网页重新部署了&#xff0c;跳转页面的时候有时候js连接hash变了导致报错跳不过去&#xff0c;并且用户体验不到新功能&#xff0c;需要进行优化&#xff0c;每当打包发版后客户进入系统就…

F#奇妙游(1):F#浅尝

F#奇妙游&#xff08;1&#xff09;&#xff1a;F#浅尝 是什么 F#是.NET平台的OCaml。 这句话很欠打&#xff0c;.NET和OCaml前者知道的人有一些&#xff0c;后者就很少了。.NET平台是一个开源的软件平台&#xff0c;早期由微软主导&#xff0c;目前已经开源&#xff0c;由.…

如何使用CSS Grid 居中 div

本文翻译自 How to Center a Div Using CSS Grid&#xff0c;作者&#xff1a;Fimber Elemuwa, Ralph Mason。 略有删改 在本文中&#xff0c;我们将介绍使用CSS Grid在水平和垂直方向上居中div的五种方法&#xff0c;当然这些技术可用于任何类型的元素。 初始化 我们首先创建…

ASP.Net Core Web API项目发布到IIS(二)

目录 一.启动并配置IIS环境 1.启用或关闭window功能 2.设置万维网服务 3.点击确定等待配置更改 二.创建新的Web网站并进行设置 1.打开IIS管理 2.配置默认的网站 3.创建新的网站 4.测试 三.可能出现的问题 1.404错误 前一篇已经记录了如何创建项目并发布到文件夹&#x…

配置管理数据库(CMDB)

什么是CMDB 配置管理数据库(Configuration Management Database&#xff0c;简称CMDB)是组织IT基础结构中配置项(Configuration Item)及其关系的数据库。CI指示了任何需要管理的、以确保成功交付服务的项目。CI可以是一个具体的实体&#xff0c;如服务器、交换机&#xff0c;也…

软件测试的自动化工具

在软件开发过程中&#xff0c;测试是必不可少的一个环节。而在测试中&#xff0c;测试人员需要花费大量的时间和精力进行手动测试&#xff0c;这不仅费时费力&#xff0c;而且效率较低。因此&#xff0c;自动化测试工具的出现为测试人员提供了更加便捷高效的测试方法。本文将介…

认识CSS

hi,大家好,今天我们来简单认识一下前端三剑客之一的CSS 目录 &#x1f437;CSS是什么&#x1f437;基本语法规范&#x1f437;CSS引入方式&#x1f95d;内部样式&#x1f95d;外部样式&#x1f95d;内联样式 &#x1f437;认识选择器&#x1f349;标签选择器&#x1f349;类选…