import java.awt.BorderLayout;
import java.awt.GridLayout;
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;
public class CalendarTableEx1 extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JPanel jPanel = null;
private JPanel jPanel1 = null;
private JComboBox jComboBox = null;
private JComboBox jComboBox1 = null;
private JScrollPane jScrollPane = null;
private JTable jTable = null;
/**
* 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(getJComboBox(), null);
jPanel.add(getJComboBox1(), null);
}
return jPanel;
}
/**
* This method initializes jPanel1
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel1() {
if (jPanel1 == null) {
jPanel1 = new JPanel();
jPanel1.setLayout(new BorderLayout());
jPanel1.add(getJScrollPane(), BorderLayout.CENTER);
}
return jPanel1;
}
/**
* This method initializes jComboBox
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox() {
if (jComboBox == null) {
jComboBox = new JComboBox();
DefaultComboBoxModel yearData = new DefaultComboBoxModel();
yearData.addElement("2006");
yearData.addElement("2007");
yearData.addElement("2008");
yearData.addElement("2009");
yearData.addElement("2010");
yearData.addElement("2011");
jComboBox.setModel(yearData);
jComboBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
System.out.println("itemStateChanged()"); // TODO Auto-generated Event stub itemStateChanged()
}
});
}
return jComboBox;
}
/**
* This method initializes jComboBox1
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox1() {
if (jComboBox1 == null) {
jComboBox1 = new JComboBox();
DefaultComboBoxModel monthData = new DefaultComboBoxModel();
monthData.addElement("1");
monthData.addElement("2");
monthData.addElement("3");
monthData.addElement("4");
monthData.addElement("5");
monthData.addElement("6");
monthData.addElement("7");
monthData.addElement("8");
monthData.addElement("9");
monthData.addElement("10");
monthData.addElement("11");
monthData.addElement("12");
jComboBox1.setModel(monthData);
jComboBox1.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
System.out.println("itemStateChanged()"); // TODO Auto-generated Event stub itemStateChanged()
}
});
}
return jComboBox1;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setViewportView(getJTable());
}
return jScrollPane;
}
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
private JTable getJTable() {
if (jTable == null) {
jTable = new JTable();
jTable.setModel(new CalendarTableModel());
jTable.setRowSelectionAllowed(false);
jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jTable.setRowHeight(60);
}
return jTable;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
CalendarTableEx1 thisClass = new CalendarTableEx1();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
/**
* This is the default constructor
*/
public CalendarTableEx1() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(574, 466);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJPanel(), BorderLayout.NORTH);
jContentPane.add(getJPanel1(), BorderLayout.CENTER);
}
return jContentPane;
}
} // @jve:decl-index=0:visual-constraint="10,10"
import javax.swing.table.AbstractTableModel;
public class CalendarTableModel extends AbstractTableModel {
String[] columnNames = {"일", "월", "화", "수", "목", "금", "토"};
Object[][] data = {
{"", "", "", "", "", "", ""},
{"", "", "", "", "", "", ""},
{"", "", "", "", "", "", ""},
{"", "", "", "", "", "", ""},
{"", "", "", "", "", "", ""},
{"", "", "", "", "", "", ""}
};
public CalendarTableModel() {
}
@Override
public int getColumnCount() {
// TODO Auto-generated method stub
return columnNames.length;
}
@Override
public int getRowCount() {
// TODO Auto-generated method stub
return data.length;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
// TODO Auto-generated method stub
return data[rowIndex][columnIndex];
}
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
}
'Study > Programming' 카테고리의 다른 글
자바 IO 문자기반 (0) | 2009.05.22 |
---|---|
자바 IO 바이트기반 (0) | 2009.05.22 |
자바 Swing 구구단 (0) | 2009.05.21 |
자바 Swing (0) | 2009.05.21 |
AWT choice, list (0) | 2009.05.20 |