home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 July / Chip_1998-07_cd.bin / zkuste / JBuilder / BDK / Win / bdk_sep97.exe / _SETUP.1 / MessageDialog.java < prev    next >
Encoding:
Java Source  |  1997-09-10  |  1.5 KB  |  69 lines

  1.  
  2. /**
  3.  * Pop up a (modal) Message dialog and wait for a user to press "continue".
  4.  */
  5.  
  6. package sun.beanbox;
  7.  
  8. import java.awt.*;
  9. import java.awt.event.*;
  10.  
  11. public class MessageDialog extends Dialog implements ActionListener {
  12.  
  13.     public MessageDialog(Frame frame, String title, String message) {
  14.     this(frame, title, message, false);
  15.     }
  16.  
  17.     public MessageDialog(Frame frame, String title,
  18.              String message, boolean leftIndented) {
  19.     super(frame, title, true);
  20.         new WindowCloser(this);
  21.     
  22.     GridBagLayout gridBag = new GridBagLayout();
  23.     setLayout(gridBag);
  24.     GridBagConstraints cons = new GridBagConstraints();
  25.     cons.gridwidth = GridBagConstraints.REMAINDER;
  26.     if (leftIndented) {
  27.         cons.anchor = GridBagConstraints.WEST;
  28.     }
  29.  
  30.     // Add a "Label" for reach line of text.
  31.     int width = 400;
  32.     int height = 5;
  33.     while (message.length() > 0) {
  34.         int ix = message.indexOf('\n');
  35.         String line;
  36.         if (ix >= 0) {
  37.         line = message.substring(0, ix);
  38.         message = message.substring(ix+1);
  39.         } else {
  40.         line = message;
  41.         message = "";
  42.         }
  43.         Label l = new Label(line);
  44.         gridBag.setConstraints(l, cons);
  45.         add(l);
  46.         height += 20;
  47.     }
  48.  
  49.     cons.anchor = GridBagConstraints.CENTER;
  50.     Button b = new Button("Continue");
  51.     b.addActionListener(this);
  52.     gridBag.setConstraints(b, cons);
  53.     add(b);
  54.     height += 25;
  55.     height += 35;
  56.  
  57.         int x = frame.getLocation().x + 30;
  58.         int y = frame.getLocation().y + 100;
  59.         setBounds(x, y, 400, height+5);
  60.         show();
  61.     }
  62.  
  63.     public void actionPerformed(ActionEvent evt) {
  64.     // our button got pushed.
  65.         dispose();
  66.     }
  67.  
  68. }
  69.