Advertisement
alienxp03

SimpleCustomDialog

Feb 11th, 2013
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.58 KB | None | 0 0
  1. package test;
  2.  
  3. import java.awt.Dimension;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.WindowAdapter;
  7. import java.awt.event.WindowEvent;
  8.  
  9. import javax.swing.Box;
  10. import javax.swing.BoxLayout;
  11. import javax.swing.JButton;
  12. import javax.swing.JDialog;
  13. import javax.swing.JFrame;
  14. import javax.swing.JTextField;
  15.  
  16. class AboutDialog extends JDialog  {
  17.  
  18.     private JTextField text;
  19.    
  20.     public AboutDialog() {
  21.  
  22.         initUI();
  23.     }
  24.  
  25.     public final void initUI() {
  26.  
  27.         setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
  28.         add(Box.createRigidArea(new Dimension(0, 10)));
  29.  
  30.         text = new JTextField("user enter text");
  31.         add(text);
  32.  
  33.         add(Box.createRigidArea(new Dimension(0, 50)));
  34.  
  35.         JButton close = new JButton("Close");
  36.         close.addActionListener(new ActionListener() {
  37.            
  38.             public void actionPerformed(ActionEvent e) {
  39.                 SimpleCustomDialog.data.setPatientNameOList(text.getText());
  40.                 dispose(); 
  41.             }
  42.         });
  43.  
  44.         close.setAlignmentX(0.5f);
  45.         add(close);
  46.  
  47.         setModalityType(ModalityType.APPLICATION_MODAL);
  48.  
  49.         setTitle("About Notes");
  50.         setLocationRelativeTo(null);
  51.         setSize(300, 200);
  52.     }
  53. }
  54.  
  55. public class SimpleCustomDialog extends JFrame implements ActionListener {
  56.     JButton dialog;
  57.    
  58.     private static final long serialVersionUID = 1L;
  59.     public static SearchData data;
  60.  
  61.     public SimpleCustomDialog() {
  62.         data = new SearchData();
  63.         initUI();
  64.     }
  65.  
  66.     public final void initUI() {
  67.        
  68.         dialog = new JButton("Open dialog");
  69.         dialog.addActionListener(this);
  70.        
  71.         add(Box.createRigidArea(new Dimension(0, 50)));
  72.         this.add(dialog);
  73.  
  74.         setTitle("Simple Dialog");
  75.         setSize(300, 200);
  76.         setLocationRelativeTo(null);
  77.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  78.     }
  79.  
  80.     public static void main(String[] args) {
  81.         SimpleCustomDialog sd = new SimpleCustomDialog();
  82.         sd.setVisible(true);
  83.     }
  84.  
  85.     public void actionPerformed(ActionEvent e) {
  86.         AboutDialog ad = new AboutDialog();
  87.         ad.addWindowListener(new WindowAdapter() {
  88.             public void windowClosed(WindowEvent e) {
  89.                 dialog.setText("Name of user : "+SimpleCustomDialog.data.getPatientNameOList());
  90.             }
  91.         });
  92.         ad.setVisible(true);
  93.     }
  94. }
  95.  
  96. class SearchData{
  97.     private String patientNameOList;
  98.     private String raceOList;
  99.    
  100.     public String getPatientNameOList(){
  101.         return patientNameOList;
  102.     }
  103.    
  104.     public void setPatientNameOList(String patientNameOList){
  105.         this.patientNameOList = patientNameOList;
  106.     }
  107.    
  108.     public String getRaceOList(){
  109.         return raceOList;
  110.     }
  111.    
  112.     public void setRaceOList(String raceOList){
  113.         this.raceOList = raceOList;
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement