public class Tasks { private static JFrame frame; private static JList lessonList; private static JPanel contentPane; private static JList sollist; private static JList saglist; private static JComboBox teacherComboBox; private static DefaultListModel sollistmodel = new DefaultListModel<>(); private static DefaultListModel saglistmodel = new DefaultListModel<>(); public static void main() throws SQLException { frame = new JFrame("Yönetici Girişi | Öğretmen İşlemleri"); frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); frame.setSize(500, 400); frame.setLocationRelativeTo(null); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); frame.setContentPane(contentPane); contentPane.setLayout(null); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(36, 68, 138, 197); contentPane.add(scrollPane); sollist = new JList<>(sollistmodel); listLessonModel1(); scrollPane.setViewportView(sollist); // Set up the second list and its scroll pane JScrollPane scrollPane_1 = new JScrollPane(); scrollPane_1.setBounds(316, 68, 138, 197); contentPane.add(scrollPane_1); saglist = new JList<>(saglistmodel); scrollPane_1.setViewportView(saglist); // Add buttons and combo box JButton btnsolaekle = new JButton(">>"); btnsolaekle.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String secilenders = sollist.getSelectedValue(); DefaultListModel model = (DefaultListModel) saglist.getModel(); model.addElement(secilenders); sollistmodel.removeElement(secilenders); } }); btnsolaekle.setFont(new Font("Tahoma", Font.BOLD, 16)); btnsolaekle.setBounds(199, 107, 89, 23); contentPane.add(btnsolaekle); JButton btnsagaekle = new JButton("<<"); btnsagaekle.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String secilenders = saglist.getSelectedValue(); DefaultListModel model = (DefaultListModel) sollist.getModel(); model.addElement(secilenders); saglistmodel.removeElement(secilenders); } }); btnsagaekle.setFont(new Font("Tahoma", Font.BOLD, 16)); btnsagaekle.setBounds(199, 159, 89, 23); contentPane.add(btnsagaekle); String[] teacherNames = getTeacherNamesFromDatabase(); teacherComboBox = new JComboBox<>(teacherNames); teacherComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateSelectedLessonsForTeacher(); } }); teacherComboBox.setFont(new Font("Tahoma", Font.BOLD, 16)); teacherComboBox.setBounds(160, 10, 180, 30); contentPane.add(teacherComboBox); JButton Kaydet = new JButton("Kaydet"); Kaydet.setFont(new Font("Tahoma", Font.BOLD, 16)); Kaydet.setBounds(185, 275, 120, 30); contentPane.add(Kaydet); frame.setVisible(true); } private static void listLessonModel1() throws SQLException { Connection connection = Mysql.Connection; String sqlLesson = "SELECT Lesson FROM teacher_courses WHERE Confirmation = 0"; PreparedStatement statementLesson = connection.prepareStatement(sqlLesson); ResultSet resultLesson = statementLesson.executeQuery(); while (resultLesson.next()) { int İd = resultLesson.getInt("Lesson"); String Lesson = returnName(String.valueOf(İd)); sollistmodel.addElement(Lesson); } resultLesson.close(); statementLesson.close(); } public static String returnName(String İd) { Connection connection = Mysql.Connection; String name = ""; try { String sql = "SELECT Name FROM Lessons WHERE İd= ?"; PreparedStatement statement = connection.prepareStatement(sql); statement.setString(1, İd); ResultSet resultSet = statement.executeQuery(); if (resultSet.next()) { name = resultSet.getString("Name"); } } catch (SQLException e) { e.printStackTrace(); } return name; }