home *** CD-ROM | disk | FTP | other *** search
Java Source | 1999-02-11 | 2.3 KB | 95 lines |
- /* ****************************************************************
- ** @(#)messagebox.java 1.2 97/02/24
- **
- ** Copyright 1997 Sun Microsystems, Inc. All Rights Reserved
- **
- ** ****************************************************************
- */
-
- import java.awt.*;
-
- public class messagebox extends Dialog {
-
- public Button ok;
- public Label message;
- private String title;
- private String messagetext;
-
- public messagebox(Frame frame,boolean modal,String caption,String message) {
- super(frame,modal);
- title=caption;
- messagetext=message;
- }
-
- public void doit(String messagestr) {
- doit("messagebox",messagestr);
- }
-
- public void doit(String caption,String messagestr) {
- setTitle(caption);
- message.setText(messagestr);
- pack();
- show();
- }
-
- public void init() {
- if (title==null)
- title=new String("messagebox");
- setTitle(title);
-
- GridBagLayout grid = new GridBagLayout();
- int rowHeights[] = {30,30,30,30,30};
- int columnWidths[] = {30,30,30,30,30};
- double rowWeights[] = {0.0,0.0,0.0,0.0,0.0};
- double columnWeights[] = {0.0,0.0,0.0,0.0,0.0};
- grid.rowHeights = rowHeights;
- grid.columnWidths = columnWidths;
- grid.rowWeights = rowWeights;
- grid.columnWeights = columnWeights;
-
- ok=new Button("Ok");
- add(ok);
-
- message=new Label(messagetext);
- add(message);
-
- GridBagConstraints con = new GridBagConstraints();
- reset(con);
- con.gridx = 2;
- con.gridy = 3;
- grid.setConstraints(ok, con);
-
- reset(con);
- con.gridx = 1;
- con.gridy = 1;
- con.gridwidth = 2;
- grid.setConstraints(message, con);
-
- setLayout(grid);
- pack();
- }
-
- private void reset(GridBagConstraints con) {
- con.gridx = GridBagConstraints.RELATIVE;
- con.gridy = GridBagConstraints.RELATIVE;
- con.gridwidth = 1;
- con.gridheight = 1;
-
- con.weightx = 0;
- con.weighty = 0;
- con.anchor = GridBagConstraints.CENTER;
- con.fill = GridBagConstraints.NONE;
-
- con.insets = new Insets(0, 0, 0, 0);
- con.ipadx = 0;
- con.ipady = 0;
- }
- public boolean handleEvent(Event event) {
- if (event.target == ok && event.id == event.ACTION_EVENT) {
- dispose();
- } else
- return super.handleEvent(event);
- return true;
- }
- }
-