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:MemImage.java

/**
 * Demo main program, showing two ways to use it. Create a small MemImage
 * and set it as this Frame's iconImage. Also display a larger version of
 * the same image in the Frame.// w w w  .  jav  a 2  s .  c  om
 */
public static void main(String[] av) {
    Frame f = new Frame("MemImage.java");
    f.add(new MemImage());
    f.setIconImage(new MemImage(16, 16).getImage());
    f.pack();
    f.setVisible(true);
}

From source file:FrameIcon.java

/** Demo main program, showing two ways to use it.
 * Create a small MemImage and set it as this Frame's iconImage. 
 * Also display a larger version of the same image in the Frame.
 *//*from  w  w w. j av  a 2 s. com*/
public static void main(String[] av) {
    Frame f = new Frame("FrameIcon");
    Image im = Toolkit.getDefaultToolkit().getImage("java2s.gif");
    f.setIconImage(im);
    f.setSize(100, 100);
    f.setLocation(200, 200);
    f.setVisible(true);
}

From source file:TexturedText.java

/** "main program" method - construct and show */
public static void main(String[] av) {
    // create a TexturedText object, tell it to show up
    final Frame f = new Frame("TexturedText");
    TexturedText comp = new TexturedText();
    f.add(comp);/*w  ww .j a  va 2  s  .  co  m*/
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            f.setVisible(false);
            f.dispose();
            System.exit(0);
        }
    });
    f.pack();
    f.setLocation(200, 200);
    f.setVisible(true);
}

From source file:Drag.java

/**
 *  Used when running as an application.
 *///  w w w  .j  av  a 2s  . c  o  m
public static void main(String[] args) {
    Drag drag = new Drag();
    drag.setAppletFlag(false);
    drag.init();

    Frame frame = new Frame("Drag the mouse in the window");
    frame.setSize(640, 480);
    frame.add("Center", drag);
    frame.addWindowListener(new killAdapter());
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    Frame f = new Frame("FlowLayout demo");
    f.setLayout(new FlowLayout());
    f.add(new Button("Red"));
    f.add(new Button("Blue"));
    f.add(new Button("White"));
    List list = new List();
    for (int i = 0; i < args.length; i++) {
        list.add(args[i]);/*from   w ww. ja v  a 2s  . c om*/
    }
    f.add(list);
    f.add(new Checkbox("Pick me", true));
    f.add(new Label("Enter name here:"));
    f.add(new TextField(20));
    f.pack();
    f.setVisible(true);
}

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();//from   w  ww.j ava  2s. c  o m

    myApplet.setStub(myStub = new MyStub(args));
    myApplet.init();

    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:J3dSwingFrame.java

/**
 * Start the application....//from ww  w  .  jav a  2  s.c  o m
 */
public static void main(String[] args) {
    Frame frame = new J3dSwingFrame();
    frame.setVisible(true);
}

From source file:RadialLayout.java

/**
 * Run a demonstration.//from   ww w. j  a  v  a 2 s .  c  o  m
 *
 * @param args  ignored.
 * 
 * @throws Exception when an error occurs.
 */
public static void main(final String[] args) throws Exception {
    final Frame frame = new Frame();
    final Panel panel = new Panel();
    panel.setLayout(new RadialLayout());

    panel.add(new Checkbox("One"));
    panel.add(new Checkbox("Two"));
    panel.add(new Checkbox("Three"));
    panel.add(new Checkbox("Four"));
    panel.add(new Checkbox("Five"));
    panel.add(new Checkbox("One"));
    panel.add(new Checkbox("Two"));
    panel.add(new Checkbox("Three"));
    panel.add(new Checkbox("Four"));
    panel.add(new Checkbox("Five"));

    frame.add(panel);
    frame.setSize(300, 500);
    frame.setVisible(true);
}

From source file:Snippet156.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("SWT Image");
    ImageData data;//from   ww  w .j  ava2 s.c  o 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, new Listener() {
        public void handleEvent(Event 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() {
        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();
    System.exit(0);
}

From source file:AWTBufferedImageSWTImage.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("SWT Image");
    ImageData data;/*from w w w .  j  a  va  2s .  c o 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, new Listener() {
        public void handleEvent(Event 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() {
        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.
     */
}