Example usage for java.awt GraphicsDevice setDisplayMode

List of usage examples for java.awt GraphicsDevice setDisplayMode

Introduction

In this page you can find the example usage for java.awt GraphicsDevice setDisplayMode.

Prototype

public void setDisplayMode(DisplayMode dm) 

Source Link

Document

Sets the display mode of this graphics device.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setSize(800, 600);/*from   ww w.jav a2 s  . co  m*/
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    device.setFullScreenWindow(frame);
    device.setDisplayMode(new DisplayMode(800, 600, 32, 60));
    frame.setVisible(true);

    JButton btn = new JButton();
    btn.setText("Button");
    JPanel panel = new JPanel();

    panel.add(btn);
    frame.add(panel);

    btn.addActionListener(e -> {
        JOptionPane.showMessageDialog(frame.getContentPane(), "JOptionPane");
    });
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    device.setFullScreenWindow(frame);// w  ww .ja  v a  2s .  co m
    device.setDisplayMode(new DisplayMode(800, 600, 32, 60));

    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowIconified(WindowEvent we) {
            if (programmatic) {
                programmatic = false;
                frame.setState(JFrame.NORMAL);
            }
        }
    });

    JButton btn = new JButton();
    btn.setText("Btn");
    final JPanel panel = new JPanel();

    panel.add(btn);
    frame.add(panel);

    btn.addActionListener(e -> {
        programmatic = true;
        JOptionPane.showMessageDialog(panel, "Sample");
    });
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gs = ge.getDefaultScreenDevice();

    boolean canChg = gs.isDisplayChangeSupported();
    if (canChg) {
        DisplayMode displayMode = gs.getDisplayMode();
        int screenWidth = 640;
        int screenHeight = 480;
        int bitDepth = 8;
        displayMode = new DisplayMode(screenWidth, screenHeight, bitDepth, displayMode.getRefreshRate());
        try {/*from  w ww . j  a  v a 2 s.c o  m*/
            gs.setDisplayMode(displayMode);
        } catch (Throwable e) {
            gs.setFullScreenWindow(null);
        }
    }
}

From source file:FullScreen.java

public static void main(String args[]) {
    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice graphicsDevice = graphicsEnvironment.getDefaultScreenDevice();
    DisplayMode originalDisplayMode = graphicsDevice.getDisplayMode();

    try {/*from  w  w  w. j  a  v  a2 s.  c  o m*/
        Frame frame = new Frame();
        frame.setUndecorated(true);
        frame.setIgnoreRepaint(true);
        graphicsDevice.setFullScreenWindow(frame);
        if (graphicsDevice.isDisplayChangeSupported()) {
            graphicsDevice.setDisplayMode(getBestDisplayMode(graphicsDevice));
        }
        frame.createBufferStrategy(2); // 2 buffers
        Rectangle bounds = frame.getBounds();
        BufferStrategy bufferStrategy = frame.getBufferStrategy();
        while (!done()) {
            Graphics g = null;
            try {
                g = bufferStrategy.getDrawGraphics();
                if ((counter <= 2)) { // 2 buffers
                    g.setColor(Color.CYAN);
                    g.fillRect(0, 0, bounds.width, bounds.height);
                }
                g.setColor(Color.RED);
                // redraw prior line, too, since 2 buffers
                if (counter != 1) {
                    g.drawLine(counter - 1, (counter - 1) * 5, bounds.width, bounds.height);
                }
                g.drawLine(counter, counter * 5, bounds.width, bounds.height);
                bufferStrategy.show();
            } finally {
                if (g != null) {
                    g.dispose();
                }
            }
            try {
                Thread.sleep(250);
            } catch (InterruptedException ignored) {
            }
        }
    } finally {
        graphicsDevice.setDisplayMode(originalDisplayMode);
        graphicsDevice.setFullScreenWindow(null);
    }
    System.exit(0);
}

From source file:MultiBufferTest.java

public static void chooseBestDisplayMode(GraphicsDevice device) {
    DisplayMode best = getBestDisplayMode(device);
    if (best != null) {
        device.setDisplayMode(best);
    }//  w ww .j ava2 s  . co  m
}

From source file:dylemator.DylematorUI.java

public void setFullscreen(boolean fullscreen) {
    //get a reference to the device.
    GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    DisplayMode dispMode = device.getDisplayMode();
    //save the old display mode before changing it.
    dispModeOld = device.getDisplayMode();

    if (this.fullscreen != fullscreen) { //are we actually changing modes.
                                         //change modes.
        this.fullscreen = fullscreen;
        // toggle fullscreen mode
        if (!fullscreen) {
            //change to windowed mode.
            //set the display mode back to the what it was when
            //the program was launched.
            device.setDisplayMode(dispModeOld);

            //hide the frame so we can change it.
            setVisible(false);//from   w  w w . jav a2 s  .co m
            //remove the frame from being displayable.
            dispose();
            //put the borders back on the frame.
            setUndecorated(false);
            //needed to unset this window as the fullscreen window.
            device.setFullScreenWindow(null);
            //recenter window
            setLocationRelativeTo(null);
            setResizable(true);

            //reset the display mode to what it was before
            //we changed it.
            setVisible(true);

        } else { //change to fullscreen.
                 //hide everything
            setVisible(false);
            //remove the frame from being displayable.
            dispose();
            //remove borders around the frame
            setUndecorated(true);
            //make the window fullscreen.
            device.setFullScreenWindow(this);
            //attempt to change the screen resolution.
            device.setDisplayMode(dispMode);
            setResizable(false);
            setAlwaysOnTop(false);
            //show the frame
            setVisible(true);
        }
        //make sure that the screen is refreshed.
        repaint();

    }
    this.requestFocus();
}