home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 25 / IOPROG_25.ISO / SOFT / JavaS / javastar-eval.exe / data1.cab / Program_Files / examples / namedb3 / messagebox.java < prev    next >
Encoding:
Java Source  |  1999-02-11  |  2.4 KB  |  98 lines

  1. /* ****************************************************************
  2. ** @(#)messagebox.java    1.2 97/02/24
  3. **
  4. ** Copyright 1997 Sun Microsystems, Inc. All Rights Reserved
  5. **
  6. ** ****************************************************************
  7. */
  8.  
  9. import java.awt.*;
  10.  
  11. public class messagebox extends Dialog {
  12.  
  13.   public Button ok;
  14.   public Label message;
  15.   private String title;
  16.   private String messagetext;
  17.  
  18.   public messagebox(Frame frame,boolean modal,String caption,String message) {
  19.     super(frame,modal);
  20.     title=caption;
  21.     messagetext=message;
  22.   }
  23.  
  24.   public void doit(String messagestr) {
  25.     doit("messagebox",messagestr);
  26.   }
  27.  
  28.   public void doit(String caption,String messagestr) {
  29.     setTitle(caption);
  30.     message.setText(messagestr);
  31.     pack();
  32.     show();
  33.   }
  34.  
  35.   public void init() {
  36.     if (title==null)
  37.       title=new String("messagebox");
  38.     setTitle(title);
  39.     this.setName(title);
  40.  
  41.     GridBagLayout grid = new GridBagLayout();
  42.     int rowHeights[] = {30,30,30,30,30};
  43.     int columnWidths[] = {30,30,30,30,30};
  44.     double rowWeights[] = {0.0,0.0,0.0,0.0,0.0};
  45.     double columnWeights[] = {0.0,0.0,0.0,0.0,0.0};
  46.     grid.rowHeights = rowHeights;
  47.     grid.columnWidths = columnWidths;
  48.     grid.rowWeights = rowWeights;
  49.     grid.columnWeights = columnWeights;
  50.     
  51.     ok=new Button("Ok");
  52.     ok.setName("ok_button");
  53.     add(ok);
  54.  
  55.     message=new Label(messagetext);
  56.     message.setName("message_label");
  57.     add(message);
  58.  
  59.     GridBagConstraints con = new GridBagConstraints();
  60.     reset(con);
  61.     con.gridx = 2;
  62.     con.gridy = 3;
  63.     grid.setConstraints(ok, con);
  64.  
  65.     reset(con);
  66.     con.gridx = 1;
  67.     con.gridy = 1;
  68.     con.gridwidth = 2;
  69.     grid.setConstraints(message, con);
  70.  
  71.     setLayout(grid);
  72.     pack();
  73.   }
  74.  
  75.   private void reset(GridBagConstraints con) {
  76.     con.gridx = GridBagConstraints.RELATIVE;
  77.     con.gridy = GridBagConstraints.RELATIVE;
  78.     con.gridwidth = 1;
  79.     con.gridheight = 1;
  80.  
  81.     con.weightx = 0;
  82.     con.weighty = 0;
  83.     con.anchor = GridBagConstraints.CENTER;
  84.     con.fill = GridBagConstraints.NONE;
  85.     
  86.     con.insets = new Insets(0, 0, 0, 0);
  87.     con.ipadx = 0;
  88.     con.ipady = 0;
  89.   }
  90.   public boolean handleEvent(Event event) {
  91.     if (event.target == ok && event.id == event.ACTION_EVENT) {
  92.       dispose();
  93.     } else
  94.       return super.handleEvent(event);
  95.     return true;
  96.   }
  97. }
  98.