/*
 * Copyright (c) 2024. Elex. All Rights Reesrved.
 * https://www.elex-project.com/
 */

package com.elex_project.examples.components.spinner;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.time.LocalDate;
import java.util.Dictionary;
import java.util.Hashtable;

public class SpinnerExample extends JPanel {

	public SpinnerExample() {
		super(new FlowLayout());

		final String[] data = {"Do", "Re", "Mi", "Fa", "Sol", "La", "Si"};
		final JSpinner spinner = new JSpinner(new SpinnerListModel(data));

		spinner.addChangeListener(new ChangeListener() {
			@Override
			public void stateChanged(ChangeEvent changeEvent) {
				JSpinner eventSource = (JSpinner) changeEvent.getSource();
				// 모델을 통해서 선택된 값을 가져온다.
				System.out.println(eventSource.getModel().getValue());
			}
		});

		this.add(spinner);

	}

	public static void main(String... args) {

		final JFrame jFrame = new JFrame();
		jFrame.setTitle("Example");
		jFrame.setSize(800, 600);
		jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jFrame.setContentPane(new SpinnerExample());

		SwingUtilities.invokeLater(() -> {
			jFrame.setVisible(true);
		});


	}
}
