source: trunk/j/src/bsh/commands/frame.bsh @ 2

Last change on this file since 2 was 2, checked in by piso, 18 years ago

Initial checkin.

File size: 1016 bytes
Line 
1/*
2    Show component in a frame, centered and packed.  Handle disposal.
3*/
4bsh.help.frame = "usage: frame( Component component )";
5 
6import java.awt.*;
7import bsh.Capabilities;
8
9frame( Component comp ) {
10
11  // Ignore unhandled method invocations from listeners.
12  invoke( method, args ) { }
13
14    windowClosing( event ) {
15        frame.dispose();
16    }
17
18  // if the desktop is there make an internal frame
19  if ( bsh.system.desktop != void ) {
20    frame = bsh.system.desktop.makeInternalFrame("frame");
21    frame.setClosable(true);
22    frame.getContentPane().add( comp, "Center" );
23      frame.pack();  // must pack before adding to desktop?
24    bsh.system.desktop.addInternalFrame( frame );
25  } else {
26    // make an external JFrame or Frame
27    if ( Capabilities.haveSwing() ) {
28      frame = new javax.swing.JFrame();
29      frame.getContentPane().add( comp, "Center" );
30    } else {
31      frame = new Frame();
32      frame.add( comp, "Center" );
33    }
34
35    frame.addWindowListener(this);
36      frame.pack();
37  }
38
39    frame.show();
40    return frame;
41}
42
Note: See TracBrowser for help on using the repository browser.