import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Calandar { final int YEAR = 2006; int selectedMonth = 0; String month[] = {"January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; int days[] = {31,28,31,30,31,30,31,31,30,31,30,31}; String week[] = {"Sunday", "Monday" , "Tuesday", "Wensday", "Thursday", "Friday", "Saturday"}; int start[] = {0,3,3,6,1,4,6,2,5,0,3,5}; public Calandar(int month) { selectedMonth = month - 1; } public void make(){ JFrame main = new JFrame("Availability for " + month[selectedMonth] + " , " + YEAR); main.setLayout(new BorderLayout()); JLabel north = new JLabel("GREEN DAYS ARE AVAILABLE,"+ " RED DAYS ARE NOT.", JLabel.CENTER); JPanel center = new JPanel( new GridLayout(0,7)); // days of the week for (int i = 0; i < week.length; i++){ JLabel day = new JLabel(week[i], JLabel.CENTER); center.add(day); } //blank buttons at begining of monthfor for (int i = 0; i < start[selectedMonth]; i++){ JButton button = new JButton(" "); center.add(button); } //day buttons for (int i = 1; i <= days[selectedMonth]; i++){ JButton button = new JButton(new String(String.valueOf(i))); button.setBackground(Color.green); center.add(button); } // trailing blank buttons for( int i = 0; i< 7 - (( start[selectedMonth] + days[selectedMonth]) %7 ); i++){ JButton button = new JButton(" "); center.add(button); } JLabel south = new JLabel ("Click \'Reserve Room\' in the main " + "window when finished selecting dates"); main.add("North", north); main.add("Center", center); main.add("South", south); main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); main.setLocationRelativeTo(null); main.setVisible(true); main.pack(); } public static void main(String args[]){ Calandar a; for (int i = 1; i < 13; i++){ a = new Calandar(i); a.make(); } } }