/* * Created Date: 2017-10-15 * ProjectRegisterFrm.java * 작성자: 도도(dodo) - rabbit.white@daum.net */ package JWindow; import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import javax.swing.JOptionPane; import java.awt.Font; import java.awt.Toolkit; import javax.swing.border.LineBorder; import javax.swing.table.DefaultTableModel; import JDBC.DBMS; import JDBC.DML; import java.awt.Color; import java.awt.Window.Type; import java.util.Calendar; import java.util.Date; import javax.swing.SwingConstants; import javax.swing.JTextField; import javax.swing.JComboBox; import javax.swing.JButton; import javax.swing.JScrollPane; import java.awt.Component; import javax.swing.JTable; import java.awt.event.ActionListener; import java.sql.SQLException; import java.awt.event.ActionEvent; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class ProjectRegisterFrm extends JFrame { private JPanel contentPane; private JTextField txtProjectName; private JTextField txtPrice; private JTable table; private JTextField txtSearch; private JTextField txtCompanyName; private JTextField txtCompanyID; /** * Create the frame. */ public ProjectRegisterFrm() { DBMS dbms = new DBMS("jdbc:mysql://localhost:3306/jungdy", "root", "apmsetup"); DML dml = new DML(dbms); setResizable(false); setType(Type.UTILITY); setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\jungdy\\Desktop\\JavaSwing\\logo-icons.png")); setTitle("\uD504\uB85C\uC81D\uD2B8 \uB4F1\uB85D"); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 635, 460); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JPanel panel = new JPanel(); panel.setBorder(new LineBorder(Color.GRAY)); panel.setBounds(12, 57, 592, 138); contentPane.add(panel); panel.setLayout(null); JLabel lblNewLabel = new JLabel("\uD504\uB85C\uC81D\uD2B8\uBA85"); lblNewLabel.setFont(new Font("돋움", Font.PLAIN, 12)); lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT); lblNewLabel.setBounds(12, 13, 75, 15); panel.add(lblNewLabel); txtProjectName = new JTextField(); txtProjectName.setFont(new Font("돋움", Font.PLAIN, 12)); txtProjectName.setBounds(99, 13, 481, 21); panel.add(txtProjectName); txtProjectName.setColumns(10); JLabel label_1 = new JLabel("\uAE08\uC561"); label_1.setFont(new Font("돋움", Font.PLAIN, 12)); label_1.setBounds(12, 41, 57, 15); panel.add(label_1); txtPrice = new JTextField(); txtPrice.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { // 숫자만 입력 char c = e.getKeyChar(); if (!Character.isDigit(c)) { e.consume(); return; } } }); txtPrice.setFont(new Font("돋움", Font.PLAIN, 12)); txtPrice.setColumns(10); txtPrice.setBounds(99, 41, 481, 21); panel.add(txtPrice); JPanel panel_2 = new JPanel(); panel_2.setBorder(new LineBorder(Color.GRAY)); panel_2.setBounds(0, 68, 592, 70); panel.add(panel_2); panel_2.setLayout(null); JComboBox cmb_startDay = new JComboBox(); cmb_startDay.setFont(new Font("돋움", Font.PLAIN, 12)); cmb_startDay.setBounds(218, 10, 57, 21); panel_2.add(cmb_startDay); JComboBox cmb_endDay = new JComboBox(); cmb_endDay.setFont(new Font("돋움", Font.PLAIN, 12)); cmb_endDay.setBounds(218, 41, 57, 21); panel_2.add(cmb_endDay); JComboBox cmb_endMonth = new JComboBox(); cmb_endMonth.setFont(new Font("돋움", Font.PLAIN, 12)); cmb_endMonth.setBounds(159, 41, 57, 21); panel_2.add(cmb_endMonth); JComboBox cmb_startMonth = new JComboBox(); cmb_startMonth.setFont(new Font("돋움", Font.PLAIN, 12)); cmb_startMonth.setBounds(159, 10, 57, 21); panel_2.add(cmb_startMonth); JComboBox cmb_startYear = new JComboBox(); cmb_startYear.setFont(new Font("돋움", Font.PLAIN, 12)); cmb_startYear.setBounds(100, 10, 57, 21); panel_2.add(cmb_startYear); JComboBox cmb_endYear = new JComboBox(); cmb_endYear.setFont(new Font("돋움", Font.PLAIN, 12)); cmb_endYear.setBounds(100, 41, 57, 21); panel_2.add(cmb_endYear); JLabel label_5 = new JLabel("\uC885\uB8CC\uC77C\uC790"); label_5.setFont(new Font("돋움", Font.PLAIN, 12)); label_5.setBounds(12, 41, 101, 15); panel_2.add(label_5); JLabel label_7 = new JLabel("\uC2DC\uC791\uC77C\uC790"); label_7.setFont(new Font("돋움", Font.PLAIN, 12)); label_7.setBounds(12, 10, 57, 15); panel_2.add(label_7); txtCompanyName = new JTextField(); txtCompanyName.setEditable(false); txtCompanyName.setFont(new Font("돋움", Font.PLAIN, 12)); txtCompanyName.setColumns(10); txtCompanyName.setBounds(434, 10, 146, 21); panel_2.add(txtCompanyName); JLabel label_3 = new JLabel("\uD68C\uC0AC\uBA85"); label_3.setFont(new Font("돋움", Font.PLAIN, 12)); label_3.setBounds(335, 13, 57, 15); panel_2.add(label_3); JLabel txtCompany = new JLabel("\uC0AC\uC5C5\uC790\uB4F1\uB85D\uBC88\uD638"); txtCompany.setFont(new Font("돋움", Font.PLAIN, 12)); txtCompany.setBounds(335, 43, 104, 15); panel_2.add(txtCompany); txtCompanyID = new JTextField(); txtCompanyID.setEditable(false); txtCompanyID.setFont(new Font("돋움", Font.PLAIN, 12)); txtCompanyID.setColumns(10); txtCompanyID.setBounds(434, 40, 146, 21); panel_2.add(txtCompanyID); JLabel label = new JLabel("\uD504\uB85C\uC81D\uD2B8 \uB4F1\uB85D"); label.setFont(new Font("돋움", Font.BOLD, 15)); label.setBounds(12, 26, 109, 21); contentPane.add(label); JPanel panel_1 = new JPanel(); panel_1.setBorder(new LineBorder(Color.GRAY)); panel_1.setBounds(12, 237, 592, 131); contentPane.add(panel_1); panel_1.setLayout(null); String header[] = {"안녕", "하세", "요"}; String cells[][] = { {"111", "222", "333"}, {"444", "555", "666"}, {"777", "888", "999"}};
table = new JTable(cells, header); table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { // 테이블 선택 값 가져오기 int row = table.getSelectedRow(); int col = table.getSelectedColumn(); Object value = table.getValueAt(row, col); txtCompanyID.setText( value.toString() ); } });
table.setFont(new Font("돋움", Font.PLAIN, 12)); JScrollPane scrollPane = new JScrollPane(table); scrollPane.setBounds(12, 40, 568, 85); panel_1.add(scrollPane); txtSearch = new JTextField(); txtSearch.setFont(new Font("돋움", Font.PLAIN, 12)); txtSearch.setColumns(10); txtSearch.setBounds(101, 9, 402, 21); panel_1.add(txtSearch); JLabel label_2 = new JLabel("\uD68C\uC0AC\uC870\uD68C"); label_2.setFont(new Font("돋움", Font.PLAIN, 12)); label_2.setBounds(12, 12, 57, 15); panel_1.add(label_2); JButton btnQuery = new JButton("\uC870\uD68C"); btnQuery.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { String sql = "select * from project where name like '%" + txtSearch.getText() + "%'"; dml.select(sql); System.out.print(sql); String[][] cells = dml.getCells(); String[] header = dml.getHeader(); DefaultTableModel defTableModel = new DefaultTableModel(cells, header); table.setModel(defTableModel); } });
btnQuery.setFont(new Font("돋움", Font.PLAIN, 12)); btnQuery.setBounds(515, 7, 65, 24); panel_1.add(btnQuery); JButton btnOK = new JButton("\uB4F1\uB85D"); btnOK.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String startDate = cmb_startYear.getSelectedItem().toString() + "-" + cmb_startMonth.getSelectedItem().toString() + "-" + cmb_startDay.getSelectedItem().toString(); String endDate = cmb_endYear.getSelectedItem().toString() + "-" + cmb_endMonth.getSelectedItem().toString() + "-" + cmb_endDay.getSelectedItem(); if ( txtProjectName.getText().isEmpty() ) { JOptionPane.showMessageDialog(null, "프로젝트명을 입력하세요."); return; } if ( txtPrice.getText().isEmpty() ) { JOptionPane.showMessageDialog(null, "금액을 입력하세요."); return; } if ( txtCompanyID.getText().isEmpty() ) { JOptionPane.showMessageDialog(null, "회사코드를 입력하세요."); return; } String sql = "insert into project (name, price, startdate, enddate, company_id) values " + "('" + txtProjectName.getText() + "' , " + txtPrice.getText() + ", '" + startDate + "' , '" + endDate + "' , '" + txtCompanyID.getText() + "')"; System.out.println(sql); try { dml.update(sql); } catch (ClassNotFoundException | SQLException e1) { e1.printStackTrace(); } contentPane.setLayout(null); JOptionPane.showMessageDialog(null, "등록이 완료되었습니다."); } }); btnOK.setFont(new Font("돋움", Font.PLAIN, 12)); btnOK.setBounds(468, 378, 136, 24); contentPane.add(btnOK);
Calendar cal = java.util.Calendar.getInstance();
cmb_startYear.addItem( cal.get( cal.YEAR ) ); cmb_endYear.addItem( cal.get( cal.YEAR ) ); cmb_startMonth.addItem( cal.get( cal.MONTH ) + 1 ); cmb_endMonth.addItem( cal.get( cal.MONTH ) + 1 ); cmb_startDay.addItem( cal.get( cal.DATE ) ); cmb_endDay.addItem( cal.get( cal.DATE ) ); int i = 1900; int j = 2099; while ( i <= j ) { cmb_startYear.addItem(i); cmb_endYear.addItem(i); i++; } i = 1; j = 12; while ( i <= j ) { cmb_startMonth.addItem(i); cmb_endMonth.addItem(i); i++; } i = 1; j = 31; while ( i <= j ) { cmb_startDay.addItem(i); cmb_endDay.addItem(i); i++; } }
}
|