Java实现全屏的四种方式(四个例子)【附源码】

阅读更多

FullScreenDemo.java:

package FullScreenDemo;

import java.awt.*;

import javax.swing.*;

/**
 * @author http://xp9802.iteye.com/
 * 2011-11-19下午04:40:38
 */
public class FullScreenDemo {

	public static void main(String[] args) {
		final JFrame jframe = new JFrame();
		JButton fullsButton = new JButton("全屏显示");
		JButton exitButton = new JButton("退出");
		exitButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				System.exit(1);
			}
		});
		fullsButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
				//通过调用GraphicsEnvironment的getDefaultScreenDevice方法获得当前的屏幕设备了
				GraphicsDevice gd = ge.getDefaultScreenDevice();
				// 全屏设置
				gd.setFullScreenWindow(jframe);
			}
		});
		jframe.add(fullsButton);
		jframe.add(exitButton);
		jframe.setLayout(new FlowLayout());
		jframe.setSize(400, 300);
		jframe.setVisible(true);
	}
}

 

 

 

FullScreenDemo1.java:

 

 

package FullScreenDemo;

import java.awt.FlowLayout;

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

/**
 * @author http://xp9802.iteye.com/
 * 2011-11-19下午04:31:38
 */
public class FullScreenDemo1 {

	public static void main(String[] args) {
		JFrame jframe = new JFrame();
		JButton exitButton = new JButton("退出");
		exitButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				System.exit(1);
			}
		});
		jframe.add(exitButton);
		jframe.setLayout(new FlowLayout());
		jframe.setUndecorated(false);
		jframe.getGraphicsConfiguration().getDevice()
				.setFullScreenWindow(jframe);
		jframe.setVisible(true);
	}
}

 

 

FullScreenDemo2.java:

 

package FullScreenDemo;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;

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


/**
 * @author http://xp9802.iteye.com/
 * 2011-11-19下午04:32:38
 */
public class FullScreenDemo2 {
	public static void main(String[] args) {
		JFrame jframe = new JFrame();
		JButton exitButton = new JButton("退出");
		exitButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				System.exit(1);
			}
		});
		jframe.add(exitButton);
		jframe.setLayout(new FlowLayout());
		/**
		 * true无边框 全屏显示
		 * false有边框 全屏显示
		 */
		jframe.setUndecorated(false);
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		jframe.setSize(d.width, d.height);
		jframe.setVisible(true);
	}
}

 

 

 

FullScreenDemo3.java:

 

 

package FullScreenDemo;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Rectangle;
import java.awt.Toolkit;

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

/**
 * @author http://xp9802.iteye.com/
 * 2011-11-19下午04:39:38
 */
public class FullScreenDemo3 {

	public static void main(String[] args) {
		JFrame jframe = new JFrame();
		JButton exitButton = new JButton("退出");
		exitButton.addActionListener(new java.awt.event.ActionListener() {

			public void actionPerformed(java.awt.event.ActionEvent evt) {
				System.exit(1);
			}
		});
		jframe.add(exitButton);
		jframe.setLayout(new FlowLayout());
		/**
		 * true无边框 全屏显示
		 * false有边框 全屏显示
		 */
		jframe.setUndecorated(false);
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		Rectangle bounds = new Rectangle(screenSize);
		jframe.setBounds(bounds);
		jframe.setExtendedState(JFrame.MAXIMIZED_BOTH);
		jframe.setVisible(true);
	}
}

 

 

 源码解压密码为:xp9802.iteye.com

  • FullScreenDemo.zip (2.9 KB)
  • 下载次数: 128

你可能感兴趣的:(Java,全屏,FullScreen)