package lecture.swing;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import jp.avaj.lib.debug.L;
import jp.avaj.lib.swing.PcScreen;
import jp.avaj.lib.swing.SwingComp;
/** JOptionPane.showInputDialogのサンプル Swing Java */
class OptionPaneInputDialog extends JFrame {
  public static void main(String[] args) {
    new OptionPaneInputDialog();
  }
 private OptionPaneInputDialog() {
   setTitle("OptionPaneInputDialog Test");
   JPanel mainPanel = new JPanel();
   getContentPane().add(mainPanel);
   mainPanel.setLayout(new BoxLayout(mainPanel,BoxLayout.Y_AXIS));
   // showInputDialog(Component parentComponent, Object message)
   {
     JPanel panel = new JPanel();
     mainPanel.add(panel);
     panel.setLayout(new BoxLayout(panel,BoxLayout.X_AXIS));
     panel.setBorder(new TitledBorder("showInputDialog"));
     //
     JButton btn0 = SwingComp.button("push-50",panel,null);
     btn0.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent ev) {
           String str = JOptionPane.showInputDialog(OptionPaneInputDialog.this,"入力してください");
           if (str != null) {
             L.p(str);
           }
           else {
             L.p("canceled");
           }
         }
       }
     );
   }
   // showInputDialog(Component parentComponent, Object message, Object initialSelectionValue)
   // 表示の初期値を設定する
   {
     JPanel panel = new JPanel();
     mainPanel.add(panel);
     panel.setLayout(new BoxLayout(panel,BoxLayout.X_AXIS));
     panel.setBorder(new TitledBorder("showInputDialog初期値設定"));
     //
     JButton btn0 = SwingComp.button("push-60",panel,null);
     btn0.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent ev) {
           String str = JOptionPane.showInputDialog(OptionPaneInputDialog.this,"入力してください","初期値");
           if (str != null) {
             L.p(str);
           }
           else {
             L.p("canceled");
           }
         }
       }
     );
   }
   // showInputDialog(Component parentComponent, Object message, String title, int messageType)
   // タイプを指定する⇒以下のどれか
   // ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE、または PLAIN_MESSAGE
   // タイプに応じたアイコンが表示される
   {
     JPanel panel = new JPanel();
     mainPanel.add(panel);
     panel.setLayout(new BoxLayout(panel,BoxLayout.X_AXIS));
     panel.setBorder(new TitledBorder("showInputDialogタイプ指定"));
     //
     // ERROR_MESSAGE
     JButton btn0 = SwingComp.button("push-70",panel,null);
     btn0.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent ev) {
           String str = JOptionPane.showInputDialog(OptionPaneInputDialog.this,"入力してください","ERROR_MESSAGEタイトル",JOptionPane.ERROR_MESSAGE);
           if (str != null) {
             L.p(str);
           }
           else {
             L.p("canceled");
           }
         }
       }
     );
     // INFORMATION_MESSAGE
     JButton btn1 = SwingComp.button("push-71",panel,null);
     btn1.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent ev) {
           String str = JOptionPane.showInputDialog(OptionPaneInputDialog.this,"入力してください","INFORMATION_MESSAGEタイトル",JOptionPane.INFORMATION_MESSAGE);
           if (str != null) {
             L.p(str);
           }
           else {
             L.p("canceled");
           }
         }
       }
     );
     // WARNING_MESSAGE
     JButton btn2 = SwingComp.button("push-72",panel,null);
     btn2.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent ev) {
           String str = JOptionPane.showInputDialog(OptionPaneInputDialog.this,"入力してください","WARNING_MESSAGEタイトル",JOptionPane.WARNING_MESSAGE);
           if (str != null) {
             L.p(str);
           }
           else {
             L.p("canceled");
           }
         }
       }
     );
     // QUESTION_MESSAGE
     JButton btn3 = SwingComp.button("push-73",panel,null);
     btn3.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent ev) {
           String str = JOptionPane.showInputDialog(OptionPaneInputDialog.this,"入力してください","QUESTION_MESSAGEタイトル",JOptionPane.QUESTION_MESSAGE);
           if (str != null) {
             L.p(str);
           }
           else {
             L.p("canceled");
           }
         }
       }
     );
     // PLAIN_MESSAGE ⇒ アイコンは表示されない
     JButton btn4 = SwingComp.button("push-74",panel,null);
     btn4.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent ev) {
           String str = JOptionPane.showInputDialog(OptionPaneInputDialog.this,"入力してください","PLAIN_MESSAGEタイトル",JOptionPane.PLAIN_MESSAGE);
           if (str != null) {
             L.p(str);
           }
           else {
             L.p("canceled");
           }
         }
       }
     );
   }
   // showInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue)
   // 複数の値を表示し、それから選択する ⇒ 初期値も設定できる
   // アイコンも指定することができる
   // メッセージタイプを指定する ⇒ 対応するアイコンが表示される
   // ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE、PLAIN_MESSAGE
   // 本例ではERROR_MESSAGEの場合のみ提示する
   {
     JPanel panel = new JPanel();
     mainPanel.add(panel);
     panel.setLayout(new BoxLayout(panel,BoxLayout.X_AXIS));
     panel.setBorder(new TitledBorder("showInputDialog複数値選択"));
     //
     JButton btn0 = SwingComp.button("push0-80",panel,null);
     btn0.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent ev) {
           Icon icon = new ImageIcon("meg.jpg");
           String str = (String)JOptionPane.showInputDialog(OptionPaneInputDialog.this,"複数値選択メッセージ","複数値選択タイトル",JOptionPane.ERROR_MESSAGE,icon,new Object[]{"aaaa","bbbb","cccc","dddd"},"bbbb");
           if (str != null) {
             L.p(str);
           }
           else {
             L.p("canceled");
           }
         }
       }
     );
   }
   // showInputDialog(Object message)
   // 親画面を指定しないで入力Dialogを表示する
   {
     JPanel panel = new JPanel();
     mainPanel.add(panel);
     panel.setLayout(new BoxLayout(panel,BoxLayout.X_AXIS));
     panel.setBorder(new TitledBorder("showInputDialog複数値選択"));
     //
     JButton btn0 = SwingComp.button("push-90",panel,null);
     btn0.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent ev) {
           String str = JOptionPane.showInputDialog("入力してください");
           if (str != null) {
             L.p(str);
           }
           else {
             L.p("canceled");
           }
         }
       }
     );
   }
   // showInputDialog(Object message, Object initialSelectionValue)
   // 親画面を指定しないで入力Dialogを表示する
   // 初期値を設定することができる
   {
     JPanel panel = new JPanel();
     mainPanel.add(panel);
     panel.setLayout(new BoxLayout(panel,BoxLayout.X_AXIS));
     panel.setBorder(new TitledBorder("showInputDialog複数値選択"));
     //
     JButton btn0 = SwingComp.button("push-100",panel,null);
     btn0.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent ev) {
           String str = JOptionPane.showInputDialog("入力してください","aaaa");
           if (str != null) {
             L.p(str);
           }
           else {
             L.p("canceled");
           }
         }
       }
     );
   }
   // showOptionDialog
   // ⇒ showMessageDialog,showConfirmMessage,showInputMesasageを合わせた機能を持っている
   // ⇒ 上のそれぞれを使えばよいので、サンプルは提示しない
   pack();
   PcScreen.display(this,PcScreen.POS_CENTER_CENTER);
   setVisible(true);
  }
}
//---------------------------------------------------
//・目次 - Swing
//  http://blogs.yahoo.co.jp/artery2020/40568561.html
//・目次 - Java入門
//  http://blogs.yahoo.co.jp/artery2020/39975776.html
//・目次 - ビジネスパーソンの常識と非常識
//  http://blogs.yahoo.co.jp/artery2020/39728331.html
//・目次 - 論理・発想・思考についての考察と鍛え方
//  http://blogs.yahoo.co.jp/artery2020/39657784.html
//---------------------------------------------------