Java Code Examples for java.awt.Frame#addWindowListener()

The following examples show how to use java.awt.Frame#addWindowListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UILauncher.java    From JPPF with Apache License 2.0 6 votes vote down vote up
/**
 * Load the UI from the specified path to an XML descriptor.
 * @param src the path tot he XML docuemnt to load
 * @param type the type of the path: url or file.
 * @return the root {@link JComponent} of the admin console.
 * @since 5.0
 */
private synchronized static JComponent loadUI(final String src, final String type) {
  if (consoleComponent == null) {
    OptionElement elt = null;
    try {
      final Frame frame = new JFrame();
      OptionsHandler.setMainWindow(frame);
      frame.addWindowListener(new WindowClosingListener());
      if ("url".equalsIgnoreCase(type)) elt = OptionsHandler.addPageFromURL(src, null);
      else elt = OptionsHandler.addPageFromXml(src);
      frame.add(elt.getUIComponent());
      OptionsHandler.loadPreferences();
      frame.setTitle(elt.getLabel());
      final String iconPath = elt.getIconPath();
      frame.setIconImage(GuiUtils.loadIcon(iconPath != null ? iconPath : GuiUtils.JPPF_ICON).getImage());
      OptionsHandler.loadMainWindowAttributes(OptionsHandler.getPreferences().node(elt.getName()));
      OptionsHandler.getBuilder().triggerInitialEvents(elt);
    } catch (final Exception e) {
      e.printStackTrace();
      log.error(e.getMessage(), e);
    }
    consoleComponent = (elt == null) ? null : elt.getUIComponent();
  }
  return consoleComponent;
}
 
Example 2
Source File: MultiMonPrintDlgTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void executeTest() {

        GraphicsDevice defDev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        int x = 0;
        Frame f = null;
        for (x = 0; x < gd.length; x ++) {
            if (gd[x] != defDev) {
                secFrame = new Frame("Screen " + x + " - secondary", gd[x].getDefaultConfiguration());
                f = secFrame;
            } else {
                primaryFrame = new Frame("Screen " + x + " - primary", gd[x].getDefaultConfiguration());
                f = primaryFrame;
            }
            Button b = new Button("Print");
            b.addActionListener(this);
            f.add("South", b);
            f.addWindowListener (new WindowAdapter() {
                public void windowClosing(WindowEvent we) {
                    ((Window) we.getSource()).dispose();
                }
            });
            f.setSize(200, 200);
            f.setVisible(true);
        }
    }
 
Example 3
Source File: VncClient.java    From cosmic with Apache License 2.0 6 votes vote down vote up
private Frame createVncClientMainWindow(final BufferedImageCanvas canvas, final String title) {
    // Create AWT windows
    final Frame frame = new Frame(title + " - VNCle");

    // Use scrolling pane to support screens, which are larger than ours
    final ScrollPane scroller = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
    scroller.add(canvas);
    scroller.setSize(this.screen.getFramebufferWidth(), this.screen.getFramebufferHeight());

    frame.add(scroller);
    frame.pack();
    frame.setVisible(true);

    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(final WindowEvent evt) {
            frame.setVisible(false);
            shutdown();
        }
    });

    return frame;
}
 
Example 4
Source File: FrameDemo2.java    From Java with Artistic License 2.0 6 votes vote down vote up
public static void main(String[] args) {
	// ��������
	Frame f = new Frame();

	// ��������
	f.setTitle("����ر�");
	f.setSize(400, 200);
	f.setLocation(500, 250);

	// ע���¼�
	f.addWindowListener(new WindowAdapter() {
		@Override
		public void windowClosing(WindowEvent e) {
			System.exit(0);
		}
	});

	// ���ô���ɼ�
	f.setVisible(true);
}
 
Example 5
Source File: Client.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
protected static Frame createVncClientMainWindow(BufferedImageCanvas canvas, String title, WindowListener windowListener) {
    // Create AWT windows
    Frame frame = new Frame(title + " - RDP");

    // Use scrolling pane to support screens, which are larger than ours
    scroller = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
    scroller.add(canvas);
    scroller.setSize(canvas.getWidth(), canvas.getHeight());

    frame.add(scroller);
    frame.pack();
    frame.setVisible(true);

    frame.addWindowListener(windowListener);

    return frame;
}
 
Example 6
Source File: VncClient.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
private Frame createVncClientMainWindow(BufferedImageCanvas canvas, String title) {
    // Create AWT windows
    final Frame frame = new Frame(title + " - VNCle");

    // Use scrolling pane to support screens, which are larger than ours
    ScrollPane scroller = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
    scroller.add(canvas);
    scroller.setSize(screen.getFramebufferWidth(), screen.getFramebufferHeight());

    frame.add(scroller);
    frame.pack();
    frame.setVisible(true);

    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent evt) {
            frame.setVisible(false);
            shutdown();
        }
    });

    return frame;
}
 
Example 7
Source File: GLVisualProcessorTester.java    From constellation with Apache License 2.0 5 votes vote down vote up
public GLVisualProcessorDemo() {
    frame = new Frame("JOGL Tester");
    frame.setSize(1920, 1080);
    frame.setResizable(false);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            frame.dispose();
            System.exit(0);
        }
    });
}
 
Example 8
Source File: GLVisualProcessorGraphTester.java    From constellation with Apache License 2.0 5 votes vote down vote up
public GLVisualProcessorDemo() {
    frame = new Frame("JOGL Tester");
    frame.setSize(1920, 1080);
    frame.setResizable(false);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            frame.dispose();
            System.exit(0);
        }
    });
}
 
Example 9
Source File: AWTConsole.java    From beanshell with Apache License 2.0 5 votes vote down vote up
public static void main( String args[] ) {
    AWTConsole console = new AWTConsole();
    final Frame f = new Frame("Bsh Console");
    f.add(console, "Center");
    f.pack();
    f.setVisible(true);
    f.addWindowListener( new WindowAdapter() {
        public void windowClosing( WindowEvent e ) {
            f.dispose();
        }
    } );

    interpreter = new Interpreter( console );
    interpreter.run();
}
 
Example 10
Source File: BasicStrokeExample.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {
  Frame frame = new Frame("BasicStrokeExample ");
  frame.setSize(300, 200);
  frame.add(new CanvasToDisplay());
  frame.setVisible(true);
  frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
      System.exit(0);
    }
  });
}
 
Example 11
Source File: DelaunayTriangulationExample.java    From delaunay-triangulator with MIT License 5 votes vote down vote up
public static void main(String[] args) {
    Frame frame = new Frame("Delaunay Triangulation Example");
    frame.setResizable(false);

    GLCapabilities caps = new GLCapabilities(GLProfile.get("GL2"));
    caps.setSampleBuffers(true);
    caps.setNumSamples(8);

    GLCanvas canvas = new GLCanvas(caps);

    DelaunayTriangulationExample ex = new DelaunayTriangulationExample();
    MouseListener lister = ex;
    canvas.addGLEventListener(ex);
    canvas.setPreferredSize(DIMENSION);
    canvas.addMouseListener(lister);

    frame.add(canvas);

    final FPSAnimator animator = new FPSAnimator(canvas, 25);

    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            new Thread(new Runnable() {
                public void run() {
                    animator.stop();
                    System.exit(0);
                }
            }).start();
        }
    });

    frame.setVisible(true);
    frame.pack();
    animator.start();
}
 
Example 12
Source File: AWTFontCalibration.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
@Override
  public void run()
  {
      Logger.getLogger("").setLevel(Level.CONFIG);
      for (Handler handler : Logger.getLogger("").getHandlers())
          handler.setLevel(Level.CONFIG);

      final double factor = getCalibrationFactor();

      final Frame frame = new Frame("Java AWT: Calibration factor " + factor);
      frame.setSize(text_width, text_height);
      
      // Would like to use TextField or Label, but:
      // "Peered AWT components, such as Label and TextField,
      //  can only use logical fonts." (Javadoc for 'Font')
      // Sure enough at least on Windows the font family is
      // ignored, only the style and size are honored
      // by Label.setFont() or TextField.setFont()
      // --> Use canvas and draw the text with font.
      final Canvas text = new Canvas()
{
	private static final long serialVersionUID = 1L;

	@Override
	public void paint(final Graphics gc)
	{
		super.paint(gc);
		gc.setFont(font);
		final FontMetrics metrics = gc.getFontMetrics();
		
		// drawString x/y is 'baseline' of text
		final int y = metrics.getLeading() + metrics.getAscent();
		gc.drawString(FontCalibration.TEXT, 0, y);
		
		// Show baseline and 'leading'
		gc.setColor(Color.RED);
		gc.drawLine(0, y, text_width, y);
		gc.setColor(Color.GREEN);
		gc.drawLine(0, metrics.getLeading(), text_width, metrics.getLeading());
	}
};
      text.setSize(text_width, text_height);
      
      frame.add(text);
      
      frame.addWindowListener(new WindowAdapter()
      {
          @Override
          public void windowClosing(WindowEvent windowEvent)
          {
              System.exit(0);
          }
      });

      frame.pack();
      frame.setVisible(true);

      if (Math.abs(factor - 1.0) > 0.01)
          System.err.println("Calibration is not 1.0 but " + factor);
  }
 
Example 13
Source File: Snippet14.java    From noa-libre with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void main(String[] args) {				
	try {
		HashMap configuration = new HashMap();
		configuration.put(IOfficeApplication.APPLICATION_HOME_KEY, OPEN_OFFICE_ORG_PATH);
		configuration.put(IOfficeApplication.APPLICATION_TYPE_KEY, IOfficeApplication.LOCAL_APPLICATION);
		final IOfficeApplication officeAplication = OfficeApplicationRuntime.getApplication(configuration);	
		
		officeAplication.setConfiguration(configuration);
		officeAplication.activate();
		
		final Frame frame = new Frame();
     frame.setVisible(true);
     frame.setSize(400, 400);
     frame.validate();
     Panel panel = new Panel(new BorderLayout());
     frame.add(panel);  
     panel.setVisible(true);
     frame.addWindowListener(new WindowAdapter() {
       public void windowClosing(WindowEvent windowEvent) {
         frame.dispose();
         try {
           officeAplication.deactivate();
         }
         catch (OfficeApplicationException applicationException) {            
         }
       }        
     }); 
     
     IFrame officeFrame = officeAplication.getDesktopService().constructNewOfficeFrame(panel);
     officeAplication.getDocumentService().constructNewDocument(officeFrame, IDocument.WRITER, DocumentDescriptor.DEFAULT);
     frame.validate();
     
     //Now it is time to disable two commands in the frame
     officeFrame.disableDispatch(GlobalCommands.CLOSE_DOCUMENT);
     officeFrame.disableDispatch(GlobalCommands.QUIT_APPLICATION);
     officeFrame.updateDispatches();
	} 
	catch (Throwable throwable) {
		throwable.printStackTrace();
	} 
}
 
Example 14
Source File: GeneratorPreviewer.java    From algorithms-nutshell-2ed with MIT License 4 votes vote down vote up
public static void main(String[] args) {
	final Frame f = new Frame();
	f.setSize(800, 600);
	f.setLayout(null);

	f.addWindowListener (new WindowAdapter() {
		public void windowClosing(WindowEvent we) {
			f.setVisible(false);
			System.exit(0);
		}
	});
	
	GeneratorPanel<IPoint> gp = new GeneratorPanel<IPoint> ();

	Generator<IPoint> gen1 = new UniformGenerator();
	Generator<IPoint> gen2 = new UnusualGenerator(40);

	gp.addGenerator("Uniform", gen1);
	gp.addGenerator("Unusual", gen2);
	gp.addGenerator("Circle", new CircleGenerator(9));
	
	f.add(gp);
	

	final TextArea ta = new TextArea(40,80);
	ta.setBounds(gp.getWidth()+20, 40, f.getWidth() - gp.getWidth() - 30, f.getHeight()-80);
	f.add(ta);
	
	gp.register(new IGeneratorManager<IPoint>() {

		public void generate(IPoint[] items) {
			StringBuilder sb = new StringBuilder();
			for (IPoint p : items) {
				sb.append(p.toString());
				sb.append("\n");
			}
			ta.setText(sb.toString());
		}
		
	});
	
	f.setVisible (true);
}