/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 */

package com.mycompany.assign_final;

import java.util.List;

/**
 *
 * @author atom
 */
public class Assign_final {
 public static void main(String[] args) {
                new EventSchedulerGUI();

}
}

Assign_final.java
Skip to main content
Google ClassroomClassroom
SCD-A (Fall 2024)A
O
T
S
O
S
O
S
F
S
O
A
E
Assignment-2
Assignment-2
farooq ahmed
•
Oct 10
40 points
Due Oct 21, 11:59 PM
Implement using Java Swing
Assignment-2.pdf
PDF
Class comments
Your work
Turned in
Assign_final.java
Java
EventSchedulerGUI.java
Java
Room.java
Java
Scheduler.java
Java
Seminar.java
Java
Slot.java
Java
Private comments

/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.mycompany.assign_final;

/**
 *
 * @author atom
 */
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.List;

public class EventSchedulerGUI extends JFrame {

    private Scheduler scheduler;
    private JTable seminarTable;
    private JTable schedulingTable;
    private JTable conflictTable;
    private DefaultTableModel seminarTableModel;
    private DefaultTableModel schedulingTableModel;
    private DefaultTableModel conflictTableModel;

    public EventSchedulerGUI() {
        scheduler = new Scheduler();
        createGUI();
    }

    private void createGUI() {
        setLayout(new BorderLayout());

        JPanel seminarPanel = new JPanel();
        seminarPanel.setLayout(new BorderLayout());
        
        String[] seminarColumns = {"Seminar", "Speaker", "Attendees"};
        seminarTableModel = new DefaultTableModel(seminarColumns, 0);
        seminarTable = new JTable(seminarTableModel);

        JScrollPane seminarScrollPane = new JScrollPane(seminarTable);

        // Seminar File Upload Button
        JButton seminarFileUploadButton = new JButton("Upload Seminar File");
        seminarFileUploadButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                uploadSeminarFile();
            }
        });

        seminarPanel.add(seminarScrollPane, BorderLayout.CENTER);
        seminarPanel.add(seminarFileUploadButton, BorderLayout.SOUTH);

        // Scheduling Panel
        JPanel schedulingPanel = new JPanel();
        schedulingPanel.setLayout(new BorderLayout());

      
        String[] schedulingColumns = {"Seminar", "Room", "Time Slot"};
        schedulingTableModel = new DefaultTableModel(schedulingColumns, 0);
        schedulingTable = new JTable(schedulingTableModel);

        JScrollPane schedulingScrollPane = new JScrollPane(schedulingTable);

        // Scheduling File Upload Button
        JButton schedulingFileUploadButton = new JButton("Upload Scheduling File");
        schedulingFileUploadButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                uploadSchedulingFile();
            }
        });

        schedulingPanel.add(schedulingScrollPane, BorderLayout.CENTER);
        schedulingPanel.add(schedulingFileUploadButton, BorderLayout.SOUTH);

        JPanel conflictPanel = new JPanel();
        conflictPanel.setLayout(new BorderLayout());

        String[] conflictColumns = {"Conflict"};
        conflictTableModel = new DefaultTableModel(conflictColumns, 0);
        conflictTable = new JTable(conflictTableModel);

        JScrollPane conflictScrollPane = new JScrollPane(conflictTable);

        // Analyze Button
        JButton analyzeButton = new JButton("Analyze");
        analyzeButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                analyzeConflicts();
            }
        });

        conflictPanel.add(conflictScrollPane, BorderLayout.CENTER);
        conflictPanel.add(analyzeButton, BorderLayout.SOUTH);

        // Tabbed Pane
        JTabbedPane tabbedPane = new JTabbedPane();
        tabbedPane.addTab("Seminars", seminarPanel);
        tabbedPane.addTab("Scheduling", schedulingPanel);
        tabbedPane.addTab("Conflicts", conflictPanel);

        add(tabbedPane, BorderLayout.CENTER);

        setSize(800, 600);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    private void uploadSeminarFile() {
        JFileChooser fileChooser = new JFileChooser();
        int returnValue = fileChooser.showOpenDialog(this);
        if (returnValue == JFileChooser.APPROVE_OPTION) {
            File selectedFile = fileChooser.getSelectedFile();
            scheduler.loadSeminars(selectedFile.getAbsolutePath());
            updateSeminarTable();
        }
    }

    private void uploadSchedulingFile() {
        JFileChooser fileChooser = new JFileChooser();
        int returnValue = fileChooser.showOpenDialog(this);
        if (returnValue == JFileChooser.APPROVE_OPTION) {
            File selectedFile = fileChooser.getSelectedFile();
            scheduler.loadScheduling(selectedFile.getAbsolutePath());
            updateSchedulingTable();
        }
    }

    private void analyzeConflicts() {
        List<String> conflicts = scheduler.findAllConflicts();
        updateConflictTable(conflicts);
    }

    private void updateSeminarTable() {
        seminarTableModel.setRowCount(0);
        for (Seminar seminar : scheduler.seminars) {
            String[] row = {seminar.getName(), seminar.getSpeaker(), seminar.getAttendeeIds().toString()};
            seminarTableModel.addRow(row);
        }
    }

    private void updateSchedulingTable() {
        schedulingTableModel.setRowCount(0);
        for (Seminar seminar : scheduler.seminars) {
            if (seminar.getRoom() != null && seminar.getSlot() != null) {
                String[] row = {seminar.getName(), seminar.getRoom().getRoomNumber(), String.valueOf(seminar.getSlot().getSlotId())};
                schedulingTableModel.addRow(row);
            }
        }
    }

    private void updateConflictTable(List<String> conflicts) {
        conflictTableModel.setRowCount(0);
        for (String conflict : conflicts) {
            String[] row = {conflict};
            conflictTableModel.addRow(row);
        }
    }

    
}

EventSchedulerGUI.java
Displaying EventSchedulerGUI.java.