home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 25 / IOPROG_25.ISO / SOFT / JavaS / javastar-eval.exe / data1.cab / Program_Files / examples / namedb2 / messagebox.java < prev    next >
Encoding:
Java Source  |  1999-02-11  |  2.3 KB  |  95 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.  
  40.     GridBagLayout grid = new GridBagLayout();
  41.     int rowHeights[] = {30,30,30,30,30};
  42.     int columnWidths[] = {30,30,30,30,30};
  43.     double rowWeights[] = {0.0,0.0,0.0,0.0,0.0};
  44.     double columnWeights[] = {0.0,0.0,0.0,0.0,0.0};
  45.     grid.rowHeights = rowHeights;
  46.     grid.columnWidths = columnWidths;
  47.     grid.rowWeights = rowWeights;
  48.     grid.columnWeights = columnWeights;
  49.     
  50.     ok=new Button("Ok");
  51.     add(ok);
  52.  
  53.     message=new Label(messagetext);
  54.     add(message);
  55.  
  56.     GridBagConstraints con = new GridBagConstraints();
  57.     reset(con);
  58.     con.gridx = 2;
  59.     con.gridy = 3;
  60.     grid.setConstraints(ok, con);
  61.  
  62.     reset(con);
  63.     con.gridx = 1;
  64.     con.gridy = 1;
  65.     con.gridwidth = 2;
  66.     grid.setConstraints(message, con);
  67.  
  68.     setLayout(grid);
  69.     pack();
  70.   }
  71.  
  72.   private void reset(GridBagConstraints con) {
  73.     con.gridx = GridBagConstraints.RELATIVE;
  74.     con.gridy = GridBagConstraints.RELATIVE;
  75.     con.gridwidth = 1;
  76.     con.gridheight = 1;
  77.  
  78.     con.weightx = 0;
  79.     con.weighty = 0;
  80.     con.anchor = GridBagConstraints.CENTER;
  81.     con.fill = GridBagConstraints.NONE;
  82.     
  83.     con.insets = new Insets(0, 0, 0, 0);
  84.     con.ipadx = 0;
  85.     con.ipady = 0;
  86.   }
  87.   public boolean handleEvent(Event event) {
  88.     if (event.target == ok && event.id == event.ACTION_EVENT) {
  89.       dispose();
  90.     } else
  91.       return super.handleEvent(event);
  92.     return true;
  93.   }
  94. }
  95.