Fullscreen / Vollbild Tutorial

Enigma228

Bekanntes Mitglied
Quelle:
Full-Screen Exclusive Mode (The Java™ Tutorials > Bonus > Full-Screen Exclusive Mode API)

FullScreen / Vollbild wird von der Klasse GraphicsDevice gehandhabt.

1. Zuerst holt man sich die DisplayModi
Klasse: GraphicsEnvironment
Methode: getScreenDevices() -> man erhält ein Array mit GraphicsDevices.
oder: getDefaultScreenDevice() -> man erhält ein GraphicsDevice mit aktueller Auflösung

Java:
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device;
device =ge.getDefaultScreenDevice();

2. Überprüfung ob Fullsize unterstützt wird
Klasse: GraphicsDevice
Methode: isFullScreenSupported() -> man erhält einen boolean-Wert.

3. Setzen des FullSize-Modus
Klasse: GraphicsDevice
Methode: setFullScreenWindow(Window w) -> FullScreen wird eingestellt
oder: setFullScreenWindow(null) -> um auf "normale" Grösse zurückzustellen

Java:
if(device.isFullScreenSupported()){
			device.setFullScreenWindow(this);
}

Hier mal eine einfache JFrame-Klasse in dem der User zwischen dem FullScreen- und dem Fenster-Modus hin und herschalten kann.

Java:
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;


public class MyFrame extends JFrame implements ActionListener{

	private JButton b_close, b_larger, b_smaller;
	private GraphicsDevice device;
    
	
	public MyFrame() throws HeadlessException {
		this.setLayout(null);
		this.setSize(500,500);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
		device =ge.getDefaultScreenDevice();

		if(device.isFullScreenSupported()){
			device.setFullScreenWindow(this);
		}
		
		
		b_close = new JButton("Beenden");
		b_close.setBounds(20, 20, 100, 30);
		b_close.addActionListener(this);
		
		b_larger = new JButton("FullScreen");
		b_larger.setBounds(20, 70, 100, 30);
		b_larger.addActionListener(this);
		b_larger.setEnabled(false);
		
		b_smaller = new JButton("Window");
		b_smaller.setBounds(20, 120, 100, 30);
		b_smaller.addActionListener(this);
		
		this.add(b_close);
		this.add(b_smaller);
		this.add(b_larger);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()== b_close){
			device.setFullScreenWindow(null);
            System.exit(0);
		}
		if(e.getSource()== b_larger){
			b_larger.setEnabled(false);
			b_smaller.setEnabled(true);
			device.setFullScreenWindow(this);
		}
		if(e.getSource()== b_smaller){
			b_larger.setEnabled(true);
			b_smaller.setEnabled(false);
			device.setFullScreenWindow(null);
		}
	}

	
}

Viel Spass beim Testen !!!
 
Zuletzt bearbeitet:

Enigma228

Bekanntes Mitglied
DANKE an CroniD!!!!

Dialogfelder im Fullscreen lassen sich nur an das JDesktopPane binden, da
"JDialogs sind Window Objekte. Die können nicht "über" den FullScreen." (Zitat CroniD)

"Windows cannot overlap the full-screen window. All other application windows will always appear beneath the full-screen window in the Z-order."
Zitat aus:
GraphicsDevice (Java Platform SE 6)

Bsp. von CroniD
nochmals Danke!!!
Java:
import java.awt.BorderLayout;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
 
public class FullScreenSwing extends JFrame implements ActionListener {
 
    private JDesktopPane d_pane;
    private JButton b_close, b_larger, b_smaller, b_dialog;
    private GraphicsDevice device;
    
    public FullScreenSwing() throws HeadlessException {
        this.setLayout(new BorderLayout());
        this.setSize(500,500);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        device = ge.getDefaultScreenDevice();
 
        if (device.isFullScreenSupported()){
            setUndecorated(true);
            device.setFullScreenWindow(this);
        }
        b_close = new JButton("Close");
        b_close.setBounds(20, 20, 100, 30);
        b_close.addActionListener(this);
        
        b_larger = new JButton("FullScreen");
        b_larger.setBounds(20, 70, 100, 30);
        b_larger.addActionListener(this);
        b_larger.setEnabled(false);
        
        b_smaller = new JButton("Window");
        b_smaller.setBounds(20, 120, 100, 30);
        b_smaller.addActionListener(this);
        
        b_dialog = new JButton("Show Dialog");
        b_dialog.setBounds(20, 170, 100, 30);
        b_dialog.addActionListener(this);
        
        d_pane = new JDesktopPane();
        d_pane.setBackground(null); // prevent unexpected LaF settings
        d_pane.add(b_close);
        d_pane.add(b_smaller);
        d_pane.add(b_larger);
        d_pane.add(b_dialog);
        this.add(d_pane);
    }
 
    @Override public void actionPerformed(ActionEvent e) {
        if (e.getSource() == b_close) {
            device.setFullScreenWindow(null);
            System.exit(0);
        }
        if (e.getSource() == b_larger) {
            b_larger.setEnabled(false);
            b_smaller.setEnabled(true);
            if (isDisplayable()) {
                setVisible(false);
                dispose();
            }
            setUndecorated(true);
            if (!isVisible()) {
                setVisible(true);
            }
            device.setFullScreenWindow(this);
        }
        if (e.getSource() == b_smaller) {
            b_larger.setEnabled(true);
            b_smaller.setEnabled(false);
            device.setFullScreenWindow(null);
            setVisible(false);
            dispose();
            setUndecorated(false);
            setVisible(true);
        }
        if (e.getSource() == b_dialog) {
            // is window in full screen mode?
            if (device.getFullScreenWindow() == null) {
                JOptionPane.showMessageDialog(this, "This is a test dialog.");
            } else { // isFullScreen
                JOptionPane.showInternalMessageDialog(d_pane, "This is a test dialog.");
            }
        }
    }
    
    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) { e.printStackTrace(); }
        new FullScreenSwing().setVisible(true);
    }
}
 
Zuletzt bearbeitet:
Ähnliche Java Themen
  Titel Forum Antworten Datum
M suche umfassendes Tutorial von Scenebuilder Bücher, Tutorials und Links 1
K Cooles Java Tutorial, voll hilfreich Bücher, Tutorials und Links 3
M Einsteigerbuch / Tutorial für Java am PC + Android + Eclipse Bücher, Tutorials und Links 11
M JUnit-Buch oder Tutorial Bücher, Tutorials und Links 5
J [Maven] ZIP Deployment Tutorial Bücher, Tutorials und Links 0
J LWJGL 3.1.0 Tutorial mit GLFW & OpenGL Bücher, Tutorials und Links 6
4 Literatur/Tutorial fuer Webprogrammierung Bücher, Tutorials und Links 10
J Maven Tutorial Bücher, Tutorials und Links 0
Viktim Java3D Tutorial Bücher, Tutorials und Links 4
M ausführliche Doku/Tutorial/Buch zu Java Mission Control Bücher, Tutorials und Links 0
J JavaFX Tutorial Bücher, Tutorials und Links 2
K Tutorial Patente Bücher, Tutorials und Links 0
M Suche Tutorial für Sound erstellung in JAVA Bücher, Tutorials und Links 3
D Suche HSQLDB Tutorial/Lektüre Bücher, Tutorials und Links 7
K Tutorial zum AUSDRUCKEN Bücher, Tutorials und Links 5
S Java EE 6 Tutorial Bücher, Tutorials und Links 2
S [Suche]LWJGL OpenCL Tutorial Bücher, Tutorials und Links 4
S Völliger Neuling sucht Tutorial... Bücher, Tutorials und Links 13
Y CSS Tutorial / Buch Bücher, Tutorials und Links 3
B [SUCHE] Buch oder Tutorial für "Herangehensweisen" Bücher, Tutorials und Links 3
P MYSQL-Tutorial gesucht Bücher, Tutorials und Links 5
T JEE: Überblick, Einführung, Kochbuch, Tutorial, ... Bücher, Tutorials und Links 13
S bestes Tutorial zum lernen von Java Bücher, Tutorials und Links 2
M "Java Lernen" mit welchen Buch/Tutorial? Bücher, Tutorials und Links 3
B Tutorial für JFreeChart Bücher, Tutorials und Links 11
G ext gwt tutorial ? Bücher, Tutorials und Links 6
P [Notizzettel] Tutorial: Bilder-Upload mit Jakarta HttpClient Bücher, Tutorials und Links 1
F GridBagLayout Tutorial auf deutsch für Java 1.6 ? Bücher, Tutorials und Links 2
H deutsches Buch/Tutorial/Anleitung über RMI in Verbindung mit Bücher, Tutorials und Links 1
P Tutorial zu Web Application ? Bücher, Tutorials und Links 3
K Tutorial für Anfänger Bücher, Tutorials und Links 2
T [Suche] Tutorial zu Time Scheduler in Websphere Bücher, Tutorials und Links 5
P Umfangreiches Tutorial Bücher, Tutorials und Links 12
E Suche Tutorial/Buch über guten Stil bei GUI-Programmierung Bücher, Tutorials und Links 7
kulturfenster Tree Tutorial Bücher, Tutorials und Links 2
N Suche: FTP Tutorial Bücher, Tutorials und Links 19
T [Diskussion zu:] Konsolen Tutorial Bücher, Tutorials und Links 20
rambozola Buch, Tutorial zu CMS Day Communiqué gesucht Bücher, Tutorials und Links 1
D Buch / Tutorial zum Thema GUI Bücher, Tutorials und Links 11
A Tutorial! Bücher, Tutorials und Links 3
L-ectron-X Diskussion zu "Tutorial von Beni und Roar" Bücher, Tutorials und Links 7
B [Suche] Tutorial zu HttpUnit Bücher, Tutorials und Links 5
P JMF Tutorial Bücher, Tutorials und Links 13
D Tutorial für strukturierte Programmierung (MVC) Bücher, Tutorials und Links 2
K Java3D Tutorial Bücher, Tutorials und Links 1
Nadja Gutes Tutorial für GUI? Bücher, Tutorials und Links 8

Ähnliche Java Themen

Neue Themen


Oben