如何将数据保存到文件中?
当我点击按钮时会发生这种情况。
public void actionPerformed(ActionEvent f) {
if (f.getActionCommand() == Action.BUTTON1.name()){
JButton knapp = (JButton) f.getSource();
knapp.setIcon(new ImageIcon(upptagen));
boka--;
}
}
有117个按钮,当我点击一个特定的按钮时,我希望按钮存储在一个文件中,以便下次运行main时我能记住它。
空文件位于“src / assets / data”
答案 0 :(得分:1)
I think you are going down the wrong path. Most likely, you are not interested in "storing" whole buttons.
Instead, your application allows the user to change specific properties of a button.
Meaning: you could read/write ordinary Java Properties to solve that problem. On startup, you read that property file and adapt your buttons according to the information in that file; and when the user asks for any changes, you update the properties; and write them back into the property file on your drive.