In first frame, I have a panel with form layout, I have a "ADD" button. When user click ADD button, a second frame will shown. Second frame is shown to allow user to fill the information needed to create a button in A.java.
ADD button on frame of A.java:
JButton button_3 = new JButton("ADD");//ADD ROW
button_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
addCHECKUP addC = new addCHECKUP();//note that addCHECKUP is B.java
addC.setVisible(true);
addC.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
});
frame of A.java:

If user click ADD button at frame of A.java, frame of B.java will be shown.
frame of B.java:

After user finish in giving all the input at frame of B.java, ADD button will be clicked. Then a new button is created at frame of A.java based on user input at frame of B.java.
So far, when ADD button at frame of B.java is clicked, the information is saved into a text file. Below is the ADD button code.
JButton btnAdd = new JButton("ADD");
btnAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.out.println(comboBox_1.getSelectedItem()); //getActivity
if (chckbxNewCheckBox.isSelected()){//if complication
System.out.println("*"+textField.getText());//setTaskName have * sign
}
else{
System.out.println(textField.getText());
}
System.out.println(comboBox.getSelectedItem()); //getDay
String filename = "c:" + File.separator + "Text File from B.java Class.txt";
File f = new File(filename);
PrintWriter pw = null;
try {
pw = new PrintWriter(f);
pw.println(comboBox_1.getSelectedItem());
if (chckbxNewCheckBox.isSelected()){//if complication
pw.println("*"+textField.getText());
}
else{
pw.println(textField.getText());
}
pw.println(comboBox.getSelectedItem());
pw.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
}finally{
if(pw!=null){
pw.close();
}
}
JOptionPane.showMessageDialog(null,"Successfully added !");
}
});
Now, I intend to access the text file and create a new button based on the information from text file. I don't know how to make the new button based on the information from the text file. If there is any other method that more easier, please let me know.
I want to create button like this: I put this at B.java
JButton btn_34 = new JButton("Uptitrate BB");//Task Name
BigPanel.add(btn_34, "12, 11"); //12 and 11 is based on Activity and Day
But error in BigPanel.add
I would use a Properties read and write this.
So all you need are keys and values.
And your write method may look like this
Sincerely
Update-1
I assume I have a property File containing
Now, I only need to loop over all Bs an call createButton for each containing in this property file. All I may save is the last used index. So if the user adds a new one. We create a new Button Bn. Save this in the file and you are done.
Update-2