import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.util.Calendar;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import java.awt.GridBagLayout;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JButton;
public class CalendarTableEx extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JPanel jPanel2 = null;
private JPanel jPanel = null;
private JComboBox jComboBox1 = null;
private JComboBox jComboBox2 = null;
private JPanel jPanel1 = null;
private JScrollPane jScrollPane = null;
private JTable jTable = null;
private JPanel jPanel3 = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JTextField jTextField = null;
private JTextField jTextField1 = null;
private JTextArea jTextArea = null;
private JButton jButton = null;
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
private JTable getJTable() {
if (jTable == null) {
Calendar cDay = Calendar.getInstance();
jComboBox1.setSelectedItem(String.valueOf(cDay.get(Calendar.YEAR)));
jComboBox2.setSelectedItem(String.valueOf(cDay.get(Calendar.MONTH) + 1));
}
return jTable;
}
private Object[][] arrCalendar(int year, int month) {
Object[][] = {
{"", "", "", "", "", "", ""},
{"", "", "", "", "", "", ""},
{"", "", "", "", "", "", ""},
{"", "", "", "", "", "", ""},
{"", "", "", "", "", "", ""},
{"", "", "", "", "", "", ""}
};
Calendar eDay = Calendar.getInstance();
eDay.set(year, month-1, 1);
int startdayofweek = eDay.get(Calendar.DAY_OF_WEEK);
eDay.set(year, month, -1);
int endday = eDay.get(Calendar.DATE);
int total = 1;
int day = 1;
for(int i=0 ; i< .length ; i++) {
for(int j=0 ; j< [i].length ; j++) {
if(total >= startdayofweek && total <= (startdayofweek + endday)) {
[i][j] = day ++;
}
total ++;
}
}
return ;
}
/**
* This method initializes jPanel2
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel2() {
if (jPanel2 == null) {
jPanel2 = new JPanel();
jPanel2.setLayout(new BorderLayout());
jPanel2.add(getJPanel(), BorderLayout.NORTH);
jPanel2.add(getJPanel1(), BorderLayout.CENTER);
}
return jPanel2;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
GridLayout gridLayout = new GridLayout();
gridLayout.setRows(1);
jPanel = new JPanel();
jPanel.setLayout(gridLayout);
jPanel.add(getJComboBox1(), null);
jPanel.add(getJComboBox2(), null);
}
return jPanel;
}
/**
* This method initializes jComboBox1
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox1() {
if (jComboBox1 == null) {
jComboBox1 = new JComboBox();
DefaultComboBoxModel year = new DefaultComboBoxModel();
year .addElement("2006");
year .addElement("2007");
year .addElement("2008");
year .addElement("2009");
year .addElement("2010");
year .addElement("2011");
jComboBox1.setModel(year );
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
int year = Integer.parseInt((String)jComboBox1.getSelectedItem());
int month = Integer.parseInt((String)jComboBox2.getSelectedItem());
Object[][] = arrCalendar(year, month);
jTable.setModel(new CalendarTableModel( ));
if(jTextField != null) {
jTextField.setText("");
jTextField1.setText("");
jTextArea.setText("");
}
}
});
}
return jComboBox1;
}
/**
* This method initializes jComboBox2
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox2() {
if (jComboBox2 == null) {
jComboBox2 = new JComboBox();
DefaultComboBoxModel month = new DefaultComboBoxModel();
month .addElement("1");
month .addElement("2");
month .addElement("3");
month .addElement("4");
month .addElement("5");
month .addElement("6");
month .addElement("7");
month .addElement("8");
month .addElement("9");
month .addElement("10");
month .addElement("11");
month .addElement("12");
jComboBox2.setModel(month );
jComboBox2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
int year = Integer.parseInt((String)jComboBox1.getSelectedItem());
int month = Integer.parseInt((String)jComboBox2.getSelectedItem());
Object[][] = arrCalendar(year, month);
jTable.setModel(new CalendarTableModel( ));
if(jTextField != null) {
jTextField.setText("");
jTextField1.setText("");
jTextArea.setText("");
}
}
});
}
return jComboBox2;
}
/**
* This method initializes jPanel1
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel1() {
if (jPanel1 == null) {
jPanel1 = new JPanel();
jPanel1.setLayout(new BorderLayout());
jPanel1.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
}
return jPanel1;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setViewportView(getJTable2());
}
return jScrollPane;
}
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
private JTable getJTable2() {
if (jTable == null) {
jTable = new JTable();
Calendar cDay = Calendar.getInstance();
jComboBox1.setSelectedItem(String.valueOf(cDay.get(Calendar.YEAR)));
jComboBox2.setSelectedItem(String.valueOf(cDay.get(Calendar.MONTH) + 1));
jTable.setRowHeight(60);
jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jTable.setRowSelectionAllowed(false);
jTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
if(!jTable.getValueAt(jTable.getSelectedRow(), jTable.getSelectedColumn()).equals("")) {
jTextField.setText(jComboBox1.getSelectedItem() + "년 " + jComboBox2.getSelectedItem() + "월 " + jTable.getValueAt(jTable.getSelectedRow(), jTable.getSelectedColumn()) + "일");
}
}
});
}
return jTable;
}
/**
* This method initializes jPanel3
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel3() {
if (jPanel3 == null) {
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(15, 55, 62, 27));
jLabel1.setText("제 목");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(15, 17, 62, 27));
jLabel.setText("날 짜");
jPanel3 = new JPanel();
jPanel3.setLayout(null);
jPanel3.add(jLabel, null);
jPanel3.add(jLabel1, null);
jPanel3.add(getJTextField(), null);
jPanel3.add(getJTextField1(), null);
jPanel3.add(getJTextArea(), null);
jPanel3.add(getJButton(), null);
}
return jPanel3;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new Rectangle(86, 17, 260, 27));
jTextField.setEditable(false);
}
return jTextField;
}
/**
* This method initializes jTextField1
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField1() {
if (jTextField1 == null) {
jTextField1 = new JTextField();
jTextField1.setBounds(new Rectangle(86, 55, 262, 27));
}
return jTextField1;
}
/**
* This method initializes jTextArea
*
* @return javax.swing.JTextArea
*/
private JTextArea getJTextArea() {
if (jTextArea == null) {
jTextArea = new JTextArea();
jTextArea.setBounds(new Rectangle(16, 106, 331, 287));
}
return jTextArea;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(232, 404, 116, 30));
jButton.setText("쓰 기");
}
return jButton;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
CalendarTableEx thisClass = new CalendarTableEx();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
/**
* This is the default constructor
*/
public CalendarTableEx() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(732, 466);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
GridLayout gridLayout1 = new GridLayout();
gridLayout1.setRows(1);
gridLayout1.setHgap(5);
gridLayout1.setColumns(2);
jContentPane = new JPanel();
jContentPane.setLayout(gridLayout1);
jContentPane.add(getJPanel2(), null);
jContentPane.add(getJPanel3(), null);
}
return jContentPane;
}
} // @jve:decl-index=0:visual-constraint="10,10"
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.util.Calendar;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import java.awt.GridBagLayout;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JButton;
public class CalendarTableEx4 extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JPanel jPanel2 = null;
private JPanel jPanel = null;
private JComboBox jComboBox1 = null;
private JComboBox jComboBox2 = null;
private JPanel jPanel1 = null;
private JScrollPane jScrollPane = null;
private JTable jTable = null;
private JPanel jPanel3 = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JTextField jTextField = null;
private JTextField jTextField1 = null;
private JTextArea jTextArea = null;
private JButton jButton = null;
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
private JTable getJTable() {
if (jTable == null) {
Calendar cDay = Calendar.getInstance();
jComboBox1.setSelectedItem(String.valueOf(cDay.get(Calendar.YEAR)));
jComboBox2.setSelectedItem(String.valueOf(cDay.get(Calendar.MONTH) + 1));
}
return jTable;
}
private Object[][] arrCalendar(int year, int month) {
Object[][] = {
{"", "", "", "", "", "", ""},
{"", "", "", "", "", "", ""},
{"", "", "", "", "", "", ""},
{"", "", "", "", "", "", ""},
{"", "", "", "", "", "", ""},
{"", "", "", "", "", "", ""}
};
Calendar eDay = Calendar.getInstance();
eDay.set(year, month-1, 1);
int startdayofweek = eDay.get(Calendar.DAY_OF_WEEK);
eDay.set(year, month, -1);
int endday = eDay.get(Calendar.DATE);
int total = 1;
int day = 1;
for(int i=0 ; i< .length ; i++) {
for(int j=0 ; j< [i].length ; j++) {
if(total >= startdayofweek && total <= (startdayofweek + endday)) {
[i][j] = day ++;
}
total ++;
}
}
return ;
}
/**
* This method initializes jPanel2
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel2() {
if (jPanel2 == null) {
jPanel2 = new JPanel();
jPanel2.setLayout(new BorderLayout());
jPanel2.add(getJPanel(), BorderLayout.NORTH);
jPanel2.add(getJPanel1(), BorderLayout.CENTER);
}
return jPanel2;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
GridLayout gridLayout = new GridLayout();
gridLayout.setRows(1);
jPanel = new JPanel();
jPanel.setLayout(gridLayout);
jPanel.add(getJComboBox1(), null);
jPanel.add(getJComboBox2(), null);
}
return jPanel;
}
/**
* This method initializes jComboBox1
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox1() {
if (jComboBox1 == null) {
jComboBox1 = new JComboBox();
DefaultComboBoxModel year = new DefaultComboBoxModel();
year .addElement("2006");
year .addElement("2007");
year .addElement("2008");
year .addElement("2009");
year .addElement("2010");
year .addElement("2011");
jComboBox1.setModel(year );
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
int year = Integer.parseInt((String)jComboBox1.getSelectedItem());
int month = Integer.parseInt((String)jComboBox2.getSelectedItem());
Object[][] = arrCalendar(year, month);
jTable.setModel(new CalendarTableModel( ));
if(jTextField != null) {
jTextField.setText("");
jTextField1.setText("");
jTextArea.setText("");
}
}
});
}
return jComboBox1;
}
/**
* This method initializes jComboBox2
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox2() {
if (jComboBox2 == null) {
jComboBox2 = new JComboBox();
DefaultComboBoxModel month = new DefaultComboBoxModel();
month .addElement("1");
month .addElement("2");
month .addElement("3");
month .addElement("4");
month .addElement("5");
month .addElement("6");
month .addElement("7");
month .addElement("8");
month .addElement("9");
month .addElement("10");
month .addElement("11");
month .addElement("12");
jComboBox2.setModel(month );
jComboBox2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
int year = Integer.parseInt((String)jComboBox1.getSelectedItem());
int month = Integer.parseInt((String)jComboBox2.getSelectedItem());
Object[][] = arrCalendar(year, month);
jTable.setModel(new CalendarTableModel( ));
if(jTextField != null) {
jTextField.setText("");
jTextField1.setText("");
jTextArea.setText("");
}
}
});
}
return jComboBox2;
}
/**
* This method initializes jPanel1
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel1() {
if (jPanel1 == null) {
jPanel1 = new JPanel();
jPanel1.setLayout(new BorderLayout());
jPanel1.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
}
return jPanel1;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setViewportView(getJTable2());
}
return jScrollPane;
}
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
private JTable getJTable2() {
if (jTable == null) {
jTable = new JTable();
Calendar cDay = Calendar.getInstance();
jComboBox1.setSelectedItem(String.valueOf(cDay.get(Calendar.YEAR)));
jComboBox2.setSelectedItem(String.valueOf(cDay.get(Calendar.MONTH) + 1));
jTable.setRowHeight(60);
jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jTable.setRowSelectionAllowed(false);
jTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
if(!jTable.getValueAt(jTable.getSelectedRow(), jTable.getSelectedColumn()).equals("")) {
jTextField.setText(jComboBox1.getSelectedItem() + "년 " + jComboBox2.getSelectedItem() + "월 " + jTable.getValueAt(jTable.getSelectedRow(), jTable.getSelectedColumn()) + "일");
}
}
});
}
return jTable;
}
/**
* This method initializes jPanel3
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel3() {
if (jPanel3 == null) {
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(15, 55, 62, 27));
jLabel1.setText("제 목");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(15, 17, 62, 27));
jLabel.setText("날 짜");
jPanel3 = new JPanel();
jPanel3.setLayout(null);
jPanel3.add(jLabel, null);
jPanel3.add(jLabel1, null);
jPanel3.add(getJTextField(), null);
jPanel3.add(getJTextField1(), null);
jPanel3.add(getJTextArea(), null);
jPanel3.add(getJButton(), null);
}
return jPanel3;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new Rectangle(86, 17, 260, 27));
jTextField.setEditable(false);
}
return jTextField;
}
/**
* This method initializes jTextField1
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField1() {
if (jTextField1 == null) {
jTextField1 = new JTextField();
jTextField1.setBounds(new Rectangle(86, 55, 262, 27));
}
return jTextField1;
}
/**
* This method initializes jTextArea
*
* @return javax.swing.JTextArea
*/
private JTextArea getJTextArea() {
if (jTextArea == null) {
jTextArea = new JTextArea();
jTextArea.setBounds(new Rectangle(16, 106, 331, 287));
}
return jTextArea;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(232, 404, 116, 30));
jButton.setText("쓰 기");
}
return jButton;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
CalendarTableEx4 thisClass = new CalendarTableEx4();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
/**
* This is the default constructor
*/
public CalendarTableEx4() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(732, 466);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
GridLayout gridLayout1 = new GridLayout();
gridLayout1.setRows(1);
gridLayout1.setHgap(5);
gridLayout1.setColumns(2);
jContentPane = new JPanel();
jContentPane.setLayout(gridLayout1);
jContentPane.add(getJPanel2(), null);
jContentPane.add(getJPanel3(), null);
}
return jContentPane;
}
} // @jve:decl-index=0:visual-constraint="10,10"
'Study > Programming' 카테고리의 다른 글
자바 Server, Client (0) | 2009.05.26 |
---|---|
자바 Network Chat (0) | 2009.05.26 |
자바 데이터 변경 (0) | 2009.05.25 |
자바 우편번호 찾기 (0) | 2009.05.25 |
jdbc (0) | 2009.05.25 |