Import Import Import Import Import Import Import Import Import Public Class Static New
Import Import Import Import Import Import Import Import Import Public Class Static New
Import Import Import Import Import Import Import Import Import Public Class Static New
Done:
Accurate Month Calendar with changing year
Rooster GUI pop up next to calendar
In progress:
buttons for Roster GUI [Add, Remove, Edit [input name/ lunch/ email *possibly use XML*]
Editable Day cells that trigger program to generate names for schedule--each day of the
week will have 'A', 'B', and 'H' and will either generate three names to work that lunch or
return "Holiday"
*/
import java.util.List;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import java.util.ArrayList;
public class RotatingSchedule {
//this method alls for the addition of new names to the Roster List
private void addname()
{
dList.addElement("strig");
dList.addElement("fml");
dList.addElement("Cakes");
dList.addElement("flfebndpg");
dList.addElement("strig");
dList.addElement("fml");
dList.addElement("yCakes");
dList.addElement("flfebndpg");
dList.addElement("strig");
dList.addElement("fml");
dList.addElement("CodyCakes");
dList.addElement("flfebndpg");
dList.addElement("strig");
dList.addElement("fml");
dList.addElement("yCakes");
dList.addElement("flfebndpg");
names.setVisibleRowCount(-1);
names.setLayoutOrientation(JList.VERTICAL_WRAP);
}
//
static JList names = new JList(dList);
static JLabel lblMonth, lblYear;
static JButton btnPrev, btnNext;
static JTable tblCalendar;
static JComboBox cmbYear;
static JFrame frmMain;
static Container pane, paneList;
static DefaultTableModel mtblCalendar; //Table model
static JScrollPane stblCalendar, nrl; //The scrollpane
static JPanel pnlCalendar;
static int realYear, realMonth, realDay, currentYear, currentMonth;
//for funzies
RotatingSchedule s = new RotatingSchedule();
s.addname();
//
//Prepare frame
frmMain = new JFrame ("Calendar"); //Create frame
frmMain.setSize(830, 675); //Set size to 400x400 pixels CHANGED From 330,375
pane = frmMain.getContentPane(); //Get content pane
pane.setLayout(null); //Apply null layout
frmMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Close when X is clicked
//Create controls
lblMonth = new JLabel ("January");
lblYear = new JLabel ("Change year:");
cmbYear = new JComboBox();
btnPrev = new JButton ("<<");
btnNext = new JButton (">>");
mtblCalendar = new DefaultTableModel(){public boolean isCellEditable(int rowIndex,
int mColIndex){return false;}};
tblCalendar = new JTable(mtblCalendar);
stblCalendar = new JScrollPane(tblCalendar);
pnlCalendar = new JPanel(null);
btnRoster = new JButton ("Roster");
btnBack = new JButton ("Back");
pnlRoster = new JPanel(null);
btnAdd = new JButton("Add");
btnEdit = new JButton("Edit");
//Set border
pnlCalendar.setBorder(BorderFactory.createTitledBorder("Calendar"));
pnlRoster.setBorder(BorderFactory.createTitledBorder(""));//adds a border is currently
blank
btnRoster.addActionListener(new btnRoster_Action());
btnAdd.addActionListener(new btnAdd_Action());
btnEdit.addActionListener(new btnEdit_Action());
paneList.add(pnlRoster);
pnlRoster.add(btnBack);//remove later
pnlRoster.add(btnAdd);
pnlRoster.add(btnEdit);
//
//Set bounds
pnlCalendar.setBounds(0, 0, 820, 635); // +500, +300
lblMonth.setBounds(160-lblMonth.getPreferredSize().width/2, 25, 100, 25);
lblYear.setBounds(10, 585, 80, 20);//
cmbYear.setBounds(10, 605, 80, 20);
btnPrev.setBounds(10, 25, 50, 25);
btnNext.setBounds(760, 25, 50, 25); //changed 260 - 760
stblCalendar.setBounds(10, 50, 800, 530);
btnRoster.setBounds(100, 605, 80, 20);
//list bounds::
names.setBounds(0, 30,526, 200);
nrl.setBounds(450, 50, 30, 20);//appears on the screen but currently does not work
//
//Add headers
String[] headers = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; //All headers
for (int i=0; i<7; i++){
mtblCalendar.addColumn(headers[i]);
}
//No resize/reorder
tblCalendar.getTableHeader().setResizingAllowed(false);
tblCalendar.getTableHeader().setReorderingAllowed(false);
//Populate table
for (int i=realYear-100; i<=realYear+100; i++){
cmbYear.addItem(String.valueOf(i));
}
//Refresh calendar
refreshCalendar (realMonth, realYear); //Refresh calendar
//Allow/disallow buttons
btnPrev.setEnabled(true);
btnNext.setEnabled(true);
btnRoster.setEnabled(true);
btnAdd.setEnabled(true);
btnEdit.setEnabled(true);
if(frmList.isVisible()) {btnRoster.setEnabled(false);}
if (month == 0 && year <= realYear-10){btnPrev.setEnabled(false);} //Too early
if (month == 11 && year >= realYear+100){btnNext.setEnabled(false);} //Too late
lblMonth.setText(months[month]); //Refresh the month label (at the top)
lblMonth.setBounds(160-lblMonth.getPreferredSize().width/2, 25, 180, 25); //Re-align label
with calendar
cmbYear.setSelectedItem(String.valueOf(year)); //Select the correct year in the combo box
//Clear table
for (int i=0; i<5; i++){
for (int j=0; j<7; j++){
mtblCalendar.setValueAt(null, i, j);
}
}
//Draw calendar
for (int i=1; i<=nod; i++){
int row = new Integer((i+som-2)/7);
int column = (i+som-2)%7;
mtblCalendar.setValueAt(i, row, column);
}
//Apply renderers
tblCalendar.setDefaultRenderer(tblCalendar.getColumnClass(0), new
tblCalendarRenderer());
}
}
}
}
}