Example usage for java.awt Frame setVisible

List of usage examples for java.awt Frame setVisible

Introduction

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

Prototype

public void setVisible(boolean b) 

Source Link

Document

Shows or hides this Window depending on the value of parameter b .

Usage

From source file:org.eclipse.swt.snippets.Snippet156.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("SWT Image");
    ImageData data;/*w  w  w. j  av  a 2 s .  co m*/
    if (args.length > 0) {
        String fileName = args[0];
        data = new ImageData(fileName);
    } else {
        data = createSampleImage(display);
    }
    final Image swtImage = new Image(display, data);
    final BufferedImage awtImage = convertToAWT(data);
    final Image swtImage2 = new Image(display, convertToSWT(awtImage));
    shell.addListener(SWT.Paint, e -> {
        int y = 10;
        if (swtImage != null) {
            e.gc.drawImage(swtImage, 10, y);
            y += swtImage.getBounds().height + 10;
        }
        if (swtImage2 != null) {
            e.gc.drawImage(swtImage2, 10, y);
        }
    });
    Frame frame = new Frame() {
        @Override
        public void paint(Graphics g) {
            Insets insets = getInsets();
            if (awtImage != null) {
                g.drawImage(awtImage, 10 + insets.left, 10 + insets.top, null);
            }
        }
    };
    frame.setTitle("AWT Image");
    shell.setLocation(50, 50);
    Rectangle bounds = swtImage.getBounds();
    shell.setSize(bounds.width + 50, bounds.height * 2 + 100);
    Point size = shell.getSize();
    Point location = shell.getLocation();
    Insets insets = frame.getInsets();
    frame.setLocation(location.x + size.x + 10, location.y);
    frame.setSize(size.x - (insets.left + insets.right), size.y - (insets.top + insets.bottom));
    frame.setVisible(true);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (swtImage != null)
        swtImage.dispose();
    if (swtImage2 != null)
        swtImage.dispose();
    frame.dispose();
    display.dispose();
    /* Note: If you are using JDK 1.3.x, you need to use System.exit(0) at the end of your program to exit AWT.
     * This is because in 1.3.x, AWT does not exit when the frame is disposed, because the AWT thread is not a daemon.
     * This was fixed in JDK 1.4.x with the addition of the AWT Shutdown thread.
     */
}

From source file:Bouncer.java

public static void main(String[] args) {
    final Bouncer bouncer = new Bouncer();
    Frame f = new AnimationFrame(bouncer);
    f.setFont(new Font("Serif", Font.PLAIN, 12));
    f.setSize(200, 200);/* w w w .ja  v a  2 s  .co  m*/
    Panel controls = new Panel();
    controls.add(bouncer.createCheckbox("Anti.", Bouncer.ANTIALIASING));
    controls.add(bouncer.createCheckbox("Trans.", Bouncer.TRANSFORM));
    controls.add(bouncer.createCheckbox("Gradient", Bouncer.GRADIENT));
    controls.add(bouncer.createCheckbox("Outline", Bouncer.OUTLINE));
    controls.add(bouncer.createCheckbox("Dotted", Bouncer.DOTTED));
    controls.add(bouncer.createCheckbox("Axes", Bouncer.AXES));
    controls.add(bouncer.createCheckbox("Clip", Bouncer.CLIP));
    f.add(controls, BorderLayout.NORTH);

    f.setVisible(true);
}

From source file:ImageBouncer.java

public static void main(String[] args) {
    String filename = "java2sLogo.png";
    if (args.length > 0)
        filename = args[0];//from w  w w  .ja  va  2s .  c o  m

    Image image = null;
    try {
        image = blockingLoad(new URL(filename));
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    final ImageBouncer bouncer = new ImageBouncer(image);
    Frame f = new AnimationFrame(bouncer);
    f.setFont(new Font("Serif", Font.PLAIN, 12));
    Panel controls = new Panel();
    controls.add(bouncer.createCheckbox("Bilinear", ImageBouncer.BILINEAR));
    controls.add(bouncer.createCheckbox("Transform", ImageBouncer.TRANSFORM));
    final Choice typeChoice = new Choice();
    typeChoice.add("TYPE_INT_RGB");
    typeChoice.add("TYPE_INT_ARGB");
    typeChoice.add("TYPE_INT_ARGB_PRE");
    typeChoice.add("TYPE_3BYTE_BGR");
    typeChoice.add("TYPE_BYTE_GRAY");
    typeChoice.add("TYPE_USHORT_GRAY");
    typeChoice.add("TYPE_USHORT_555_RGB");
    typeChoice.add("TYPE_USHORT_565_RGB");
    controls.add(typeChoice);
    f.add(controls, BorderLayout.NORTH);

    typeChoice.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ie) {
            String type = typeChoice.getSelectedItem();
            bouncer.setImageType(type);
        }
    });
    f.setSize(200, 200);
    f.setVisible(true);
}

From source file:TextBouncer.java

public static void main(String[] args) {

    String s = "Java Source and Support";
    final int size = 64;
    if (args.length > 0)
        s = args[0];//w w w  .j  av a 2  s.com

    Panel controls = new Panel();
    final Choice choice = new Choice();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] allFonts = ge.getAllFonts();
    for (int i = 0; i < allFonts.length; i++)
        choice.addItem(allFonts[i].getName());
    Font defaultFont = new Font(allFonts[0].getName(), Font.PLAIN, size);

    final TextBouncer bouncer = new TextBouncer(s, defaultFont);
    Frame f = new AnimationFrame(bouncer);
    f.setFont(new Font("Serif", Font.PLAIN, 12));
    controls.add(bouncer.createCheckbox("Antialiasing", TextBouncer.ANTIALIASING));
    controls.add(bouncer.createCheckbox("Gradient", TextBouncer.GRADIENT));
    controls.add(bouncer.createCheckbox("Shear", TextBouncer.SHEAR));
    controls.add(bouncer.createCheckbox("Rotate", TextBouncer.ROTATE));
    controls.add(bouncer.createCheckbox("Axes", TextBouncer.AXES));

    Panel fontControls = new Panel();
    choice.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ie) {
            Font font = new Font(choice.getSelectedItem(), Font.PLAIN, size);
            bouncer.setFont(font);
        }
    });
    fontControls.add(choice);

    Panel allControls = new Panel(new GridLayout(2, 1));
    allControls.add(controls);
    allControls.add(fontControls);
    f.add(allControls, BorderLayout.NORTH);
    f.setSize(300, 300);
    f.setVisible(true);
}

From source file:Main.java

public static void main() {

    Frame frame = new Frame();

    frame.setSize(300, 300);/*from ww w . ja  v a2  s  .  c o m*/
    frame.setVisible(true);

    iconify(frame);
}

From source file:Main.java

public static void main() {

    Frame frame = new Frame();

    Rectangle bounds = new Rectangle(20, 20, 200, 200);

    frame.setMaximizedBounds(bounds);/*from  w  ww  .  ja v a2 s  .  c  o m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main() {
    Frame frame = new Frame();
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            Frame frame = (Frame) evt.getSource();
            frame.setVisible(false);
            // frame.dispose();
        }//from   ww w  . j a  v  a 2s . c  om
    });
}

From source file:Main.java

public static void main() {
    Frame frame = new Frame();

    WindowListener listener = new WindowAdapter() {
        public void windowOpened(WindowEvent evt) {
            Frame frame = (Frame) evt.getSource();
            System.out.println(frame.getTitle());
        }/*from w ww  .  j a va2  s. co  m*/

        public void windowClosing(WindowEvent evt) {
            Frame frame = (Frame) evt.getSource();

            System.out.println(frame.getTitle());

        }

        public void windowClosed(WindowEvent evt) {
            Frame frame = (Frame) evt.getSource();
            System.out.println(frame.getTitle());
        }
    };

    frame.addWindowListener(listener);
    frame.setVisible(true);
}

From source file:ModalFrameUtil.java

public static void showAsModal(final Frame frame, final Frame owner) {
    frame.addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent e) {
            owner.setEnabled(false);/*w  w w  .  j a  v a2s  . c o  m*/
        }

        public void windowClosing(WindowEvent e) {
            owner.setEnabled(true);
            frame.removeWindowListener(this);
        }

        public void windowClosed(WindowEvent e) {
            owner.setEnabled(true);
            frame.removeWindowListener(this);
        }
    });

    owner.addWindowListener(new WindowAdapter() {
        public void windowActivated(WindowEvent e) {
            if (frame.isShowing()) {
                frame.setExtendedState(JFrame.NORMAL);
                frame.toFront();
            } else {
                owner.removeWindowListener(this);
            }
        }
    });

    frame.setVisible(true);
    try {
        new EventPump(frame).start();
    } catch (Throwable throwable) {
        throw new RuntimeException(throwable);
    }
}

From source file:Main.java

public static void main() {

    Frame frame = new Frame();

    WindowStateListener listener = new WindowAdapter() {
        public void windowStateChanged(WindowEvent evt) {
            int oldState = evt.getOldState();
            int newState = evt.getNewState();

            if ((oldState & Frame.ICONIFIED) == 0 && (newState & Frame.ICONIFIED) != 0) {
                System.out.println("Frame was iconized");
            } else if ((oldState & Frame.ICONIFIED) != 0 && (newState & Frame.ICONIFIED) == 0) {
                System.out.println("Frame was deiconized");
            }//w  w w.j  a  va  2  s.  c  o m

            if ((oldState & Frame.MAXIMIZED_BOTH) == 0 && (newState & Frame.MAXIMIZED_BOTH) != 0) {
                System.out.println("Frame was maximized");
            } else if ((oldState & Frame.MAXIMIZED_BOTH) != 0 && (newState & Frame.MAXIMIZED_BOTH) == 0) {
                System.out.println("Frame was minimized");
            }
        }
    };

    frame.addWindowStateListener(listener);
    frame.setVisible(true);
}