package memberAction;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.JApplet;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.DefaultTableModel;

public class memberAction extends JApplet implements ActionListener {


    private static final long serialVersionUID = 1L;
    JTable table;
    DefaultTableModel model;
    String[] header = new String[] { "No", "メニュー一覧","詳細内容"};
    String[][] data = new String[][]
    { { "1", "全件表示",""},
            { "2", "１件検索",""},
            {"3","新規登録",""},
            {"4","削除処理",""},
            {"5","更新処理",""},
            {"6","メインメニューに戻る",""}};


    JPanel panel = new JPanel();
    JTextField number = new JTextField(8);
    JTextField menuName = new JTextField(8);
    JTextField details = new JTextField(4);
    Button transitBtn = new Button("選択");
    Choice cho;

    public void init() {

        // 背景色の設定
        Container c = getContentPane();
        c.setBackground(Color.WHITE);
        int w = getWidth();
        int h = getHeight();
        setLayout(new BorderLayout());

        // テーブルオブジェクトの生成
        model = new DefaultTableModel(data, header);
        table = new JTable(model);
        table.setGridColor(Color.BLUE);
        DefaultTableColumnModel columnModel = (DefaultTableColumnModel) table.getColumnModel();
        columnModel.getColumn(1).setPreferredWidth(20);
        // テーブルをレイアウトに追加
        JScrollPane sc = new JScrollPane(table);
        sc.setBackground(Color.WHITE);
        sc.setPreferredSize(new Dimension(w, h - 60));
        add(sc, BorderLayout.NORTH);
        panel.setPreferredSize(new Dimension(w, 30));
        panel.setLayout(new BorderLayout());
        number.setPreferredSize(new Dimension(10, 25));
        panel.add(number, BorderLayout.WEST);
        menuName.setPreferredSize(new Dimension(20, 25));
        panel.add(menuName, BorderLayout.CENTER);
        panel.add(details, BorderLayout.EAST);
        add(panel, BorderLayout.CENTER);


        cho = (Choice)add(new Choice());
        cho.add("--選択してください--");
        cho.add("1.全件表示");
        cho.add("2.１件検索");
        cho.add("3.新規登録");
        cho.add("4.削除更新");
        cho.add("5.書換更新");
        cho.add("6.メインメニューに戻る");

        transitBtn.setPreferredSize(new Dimension(w, 30));
        transitBtn.addActionListener(this);
        add(transitBtn, BorderLayout.SOUTH);



        // テーブルの上下左右の余白設定
        add(Box.createHorizontalStrut(10), BorderLayout.EAST);
        add(Box.createHorizontalStrut(10), BorderLayout.WEST);
    }

    public void actionPerformed(ActionEvent event) {
        if (event.getSource() == transitBtn) {
            String checkNumber = number.getText();
            String checkMenuname = menuName.getText();
            String checkDetails = details.getText();
            System.out.println(cho+","+cho.getSelectedItem()+cho.getSelectedIndex());

            if(cho.getSelectedIndex()==1){
                System.out.println("全件表示");
                System.out.println("Address was transfer");
            }else if(cho.getSelectedIndex()==2){
                System.out.println("１件表示");
                System.out.println("Address was transfer");
            }else if(cho.getSelectedIndex()==3){
                System.out.println("新規登録");
                System.out.println("Address was transfer");
            }else if(cho.getSelectedIndex()==4){
                System.out.println("削除");
                System.out.println("Address was transfer");
            }else if(cho.getSelectedIndex()==5){
                System.out.println("更新");
                System.out.println("Address was transfer");
            }else if(cho.getSelectedIndex()==6){
                System.out.println("戻る");
                System.out.println("Address was transfer");
            }
        }
    }


}
