Notice
Recent Posts
Recent Comments
Link
«   2025/06   »
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
Archives
Today
Total
관리 메뉴

JAVA Developer Training

4. JAVA 프로젝트 3. 패널 생성 본문

트레이닝

4. JAVA 프로젝트 3. 패널 생성

Romenest 2021. 8. 27. 13:58

package com.example.view;

 

import javax.swing.JPanel;

import javax.swing.JLayeredPane

//import

 

홈화면

public class HomePanel extends JPanel {

    public HomePanel() {

        

        JLayeredPane layeredPane = new JLayeredPane();

        add(layeredPane);

    }

 

}

 

물품 등록화면

//InsertPanel <= JPanel,ActionListener 두개의 부모 , 두개를 사용할떈 this를 이용

public class InsertPanel extends JPanel implements ActionListener {

    private JTextField textField = null;

    private JTextField textField_1 = null;

    private JTextField textField_2 = null;

    private JTextField textField_3 = null;

    private JTextArea textArea = null;

    private JButton btnNewButton = null;

 

    @Override

    public void actionPerformed(ActionEvent e) {

        // actionListener를 거치는것들은 모두 이 곳을 거치니 각 조건을 걸어 필터링해야함

 

        // 버튼 클릭시

        if (e.getSource() == btnNewButton) {

            // System.out.println("click button");

            // int == integer(클래스)

            int code = Integer.parseInt(textField.getText());

            String name = textField_1.getText();

            String text = textArea.getText();

            int price = Integer.parseInt(textField_2.getText());

            long quantity = Long.parseLong(textField_3.getText());

 

            Item item = new Item();

            item.setCode(code);

            item.setName(name);

            item.setText(text);

            item.setPrice(price);

            item.setQuantity(quantity);

 

            int ret = ItemDB.getInstance().insertItem(item);

            if (ret == 1) {

                JOptionPane.showMessageDialog(this"물품등록성공""성공"JOptionPane.INFORMATION_MESSAGE);

                textField.setText("");

                textField_1.setText("");

                textField_2.setText("");

                textField_3.setText("");

                textArea.setText("");

 

            } else {

                JOptionPane.showMessageDialog(this"물품등록실패""실패"JOptionPane.INFORMATION_MESSAGE);

            }

 

        }

 

    }

 

    public InsertPanel() {

        super();

 

        this.setLayout(null);

 

        JLabel lblNewLabel = new JLabel("물품번호");

        lblNewLabel.setBounds(32315015);

        this.add(lblNewLabel);

 

        textField = new JTextField();

        textField.setBounds(832814421);

        this.add(textField);

        textField.setColumns(10);

 

        JLabel lblNewLabel_1 = new JLabel("물품명");

        lblNewLabel_1.setBounds(32635015);

        this.add(lblNewLabel_1);

 

        textField_1 = new JTextField();

        textField_1.setBounds(836014421);

        this.add(textField_1);

        textField_1.setColumns(10);

 

        JLabel lblNewLabel_2 = new JLabel("물품내용");

        lblNewLabel_2.setBounds(32965015);

        this.add(lblNewLabel_2);

 

        textArea = new JTextArea();

        textArea.setBounds(839114455);

        this.add(textArea);

 

        JLabel lblNewLabel_3 = new JLabel("물품가격");

        lblNewLabel_3.setBounds(321595015);

        this.add(lblNewLabel_3);

 

        textField_2 = new JTextField();

        textField_2.setColumns(10);

        textField_2.setBounds(8315614421);

        this.add(textField_2);

 

        JLabel lblNewLabel_1_1 = new JLabel("수량");

        lblNewLabel_1_1.setBounds(321915015);

        this.add(lblNewLabel_1_1);

 

        textField_3 = new JTextField();

        textField_3.setColumns(10);

        textField_3.setBounds(8318814421);

        this.add(textField_3);

 

        btnNewButton = new JButton("물품등록");

        btnNewButton.setBounds(832319123);

        this.add(btnNewButton);

        btnNewButton.addActionListener(this);

    }

 

}

 

 

 

 

//물품 조회 화면

public class SelectPanel extends JPanel implements ActionListener {

    private JButton button1 = null// 수정

    private JButton button2 = null// 삭제

 

    @Override

    public void actionPerformed(ActionEvent e) {

        if (e.getSource() == button1) {

            try {

                ItemTable.getInstance().updateData();

            } catch (Exception e1) {

 

                e1.printStackTrace();

            }

        } else if (e.getSource() == button2) {

            try {

                int ret = JOptionPane.showConfirmDialog(null"삭제하시겠습니까?""삭제"JOptionPane.OK_CANCEL_OPTION);

                if (ret == 0) {

                    ItemTable.getInstance().deleteData();

                }

 

            } catch (Exception e1) {

 

                e1.printStackTrace();

            }

        }

 

    }

 

    public SelectPanel() {

        this.setLayout(new BorderLayout());

 

        JScrollPane scroll = new JScrollPane(ItemTable.getInstance());

        this.add(scrollBorderLayout.CENTER);

 

        JPanel panel = new JPanel();

        button1 = new JButton("수정");

        button2 = new JButton("삭제");

        panel.add(button1);

        panel.add(button2);

        this.add(panelBorderLayout.SOUTH);

 

        button1.addActionListener(this);

        button2.addActionListener(this);

 

    }

 

}

 

'트레이닝' 카테고리의 다른 글

6. ermaster 테이블 DB설계  (0) 2021.08.27
5. JAVA 프로젝트 4. 프레임 생성  (0) 2021.08.27
3. JAVA 프로젝트 2. Table 생성  (0) 2021.08.27
2. JAVA 프로젝트 1. DB연동  (0) 2021.08.27
1 . JAVA 프로젝트  (0) 2021.08.27