//package CHAP09;
//
//import java.awt.BorderLayout;
//import javax.swing.DefaultListModel;
//import javax.swing.JButton;
//import javax.swing.JFrame;
//import javax.swing.JList;
//import javax.swing.JPanel;
//import javax.swing.JScrollPane;
//import javax.swing.JTextField;
//
//public class C10_LAB03_SimpleToDoList extends JFrame {
//    private DefaultListModel<String> listModel;
//
//    public C10_LAB03_SimpleToDoList() {
//        setTitle("할 일 목록");
//        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//        setSize(400, 300);
//        setLocationRelativeTo(null);
//
//        // 레이아웃 설정
//        setLayout(new BorderLayout());
//
//        // 목록 모델과 JList 생성
//        listModel = new DefaultListModel<>();
//
//        // 미리 정의된 할 일 추가
//        listModel.addElement("할 일 1: 책 읽기");
//        listModel.addElement("할 일 2: 코딩 연습");
//        listModel.addElement("할 일 3: 운동하기");
//        listModel.addElement("할 일 4: 저녁 준비");
//        listModel.addElement("할 일 5: 이메일 확인");
//
//        JList<String> toDoList = new JList<>(listModel);
//        JScrollPane scrollPane = new JScrollPane(toDoList);
//        add(scrollPane, BorderLayout.CENTER);
//
//        // 입력 패널
//        JPanel inputPanel = new JPanel();
//        inputPanel.setLayout(new BorderLayout());
//
//        JTextField taskField = new JTextField();
//        taskField.setEditable(true);      
//        JButton addButton = new JButton("추가");
//        addButton.setEnabled(true);    
//        JButton removeButton = new JButton("제거");
//        removeButton.setEnabled(true); 
//
//        inputPanel.add(taskField, BorderLayout.CENTER);
//        inputPanel.add(addButton, BorderLayout.EAST);
//        inputPanel.add(removeButton, BorderLayout.WEST);
//
//        add(inputPanel, BorderLayout.SOUTH);
//
//        setVisible(true);
//    }
//
//    public static void main(String[] args) {
//        new C10_LAB03_SimpleToDoList();
//    }
//}

//package CHAP09;
//
//import java.awt.BorderLayout;
//import javax.swing.*;
//import javax.swing.event.DocumentEvent;
//import javax.swing.event.DocumentListener;
//
//public class C10_LAB03_SimpleToDoList extends JFrame {
//    private DefaultListModel<String> listModel;
//    private JList<String> toDoList;
//    private JTextField taskField;
//    private JButton addButton;
//    private JButton removeButton;
//
//    public C10_LAB03_SimpleToDoList() {
//        setTitle("할 일 목록");
//        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//        setSize(400, 300);
//        setLocationRelativeTo(null);
//        setLayout(new BorderLayout());
//
//        // 목록 모델 + 초기 데이터
//        listModel = new DefaultListModel<>();
//        listModel.addElement("할 일 1: 책 읽기");
//        listModel.addElement("할 일 2: 코딩 연습");
//        listModel.addElement("할 일 3: 운동하기");
//        listModel.addElement("할 일 4: 저녁 준비");
//        listModel.addElement("할 일 5: 이메일 확인");
//
//        toDoList = new JList<>(listModel);
//        toDoList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//        add(new JScrollPane(toDoList), BorderLayout.CENTER);
//
//        // 입력 패널
//        JPanel inputPanel = new JPanel(new BorderLayout());
//        taskField = new JTextField();
//        addButton = new JButton("추가");
//        removeButton = new JButton("제거"); // 오타 수정: "제거)" -> "제거"
//
//        inputPanel.add(removeButton, BorderLayout.WEST);
//        inputPanel.add(taskField, BorderLayout.CENTER);
//        inputPanel.add(addButton, BorderLayout.EAST);
//        add(inputPanel, BorderLayout.SOUTH);
//
//        // --- 액션 리스너들 ---
//
//        // 추가 버튼: 공백이 아니면 추가
//        addButton.addActionListener(e -> {
//            String text = taskField.getText().trim();
//            if (!text.isEmpty()) {
//                listModel.addElement(text);
//                taskField.setText("");
//                int last = listModel.size() - 1;
//                toDoList.setSelectedIndex(last);
//                toDoList.ensureIndexIsVisible(last);
//            }
//        });
//
//        // Enter로도 추가되게
//        taskField.addActionListener(e -> addButton.doClick());
//
//        // 제거 버튼: 선택된 항목 삭제
//        removeButton.addActionListener(e -> {
//            int idx = toDoList.getSelectedIndex();
//            if (idx != -1) {
//                listModel.remove(idx);
//                // 삭제 후 선택 보정
//                if (!listModel.isEmpty()) {
//                    int newIdx = Math.min(idx, listModel.size() - 1);
//                    toDoList.setSelectedIndex(newIdx);
//                    toDoList.ensureIndexIsVisible(newIdx);
//                }
//            }
//        });
//
//        // 입력이 비어 있으면 추가 버튼 비활성화
//        addButton.setEnabled(!taskField.getText().trim().isEmpty());
//        taskField.getDocument().addDocumentListener(new DocumentListener() {
//            private void update() {
//                addButton.setEnabled(!taskField.getText().trim().isEmpty());
//            }
//            public void insertUpdate(DocumentEvent e) { update(); }
//            public void removeUpdate(DocumentEvent e) { update(); }
//            public void changedUpdate(DocumentEvent e) { update(); }
//        });
//
//        // 선택이 없으면 제거 버튼 비활성화
//        removeButton.setEnabled(false);
//        toDoList.addListSelectionListener(e -> {
//            if (!e.getValueIsAdjusting()) {
//                removeButton.setEnabled(toDoList.getSelectedIndex() != -1);
//            }
//        });
//
//        setVisible(true);
//    }
//
//    public static void main(String[] args) {
//        SwingUtilities.invokeLater(C10_LAB03_SimpleToDoList::new);
//    }
//}
//
//
//
