Currently, I am facing an issue where I have created a class that extends JPanel (shown below) and I am attempting to add multiple instances of this class to another JPanel.
public class DOBGui extends JPanel {
private static String dayList[] = {bunch of days};
private static JComboBox dobDay = new JComboBox(dayList);
private static String monthList[] = {bunch of months};
private static JComboBox dobMonth = new JComboBox(monthList);
private static String yearList[] = {bunch of dates};
private static JComboBox dobYear = new JComboBox(yearList);
public static String DOBString() {
int dayInt = dobDay.getSelectedIndex() + 1;
int monthInt = dobMonth.getSelectedIndex() + 1;
String year = dobYear.getSelectedItem().toString();
String day = "" + dayInt;
if (day.length() == 1) {
day = "0" + day;
}
String month = "" + monthInt;
if (month.length() == 1) {
month = "0" + month;
}
return day + month + year;
}
public DOBGui() {
add(dobDay);
add(dobMonth);
add(dobYear);
}
void reset() {
dobDay.setSelectedIndex(0);
dobMonth.setSelectedIndex(0);
dobYear.setSelectedIndex(0);
}
}
My problem arises when I try to add this JPanel to another JPanel twice by creating two instances of the DOBGui class, but it ends up overwriting the first one.
questionsPanel.add(new JLabel("Date for budget skills training session"), "wrap");
DOBGui budgetSkillsDate = new DOBGui();
budgetSkillsDate.reset();
questionsPanel.add(budgetSkillsDate, "wrap");
questionsPanel.add(new JLabel("Date for cooking course training session"), "wrap");
DOBGui cookingCourseDate = new DOBGui();
cookingCourseDate.reset();
questionsPanel.add(cookingCourseDate, "wrap");