Java Paste by jhsveli
Description: South_Bridge
Hide line numbers

Create new paste
Post a reply
View replies

Paste:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import java.util.*;


public class KalenderTest 
{
    public static void main(String[] args)
    {
        ComboBoxFrame frame = new ComboBoxFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}

class ComboBoxFrame extends JFrame
{
    GregorianCalendar d;
    public ComboBoxFrame()
    {
        setTitle("TEST");
        setSize(DEF_WIDTH, DEF_HEIGHT);

        //
        // Rigger YearSpinner
        //
        YearSpinner = new JSpinner();
        YearSpinner.setValue(2007);
        
        //
        // Rigger MonthCombo
        //
        MonthCombo = new JComboBox();
        MonthCombo.setEditable(true);
        MonthCombo.addItem("Januar");
        MonthCombo.addItem("Februar");
        MonthCombo.addItem("Mars");
        MonthCombo.addItem("April");
        MonthCombo.addItem("Mai");
        MonthCombo.addItem("Juni");
        MonthCombo.addItem("Juli");
        MonthCombo.addItem("August");
        MonthCombo.addItem("September");
        MonthCombo.addItem("Oktober");
        MonthCombo.addItem("November");
        MonthCombo.addItem("Desember");
        
        //
        // Rigger Kalender
        //
        d = new GregorianCalendar();
        
        int currentToday = d.get(Calendar.DAY_OF_MONTH);
        int month = d.get(Calendar.MONTH);
        
        d.set(Calendar.DAY_OF_MONTH, 1);    
        int weekday = d.get(Calendar.DAY_OF_WEEK);    
        
        String temp = "";

        temp += "MON  TUE  WED  THU  FRI  SAT  SUN\n";

        for(int i = Calendar.MONDAY; i < weekday; i++)
        {
            temp += "           ";
        }
            
        do
        {
            int day = d.get(Calendar.DAY_OF_MONTH);
            temp += day;
            
            if (day == currentToday)
                temp += "*     ";
            else
                temp += "      ";
            
            if (day >= 1 && day <= 8)
                temp += "   ";
            
            if (weekday == Calendar.SUNDAY)
                temp += "\n";
            
            d.add(Calendar.DAY_OF_MONTH, 1);
            weekday = d.get(Calendar.DAY_OF_WEEK);
        }
        while (d.get(Calendar.MONTH) == month);

        if (weekday != Calendar.SATURDAY)
        {
            temp += "\n";
        }

        //
        // ActionListener på YearSpinner
        //
        YearSpinner.addChangeListener(new ChangeListener() {

            public void stateChanged(ChangeEvent arg0) {            
                d.set(Calendar.YEAR, ((Integer)YearSpinner.getValue()).intValue());
            }
        });
        
        //
        // ActionListener på MonthCombo
        //
        MonthCombo.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {
                d.set(Calendar.MONTH, MonthCombo.getSelectedIndex());
            }
        });

        //
        // Adder YearSpinner nord på et panel
        //
        JPanel spinnerPanel = new JPanel();
        spinnerPanel.add(YearSpinner);
        add(spinnerPanel, BorderLayout.NORTH);
        
        //
        // Adder MonthCombo center på et panel
        //
        JPanel comboPanel = new JPanel();
        comboPanel.add(MonthCombo);
        add(comboPanel, BorderLayout.CENTER);
        
        //
        // Adder Kalender south på et panel
        //
        JPanel kalenderPanel = new JPanel();
        JTextArea KalenderGen = new JTextArea(temp);
        kalenderPanel.add(KalenderGen);
        add(kalenderPanel, BorderLayout.SOUTH);
    }

    public static final int DEF_WIDTH = 300;
    public static final int DEF_HEIGHT = 220;
    
    private JSpinner YearSpinner;
    private JComboBox MonthCombo;
}        

Replies:
No replies posted yet