This is how I add all of my JButtons to the panel and to the arraylist
private ArrayList<JButton> b;
String defaultLogo = "O";
for(int i=0; i<81;i++)
{
b.add(new JButton(defaultLogo));
b.get(i).addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
for (int i = 0; i < b.size(); i++){
if (e.getSource() == b.get(i)){
b.get(i).setText(getSymbol());
b.get(i).setForeground(getColor());
b.get(i).setBackground(getBackColor());
}
}
}
});
tilePanel.add(b.get(i));
}
The program allows a user to choose a symbol, background color, and foreground color and when each JButton is pressed it changes to the selected symbol, foreground color, and background color.
I want to be able to save the JButton configuration using DataOutputStream and DataInputStream. I have two action listeners attached to a save and load button that activate a save and load method when pressed. What should I write in each method to allow a user to save and load files of the JButton configurations.
save = new JMenuItem("Save");
file.add(save);
save.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource()==save){
save();
}
}
});
load = new JMenuItem("Load");
file.add(load);
load.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == load){
load();
}
}
});