home *** CD-ROM | disk | FTP | other *** search
Java Source | 1999-02-11 | 2.4 KB | 85 lines |
- /* ****************************************************************
- ** @(#)messagebox.java 1.2 0
- **
- ** Copyright 1997 Sun Microsystems, Inc. All Rights Reserved
- **
- ** ****************************************************************
- */
-
- import java.awt.*;
- import java.awt.event.*;
-
- public class messagebox extends Frame implements ActionListener {
-
- public OpenlookButton ok;
- public Label message;
- private String title;
- private String messagetext;
- private boolean UseSetName=true;
-
- public messagebox(String caption,String messagestr,boolean setname) {
- this(caption,messagestr);
- UseSetName=setname;
- }
- public messagebox(String caption,String messagestr) {
- if (caption==null)
- caption="messagebox";
- setTitle(caption);
- setBackground(Color.lightGray);
-
- GridBagLayout grid = new GridBagLayout();
-
- ok=new OpenlookButton("Ok");
- if (UseSetName)
- ok.setName("ok_button");
- ok.setFont(new Font("Serif",Font.BOLD+Font.ITALIC,16));
- ok.addActionListener(this);
- add(ok);
-
- message=new Label(messagestr);
- if (UseSetName)
- message.setName("message_label");
- message.setFont(new Font("Serif",Font.BOLD+Font.ITALIC,14));
- add(message);
-
- constrain( grid, ok, 0, 2, 1, 1, GridBagConstraints.CENTER,GridBagConstraints.HORIZONTAL,0,0,30,30,30,30,0,0 );
- constrain( grid, message, 0, 1, 1, 1, GridBagConstraints.CENTER,GridBagConstraints.HORIZONTAL,0,0,30,30,30,30,0,0 );
-
- setLayout(grid);
- }
-
- public void doit(String caption,String messagestr) {
- setTitle(caption);
- message.setText(messagestr);
- remove(message);
- add(message);
- pack();
- show();
- }
-
- public void constrain(GridBagLayout grid,Component comp,int gridx,int gridy,int gridwidth,int gridheight,int anchor,int fill,int ipadx,int ipady,int top,int left,int bottom,int right,double weightx,double weighty) {
- GridBagConstraints con=new GridBagConstraints();
- con.gridx = gridx;
- con.gridy = gridy;
- con.gridwidth = gridwidth;
- con.gridheight = gridheight;
- con.anchor = anchor;
- con.fill = fill;
- con.ipadx = ipadx;
- con.ipady = ipady;
- con.weightx=weightx;
- con.weighty=weighty;
- con.insets = new Insets(top,left,bottom,right);
- grid.setConstraints(comp,con);
- }
-
- public void actionPerformed(ActionEvent event) {
- Component comp=(Component)event.getSource();
- if (comp==ok) {
- hide();
- }
- }
- }
-
-
-