src/Tools/GraphBrowser/awtUtilities/MessageDialog.java
changeset 74015 12b1f4649ab1
parent 74014 3b8b1da2ff29
child 74016 027fb21bdd5d
equal deleted inserted replaced
74014:3b8b1da2ff29 74015:12b1f4649ab1
     1 /***************************************************************************
       
     2   Title:      awtUtilities/MessageDialog.java
       
     3   Author:     Stefan Berghofer, TU Muenchen
       
     4 
       
     5   This class defines a dialog window for displaying messages and buttons.
       
     6 ***************************************************************************/
       
     7 
       
     8 package awtUtilities;
       
     9 
       
    10 import java.awt.*;
       
    11 import java.awt.event.*;
       
    12 
       
    13 public class MessageDialog extends Dialog implements ActionListener {
       
    14 	String txt;
       
    15 
       
    16 	public String getText() { return txt; }
       
    17 
       
    18 	public void actionPerformed(ActionEvent evt) {
       
    19 		txt = evt.getActionCommand();
       
    20 		setVisible(false);
       
    21 	}
       
    22 
       
    23 	public MessageDialog(Frame parent,String title,String text,String []buttons) {
       
    24 		super(parent,title,true);
       
    25 		int i;
       
    26 		Panel p1=new Panel(),p2=new Panel();
       
    27 		p1.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
       
    28 		p2.setLayout(new FlowLayout());
       
    29 		setFont(new Font("Helvetica", Font.PLAIN, 14));
       
    30 		setLayout(new GridLayout(2,1));
       
    31 
       
    32 		while (true) {
       
    33 			int pos=text.indexOf(' ');
       
    34 			if (pos<0) {
       
    35 				p1.add(new Label(text));
       
    36 				break;
       
    37 			} else {
       
    38 				p1.add(new Label(text.substring(0,pos)));
       
    39 				if (pos+1==text.length())
       
    40 					break;
       
    41 				else
       
    42 					text=text.substring(pos+1);
       
    43 			}
       
    44 		}
       
    45 
       
    46 		add(p1);add(p2);
       
    47 		for (i=0;i<buttons.length;i++) {
       
    48 			Button bt = new Button(buttons[i]);
       
    49 			p2.add(bt);
       
    50 			bt.addActionListener(this);
       
    51 		}
       
    52 	}
       
    53 }