I'm fairly inexperienced in programming, so this might be a very stupid mistake. I'm trying to reference objects I've instantiated in the class "DateSelectionSpinner" in my "speiseplanDesign" class. The variables in question are "daySelector", "monthSelector" and "yearSelector". Both classes are in the same package and I'm using Eclipse for coding. I'm thankful for any help I can get :)
This is the class I want to use the variables in:
package foodTracker_View;
import java.awt.*;
import java.time.LocalDate;
import javax.swing.*;
/**
*
* @author
* @version 09.06.23
*
*/
public class speiseplanDesign extends JPanel {
private JLabel beschriftungSpeiseplan;
private LocalDate date = LocalDate.now();
private JFormattedTextField eingabefeldDatum;
private JPanel datumsauswahl;
public speiseplanDesign(int width, int height) {
this.setSize(width, height);
this.setBackground(Color.black);
this.setLayout(new FlowLayout(FlowLayout.CENTER));
this.setBorder(BorderFactory.createLineBorder(Color.black, 20, true));
this.setOpaque(true);
ScrollPane speisplanScroll = new ScrollPane();
beschriftungSpeiseplan = new JLabel("Speiseplan vom " + date, JLabel.CENTER);
this.add(beschriftungSpeiseplan);
beschriftungSpeiseplan.setOpaque(true);
datumsauswahl = new JPanel();
datumsauswahl.add(daySelector); //Error: daySelector cannot be resolved to a
variable
datumsauswahl.add(monthSelector); //same issue as above
datumsauswahl.add(yearSelector); //same issue as above
}
}
This is the class I've defined them in:
package foodTracker_View;
import javax.swing.*;
import java.time.*;
import javax.swing.SpinnerNumberModel;
/**
*
* Diese Klasse beinhaltet die Vorgaben für alle graphischen Komponenten,
* die im Speiseplan für die Auswahl des Datums benötigt werden
*
* @author
* @version 09.06.23
*
*/
public class DateSelectionSpinner {
private int currentYear = Year.now().getValue();
SpinnerNumberModel yearSelector = new SpinnerNumberModel(currentYear, currentYear, currentYear + 5, 1 );
String[] months = { "Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember" };
private SpinnerListModel allowedMonths = new SpinnerListModel(months);
JSpinner monthSelection = new JSpinner(allowedMonths);
private LocalDate currentDate = LocalDate.now();
private int currentDay = currentDate.getDayOfMonth();
int maxDay = 30;
SpinnerNumberModel daySelector = new SpinnerNumberModel(currentDay, currentDay, maxDay, 1);
}
I've tried specifically importing the second class to the first one, but that didn't do anything.