
import javax.swing.*;  
import java.awt.*;  
import java.awt.event.*;  

/*
public class Dialog_preferences 
{  
    private static JDialog d;  
    public Dialog_preferences() 
    {  
        JFrame f= new JFrame();  
        d = new JDialog(f , "Dialog Example", true);  
        d.setLayout( new FlowLayout() );  
        JButton b = new JButton ("OK");  
        b.addActionListener ( new ActionListener()  
        {  
            public void actionPerformed( ActionEvent e )  
            {  
            	Dialog_preferences.d.setVisible(false);  
            }  
        });  
        d.add( new JLabel ("Click button to continue."));  
        d.add(b);   
        d.setSize(300,300);    
        d.setVisible(true);  
    } 
}
*/



import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

//http://www2.hawaii.edu/~takebaya/ics111/jdialog/jdialog.html

public class Dialog_edge extends JDialog implements ActionListener 
{
    private JTextField t1, t2;
    private JCheckBox c1, c2;
    private JButton b1, b2, b3;
    private JPanel topPanel, bottomPanel;
    private JPanel eastPanel, centerPanel;
    private JLabel l1, l2;
    private String[] data;
    
    private static JDialog d;  

    public Dialog_edge () //JFrame jFrame)
    {
    	//super(jFrame,"Enter data",true);
    	
    	 JFrame f= new JFrame();  
    	 d = new JDialog(f , "Preferences", true);  
    	 
    	 //Point loc = jFrame.getLocation();
         //setLocation(loc.x+250,loc.y+250);
    	     	 
         setLocation(250,250);
    	          
         d.setResizable( false );
         
         data = new String[2]; // set to amount of data items
         
        
         
         c1 = new JCheckBox("Snap to Grid");
         l1 = new JLabel("X:");
         t1 = new JTextField("8",3);

         topPanel = new JPanel();//uses flow layout by default
         topPanel.add(c1); topPanel.add(l1); topPanel.add(t1);

         c2 = new JCheckBox("Show Grid");
         l2 = new JLabel("Y:");
         t2 = new JTextField("8",3);

         bottomPanel = new JPanel();
         bottomPanel.add(c2);  bottomPanel.add(l2); bottomPanel.add(t2);

         centerPanel = new JPanel(new GridLayout(2,1));
         centerPanel.add(topPanel);
         centerPanel.add(bottomPanel);
         d.add(centerPanel,BorderLayout.CENTER);

         b1 = new JButton("Ok");
         b1.addActionListener(this);
         
         b2 = new JButton("Cancel");
         b3 = new JButton("Help");

         eastPanel = new JPanel(new GridLayout(3,1));
         eastPanel.add(b1);
         eastPanel.add(b2);
         eastPanel.add(b3);
         d.add(eastPanel, BorderLayout.EAST);
         
         
         d.setSize(300,300);    
         d.setVisible(true);  
         
    }

	@Override
	public void actionPerformed(ActionEvent ev) 
	{
		 System.out.println("Btn OK de la Jdialog");
		 
		 Object source = ev.getSource();
	     if (source == b1) 
	     {
	        // data[0] = "salut"; // t1.getText();//descBox.getText();
	        // data[1] = "pipo" ; //t2.getText();//(String)colorList.getSelectedItem();
	    	 
	    	 data[0]  = "un";
	         data[1] = "deux";
	     	
	    	 
	     }
	     else 
	     {
	         data[0] = null;
	     }
	     
	     setVisible(false);
	     dispose();
		 
		
	}
	
	public String[] run() {
	      this.setVisible(true);
	      return data;
	   }

  
}