Example usage for java.awt Frame addNotify

List of usage examples for java.awt Frame addNotify

Introduction

In this page you can find the example usage for java.awt Frame addNotify.

Prototype

public void addNotify() 

Source Link

Document

Makes this Frame displayable by connecting it to a native screen resource.

Usage

From source file:MainClass.java

public static void main(String[] args) {
    Frame frame = new Frame("AppletAndApp as an Application");
    myApplet = new MainClass();

    frame.add(new Panel().add(myApplet));

    frame.addNotify();

    myApplet.setStub(myStub = new MyStub(args));
    myApplet.init();/* ww w.jav a2 s. c  o m*/

    frame.setSize(300, 200);
    frame.setVisible(true);

    myStub.setActive(true);
    myApplet.start();

    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent w) {
            myStub.setActive(false);
            myApplet.stop();
            myApplet.destroy();
            System.exit(0);
        }
    });
}

From source file:forseti.JUtil.java

public static synchronized Image generarImagenMensaje(String mensaje, String nombreFuente, int tamanioFuente) {
    Frame f = new Frame();
    f.addNotify();
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    env.getAvailableFontFamilyNames();/*from   w ww  .  j ava 2  s  . c  om*/
    Font fuente = new Font(nombreFuente, Font.PLAIN, tamanioFuente);
    FontMetrics medidas = f.getFontMetrics(fuente);
    int anchoMensaje = medidas.stringWidth(mensaje);
    int lineaBaseX = anchoMensaje / 10;
    int ancho = anchoMensaje + 2 * (lineaBaseX + tamanioFuente);
    int alto = tamanioFuente * 7 / 2;
    int lineaBaseY = alto * 8 / 10;
    Image imagenMensaje = f.createImage(ancho, alto);
    Graphics2D g2d = (Graphics2D) imagenMensaje.getGraphics();
    g2d.setFont(fuente);
    g2d.translate(lineaBaseX, lineaBaseY);
    g2d.setPaint(Color.lightGray);
    AffineTransform origTransform = g2d.getTransform();
    g2d.shear(-0.95, 0);
    g2d.scale(1, 3);
    g2d.drawString(mensaje, 0, 0);
    g2d.setTransform(origTransform);
    g2d.setPaint(Color.black);
    g2d.drawString(mensaje, 0, 0);

    return (imagenMensaje);
}