home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 September / dppcpro0998.iso / Rwc / Sybase / Install.exe / samples.z / MessageBox.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-03-25  |  4.8 KB  |  202 lines

  1. import java.awt.Button;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Dialog;
  6. import java.awt.Event;
  7. import java.awt.Font;
  8. import java.awt.FontMetrics;
  9. import java.awt.Frame;
  10. import java.awt.Insets;
  11. import java.awt.Label;
  12. import java.awt.Rectangle;
  13. import java.awt.Window;
  14. import java.awt.event.ActionEvent;
  15. import java.awt.event.ActionListener;
  16. import java.awt.event.WindowEvent;
  17. import java.awt.event.WindowListener;
  18. import java.util.EventObject;
  19. import powersoft.powerj.event.AWTEvent;
  20. import powersoft.powerj.event.EventData;
  21. import powersoft.powerj.ui.ResizePercentLayout;
  22.  
  23. class MessageBox extends Dialog implements WindowListener, ActionListener {
  24.    boolean __mainForm;
  25.    private Button cb_1 = new Button();
  26.    private Label label_message = new Label();
  27.    private String _message;
  28.  
  29.    public Rectangle DURectangle(int var1, int var2, int var3, int var4) {
  30.       String var5 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  31.       FontMetrics var6 = ((Component)this).getFontMetrics(((Component)this).getFont());
  32.       double var7 = (double)(var6 != null ? var6.stringWidth(var5) / var5.length() : 0);
  33.       double var9 = var6 != null ? (double)var6.getHeight() / (double)2.0F : (double)0.0F;
  34.       return new Rectangle((int)Math.round(var7 * (double)var1 / (double)4.0F), (int)Math.round(var9 * (double)var2 / (double)4.0F), (int)Math.round(var7 * (double)var3 / (double)4.0F), (int)Math.round(var9 * (double)var4 / (double)4.0F));
  35.    }
  36.  
  37.    public void DUPositionComponent(Component var1, int var2, int var3, int var4, int var5, Insets var6) {
  38.       Rectangle var7 = this.DURectangle(var2, var3, var4, var5);
  39.       if (var1 != this && var6 != null) {
  40.          var7.x += var6.left;
  41.          var7.y += var6.top;
  42.       }
  43.  
  44.       if (var1 == this && var6 != null && var6.bottom > 0) {
  45.          var7.height += var6.bottom;
  46.       }
  47.  
  48.       var1.setBounds(var7);
  49.    }
  50.  
  51.    public void setMainForm(boolean var1) {
  52.       this.__mainForm = var1;
  53.    }
  54.  
  55.    public boolean isMainForm() {
  56.       return this.__mainForm;
  57.    }
  58.  
  59.    public boolean create() throws Exception {
  60.       ((Dialog)this).setResizable(true);
  61.       Container var1 = this.getContentPane();
  62.       Font var2 = new Font("Dialog", 0, 12);
  63.       ((Component)this).setFont(var2);
  64.       boolean var3 = true;
  65.       ((Dialog)this).addNotify();
  66.       Insets var4 = (Insets)var1.getInsets().clone();
  67.       ((Component)var1).setBackground(Color.lightGray);
  68.       ((Component)var1).setForeground(Color.black);
  69.       ResizePercentLayout var5 = new ResizePercentLayout();
  70.       var1.setLayout(var5);
  71.       var1.add(this.cb_1);
  72.       var1.add(this.label_message);
  73.       this.DUPositionComponent(this, 107, 116, 226, 61, var4);
  74.       ((Window)this).addWindowListener(this);
  75.       this.cb_1.addActionListener(this);
  76.       this.DUPositionComponent(this.cb_1, 85, 25, 45, 14, var4);
  77.       this.cb_1.setFont(var2);
  78.       this.cb_1.setBackground(Color.lightGray);
  79.       this.cb_1.setForeground(Color.black);
  80.       this.cb_1.setEnabled(true);
  81.       this.cb_1.setVisible(true);
  82.       this.cb_1.setLabel("OK");
  83.       this.DUPositionComponent(this.label_message, 5, 5, 210, 10, var4);
  84.       this.label_message.setText("Message");
  85.       this.label_message.setAlignment(1);
  86.       this.label_message.setFont(var2);
  87.       this.label_message.setBackground(Color.lightGray);
  88.       this.label_message.setForeground(Color.black);
  89.       this.label_message.setEnabled(true);
  90.       this.label_message.setVisible(true);
  91.       var5.setResizePercent(this.cb_1, new Rectangle(0, 0, 0, 0));
  92.       var5.setResizePercent(this.label_message, new Rectangle(0, 0, 0, 0));
  93.       this.MessageBox_objectCreated(new EventData(this));
  94.       ((Component)this).setVisible(true);
  95.       return var3;
  96.    }
  97.  
  98.    public synchronized boolean destroy() {
  99.       if (this instanceof Window) {
  100.          ((Window)this).dispose();
  101.       } else {
  102.          ((Container)this).removeNotify();
  103.       }
  104.  
  105.       if (this.isMainForm()) {
  106.          System.gc();
  107.          System.runFinalization();
  108.          System.exit(0);
  109.       }
  110.  
  111.       return true;
  112.    }
  113.  
  114.    public boolean defaultHandleEvent(Event var1) {
  115.       this.defaultProcessEvent(new AWTEvent(var1));
  116.       return false;
  117.    }
  118.  
  119.    public void defaultProcessEvent(java.awt.AWTEvent var1) {
  120.       super.processEvent(var1);
  121.    }
  122.  
  123.    public void windowClosed(WindowEvent var1) {
  124.    }
  125.  
  126.    public void windowOpened(WindowEvent var1) {
  127.    }
  128.  
  129.    public void windowClosing(WindowEvent var1) {
  130.       Object var2 = ((EventObject)var1).getSource();
  131.       if (var2 == this) {
  132.          this.MessageBox_windowClosing(var1);
  133.       } else {
  134.          this.unhandledEvent("java.awt.event.WindowListener", "windowClosing", var1);
  135.       }
  136.  
  137.    }
  138.  
  139.    public void windowIconified(WindowEvent var1) {
  140.    }
  141.  
  142.    public void windowActivated(WindowEvent var1) {
  143.    }
  144.  
  145.    public void windowDeiconified(WindowEvent var1) {
  146.    }
  147.  
  148.    public void windowDeactivated(WindowEvent var1) {
  149.    }
  150.  
  151.    public void actionPerformed(ActionEvent var1) {
  152.       Object var2 = ((EventObject)var1).getSource();
  153.       if (var2 == this.cb_1) {
  154.          this.cb_1_actionPerformed(var1);
  155.       } else {
  156.          this.unhandledEvent("java.awt.event.ActionListener", "actionPerformed", var1);
  157.       }
  158.  
  159.    }
  160.  
  161.    public MessageBox(Frame var1, String var2) {
  162.       super(var1, true);
  163.       this._message = var2;
  164.    }
  165.  
  166.    public MessageBox(String var1) {
  167.       super((Frame)null, true);
  168.       this._message = var1;
  169.    }
  170.  
  171.    public boolean handleEvent(Event var1) {
  172.       return this.defaultHandleEvent(var1);
  173.    }
  174.  
  175.    public void unhandledEvent(String var1, String var2, Object var3) {
  176.    }
  177.  
  178.    public void processEvent(java.awt.AWTEvent var1) {
  179.       this.defaultProcessEvent(var1);
  180.    }
  181.  
  182.    public Container getContentPane() {
  183.       return this;
  184.    }
  185.  
  186.    public boolean MessageBox_objectCreated(EventData var1) {
  187.       this.label_message.setText(this._message);
  188.       return false;
  189.    }
  190.  
  191.    public boolean MessageBox_windowClosing(WindowEvent var1) {
  192.       ((Component)this).setVisible(false);
  193.       this.destroy();
  194.       return false;
  195.    }
  196.  
  197.    public boolean cb_1_actionPerformed(ActionEvent var1) {
  198.       this.destroy();
  199.       return false;
  200.    }
  201. }
  202.